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 y0 配置したい中心のY座標
157 * @param x0 配置したい中心のX座標
159 * This funtion makes a very small room centred at (x0, y0)
160 * This is used in crypts, and random elemental vaults.
162 * Note - this should be used only on allocated regions
163 * within another room.
165 void build_small_room(POSITION x0, POSITION y0)
169 for (y = y0 - 1; y <= y0 + 1; y++)
171 place_inner_bold(y, x0 - 1);
172 place_inner_bold(y, x0 + 1);
175 for (x = x0 - 1; x <= x0 + 1; x++)
177 place_inner_bold(y0 - 1, x);
178 place_inner_bold(y0 + 1, x);
181 /* Place a secret door on one side */
184 case 0: place_secret_door(y0, x0 - 1, DOOR_DEFAULT); break;
185 case 1: place_secret_door(y0, x0 + 1, DOOR_DEFAULT); break;
186 case 2: place_secret_door(y0 - 1, x0, DOOR_DEFAULT); break;
187 case 3: place_secret_door(y0 + 1, x0, DOOR_DEFAULT); break;
190 /* Clear mimic type */
191 p_ptr->current_floor_ptr->grid_array[y0][x0].mimic = 0;
193 /* Add inner open space */
194 place_floor_bold(y0, x0);
199 * 指定範囲に通路が通っていることを確認した上で床で埋める
200 * This function tunnels around a room if it will cut off part of a p_ptr->current_floor_ptr->grid_array system.
207 static void check_room_boundary(POSITION x1, POSITION y1, POSITION x2, POSITION y2)
211 bool old_is_floor, new_is_floor;
214 old_is_floor = get_is_floor(x1 - 1, y1);
217 * Count the number of floor-wall boundaries around the room
218 * Note: diagonal squares are ignored since the player can move diagonally
219 * to bypass these if needed.
222 /* Above the top boundary */
223 for (x = x1; x <= x2; x++)
225 new_is_floor = get_is_floor(x, y1 - 1);
227 /* Increment counter if they are different */
228 if (new_is_floor != old_is_floor) count++;
230 old_is_floor = new_is_floor;
234 for (y = y1; y <= y2; y++)
236 new_is_floor = get_is_floor(x2 + 1, y);
238 /* increment counter if they are different */
239 if (new_is_floor != old_is_floor) count++;
241 old_is_floor = new_is_floor;
244 /* Bottom boundary */
245 for (x = x2; x >= x1; x--)
247 new_is_floor = get_is_floor(x, y2 + 1);
249 /* increment counter if they are different */
250 if (new_is_floor != old_is_floor) count++;
252 old_is_floor = new_is_floor;
256 for (y = y2; y >= y1; y--)
258 new_is_floor = get_is_floor(x1 - 1, y);
260 /* increment counter if they are different */
261 if (new_is_floor != old_is_floor) count++;
263 old_is_floor = new_is_floor;
266 /* If all the same, or only one connection exit. */
267 if (count <= 2) return;
270 /* Tunnel around the room so to prevent problems with caves */
271 for (y = y1; y <= y2; y++)
273 for (x = x1; x <= x2; x++)
283 * find_space()の予備処理として部屋の生成が可能かを判定する /
284 * Helper function for find_space(). Is this a good location?
285 * @param blocks_high 範囲の高さ
286 * @param blocks_wide 範囲の幅
287 * @param block_y 範囲の上端
288 * @param block_x 範囲の左端
291 static bool find_space_aux(POSITION blocks_high, POSITION blocks_wide, POSITION block_y, POSITION block_x)
293 POSITION by1, bx1, by2, bx2, by, bx;
295 /* Itty-bitty rooms must shift about within their rectangle */
298 if ((blocks_wide == 2) && (block_x % 3) == 2)
302 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
303 else if ((blocks_wide % 3) == 0)
305 /* Must be aligned to the left edge of a 11x33 rectangle. */
306 if ((block_x % 3) != 0)
311 * Big rooms that do not have a width divisible by 3 must be
312 * aligned towards the edge of the dungeon closest to them.
316 /* Shift towards left edge of dungeon. */
317 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
319 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
321 if ((block_x % 3) == 1)
325 /* Shift toward right edge of dungeon. */
328 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
330 if ((block_x % 3) == 1)
338 by2 = block_y + blocks_high;
339 bx2 = block_x + blocks_wide;
341 /* Never run off the screen */
342 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
343 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
345 /* Verify available space */
346 for (by = by1; by < by2; by++)
348 for (bx = bx1; bx < bx2; bx++)
350 if (dun->room_map[by][bx])
357 /* This location is okay */
363 * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room. -LM-
364 * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
365 * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
366 * @param height 確保したい領域の高さ
367 * @param width 確保したい領域の幅
368 * @return 所定の範囲が確保できた場合TRUEを返す
370 * Find and allocate a free space in the dungeon large enough to hold\n
371 * the room calling this function.\n
373 * We allocate space in 11x11 blocks, but want to make sure that rooms\n
374 * align neatly on the standard screen. Therefore, we make them use\n
375 * blocks in few 11x33 rectangles as possible.\n
377 * Be careful to include the edges of the room in height and width!\n
379 * Return TRUE and values for the center of the room if all went well.\n
380 * Otherwise, return FALSE.\n
382 bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
384 int candidates, pick;
385 POSITION by, bx, by1, bx1, by2, bx2;
386 POSITION block_y = 0, block_x = 0;
388 /* Find out how many blocks we need. */
389 POSITION blocks_high = 1 + ((height - 1) / BLOCK_HGT);
390 POSITION blocks_wide = 1 + ((width - 1) / BLOCK_WID);
392 /* There are no way to allocate such huge space */
393 if (dun->row_rooms < blocks_high) return FALSE;
394 if (dun->col_rooms < blocks_wide) return FALSE;
399 /* Count the number of valid places */
400 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
402 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
404 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
406 /* Find a valid place */
419 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE))
421 /* Choose a random one */
422 pick = randint1(candidates);
425 /* NO_CAVE dungeon (Castle) */
428 /* Always choose the center one */
429 pick = candidates/2 + 1;
432 /* Pick up the choosen location */
433 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
435 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
437 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
441 /* This one is picked? */
452 by2 = block_y + blocks_high;
453 bx2 = block_x + blocks_wide;
456 * It is *extremely* important that the following calculation
457 * be *exactly* correct to prevent memory errors
460 /* Acquire the location of the room */
461 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
462 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
464 /* Save the room location */
465 if (dun->cent_n < CENT_MAX)
467 dun->cent[dun->cent_n].y = (byte_hack)*y;
468 dun->cent[dun->cent_n].x = (byte_hack)*x;
472 /* Reserve some blocks. */
473 for (by = by1; by < by2; by++)
475 for (bx = bx1; bx < bx2; bx++)
477 dun->room_map[by][bx] = TRUE;
482 * Hack- See if room will cut off a cavern.
484 * If so, fix by tunneling outside the room in such a
485 * way as to connect the caves.
487 check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
495 * Structure to hold all "fill" data
498 typedef struct fill_data_type fill_data_type;
500 struct fill_data_type
513 /* features to fill with */
522 /* number of filled squares */
526 static fill_data_type fill_data;
529 /* Store routine for the fractal floor generator */
530 /* this routine probably should be an inline function or a macro. */
531 static void store_height(floor_type *floor_ptr, POSITION x, POSITION y, FEAT_IDX val)
533 /* if on boundary set val > cutoff so walls are not as square */
534 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
535 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
536 (val <= fill_data.c1)) val = fill_data.c1 + 1;
538 /* store the value in height-map format */
539 floor_ptr->grid_array[y][x].feat = val;
546 * Explanation of the plasma fractal algorithm:
548 * A grid of points is created with the properties of a 'height-map'
549 * This is done by making the corners of the grid have a random value.
550 * The grid is then subdivided into one with twice the resolution.
551 * The new points midway between two 'known' points can be calculated
552 * by taking the average value of the 'known' ones and randomly adding
553 * or subtracting an amount proportional to the distance between those
554 * points. The final 'middle' points of the grid are then calculated
555 * by averaging all four of the originally 'known' corner points. An
556 * random amount is added or subtracted from this to get a value of the
557 * height at that point. The scaling factor here is adjusted to the
558 * slightly larger distance diagonally as compared to orthogonally.
560 * This is then repeated recursively to fill an entire 'height-map'
561 * A rectangular map is done the same way, except there are different
562 * scaling factors along the x and y directions.
564 * A hack to change the amount of correlation between points is done using
565 * the grd variable. If the current step size is greater than grd then
566 * the point will be random, otherwise it will be calculated by the
567 * above algorithm. This makes a maximum distance at which two points on
568 * the height map can affect each other.
570 * How fractal caves are made:
572 * When the map is complete, a cut-off value is used to create a p_ptr->current_floor_ptr->grid_array.
573 * Heights below this value are "floor", and heights above are "wall".
574 * This also can be used to create lakes, by adding more height levels
575 * representing shallow and deep water/ lava etc.
577 * The grd variable affects the width of passages.
578 * The roug variable affects the roughness of those passages
580 * The tricky part is making sure the created p_ptr->current_floor_ptr->grid_array is connected. This
581 * is done by 'filling' from the inside and only keeping the 'filled'
582 * floor. Walls bounding the 'filled' floor are also kept. Everything
583 * else is converted to the normal _extra_.
588 * Note that this uses the p_ptr->current_floor_ptr->grid_array.feat array in a very hackish way
589 * the values are first set to zero, and then each array location
590 * is used as a "heightmap"
591 * The heightmap then needs to be converted back into the "feat" format.
593 * grd=level at which fractal turns on. smaller gives more mazelike caves
594 * roug=roughness level. 16=normal. higher values make things more convoluted
595 * small values are good for smooth walls.
596 * size=length of the side of the square p_ptr->current_floor_ptr->grid_array system.
598 void generate_hmap(floor_type *floor_ptr, POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int grd, int roug, int cutoff)
600 POSITION xhsize, yhsize, xsize, ysize, maxsize;
603 * fixed point variables- these are stored as 256 x normal value
604 * this gives 8 binary places of fractional part + 8 places of normal part
607 POSITION xstep, xhstep, ystep, yhstep;
608 POSITION xstep2, xhstep2, ystep2, yhstep2;
609 POSITION i, j, ii, jj, diagsize, xxsize, yysize;
611 /* Cache for speed */
612 POSITION xm, xp, ym, yp;
614 /* redefine size so can change the value if out of range */
618 /* Paranoia about size of the system of caves */
619 if (xsize > 254) xsize = 254;
620 if (xsize < 4) xsize = 4;
621 if (ysize > 254) ysize = 254;
622 if (ysize < 4) ysize = 4;
624 /* get offsets to middle of array */
628 /* fix rounding problem */
632 /* get limits of region */
633 fill_data.xmin = x0 - xhsize;
634 fill_data.ymin = y0 - yhsize;
635 fill_data.xmax = x0 + xhsize;
636 fill_data.ymax = y0 + yhsize;
638 /* Store cutoff in global for quick access */
639 fill_data.c1 = cutoff;
642 * Scale factor for middle points:
643 * About sqrt(2) * 256 - correct for a square lattice
644 * approximately correct for everything else.
648 /* maximum of xsize and ysize */
649 maxsize = (xsize > ysize) ? xsize : ysize;
651 /* Clear the section */
652 for (i = 0; i <= xsize; i++)
654 for (j = 0; j <= ysize; j++)
656 /* -1 is a flag for "not done yet" */
657 floor_ptr->grid_array[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
658 /* Clear icky flag because may be redoing the floor_ptr->grid_array */
659 floor_ptr->grid_array[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
663 /* Boundaries are walls */
664 floor_ptr->grid_array[fill_data.ymin][fill_data.xmin].feat = (s16b)maxsize;
665 floor_ptr->grid_array[fill_data.ymax][fill_data.xmin].feat = (s16b)maxsize;
666 floor_ptr->grid_array[fill_data.ymin][fill_data.xmax].feat = (s16b)maxsize;
667 floor_ptr->grid_array[fill_data.ymax][fill_data.xmax].feat = (s16b)maxsize;
669 /* Set the middle square to be an open area. */
670 floor_ptr->grid_array[y0][x0].feat = 0;
672 /* Initialize the step sizes */
673 xstep = xhstep = xsize * 256;
674 ystep = yhstep = ysize * 256;
675 xxsize = xsize * 256;
676 yysize = ysize * 256;
679 * Fill in the rectangle with fractal height data -
680 * like the 'plasma fractal' in fractint.
682 while ((xhstep > 256) || (yhstep > 256))
684 /* Halve the step sizes */
690 /* cache well used values */
691 xstep2 = xstep / 256;
692 ystep2 = ystep / 256;
694 xhstep2 = xhstep / 256;
695 yhstep2 = yhstep / 256;
697 /* middle top to bottom. */
698 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
700 for (j = 0; j <= yysize; j += ystep)
702 /* cache often used values */
703 ii = i / 256 + fill_data.xmin;
704 jj = j / 256 + fill_data.ymin;
707 if (floor_ptr->grid_array[jj][ii].feat == -1)
711 /* If greater than 'grid' level then is random */
712 store_height(floor_ptr, ii, jj, randint1(maxsize));
716 /* Average of left and right points +random bit */
717 store_height(floor_ptr, ii, jj,
718 (floor_ptr->grid_array[jj][fill_data.xmin + (i - xhstep) / 256].feat
719 + floor_ptr->grid_array[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
720 + (randint1(xstep2) - xhstep2) * roug / 16);
727 /* middle left to right. */
728 for (j = yhstep; j <= yysize - yhstep; j += ystep)
730 for (i = 0; i <= xxsize; i += xstep)
732 /* cache often used values */
733 ii = i / 256 + fill_data.xmin;
734 jj = j / 256 + fill_data.ymin;
737 if (floor_ptr->grid_array[jj][ii].feat == -1)
741 /* If greater than 'grid' level then is random */
742 store_height(floor_ptr, ii, jj, randint1(maxsize));
746 /* Average of up and down points +random bit */
747 store_height(floor_ptr, ii, jj,
748 (floor_ptr->grid_array[fill_data.ymin + (j - yhstep) / 256][ii].feat
749 + floor_ptr->grid_array[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
750 + (randint1(ystep2) - yhstep2) * roug / 16);
757 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
759 for (j = yhstep; j <= yysize - yhstep; j += ystep)
761 /* cache often used values */
762 ii = i / 256 + fill_data.xmin;
763 jj = j / 256 + fill_data.ymin;
766 if (floor_ptr->grid_array[jj][ii].feat == -1)
770 /* If greater than 'grid' level then is random */
771 store_height(floor_ptr, ii, jj, randint1(maxsize));
775 /* Cache reused values. */
776 xm = fill_data.xmin + (i - xhstep) / 256;
777 xp = fill_data.xmin + (i + xhstep) / 256;
778 ym = fill_data.ymin + (j - yhstep) / 256;
779 yp = fill_data.ymin + (j + yhstep) / 256;
782 * Average over all four corners + scale by diagsize to
783 * reduce the effect of the square grid on the shape of the fractal
785 store_height(floor_ptr, ii, jj,
786 (floor_ptr->grid_array[ym][xm].feat + floor_ptr->grid_array[yp][xm].feat
787 + floor_ptr->grid_array[ym][xp].feat + floor_ptr->grid_array[yp][xp].feat) / 4
788 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
797 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)
800 * function used to convert from height-map back to the
801 * normal angband floor_ptr->grid_array format
803 if (floor_ptr->grid_array[y][x].info & CAVE_ICKY)
810 /* Show that have looked at this square */
811 floor_ptr->grid_array[y][x].info|= (CAVE_ICKY);
813 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
814 if (floor_ptr->grid_array[y][x].feat <= c1)
816 /* 25% of the time use the other tile : it looks better this way */
817 if (randint1(100) < 75)
819 floor_ptr->grid_array[y][x].feat = feat1;
820 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
821 floor_ptr->grid_array[y][x].info |= info1;
826 floor_ptr->grid_array[y][x].feat = feat2;
827 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
828 floor_ptr->grid_array[y][x].info |= info2;
832 else if (floor_ptr->grid_array[y][x].feat <= c2)
834 /* 25% of the time use the other tile : it looks better this way */
835 if (randint1(100) < 75)
837 floor_ptr->grid_array[y][x].feat = feat2;
838 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
839 floor_ptr->grid_array[y][x].info |= info2;
844 floor_ptr->grid_array[y][x].feat = feat1;
845 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
846 floor_ptr->grid_array[y][x].info |= info1;
850 else if (floor_ptr->grid_array[y][x].feat <= c3)
852 floor_ptr->grid_array[y][x].feat = feat3;
853 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
854 floor_ptr->grid_array[y][x].info |= info3;
857 /* if greater than cutoff then is a wall */
860 place_outer_bold(y, x);
870 * Quick and nasty fill routine used to find the connected region
871 * of floor in the middle of the p_ptr->current_floor_ptr->grid_array
873 static void cave_fill(POSITION y, POSITION x)
884 /* Enqueue that entry */
888 /* Now process the queue */
889 while (flow_head != flow_tail)
891 /* Extract the next entry */
892 ty = tmp_pos.y[flow_head];
893 tx = tmp_pos.x[flow_head];
895 /* Forget that entry */
896 if (++flow_head == TEMP_MAX) flow_head = 0;
898 /* Add the "children" */
899 for (d = 0; d < 8; d++)
901 int old_head = flow_tail;
907 /* Paranoia Don't leave the p_ptr->current_floor_ptr->grid_array */
908 if (!in_bounds(p_ptr->current_floor_ptr, j, i))
910 /* affect boundary */
911 p_ptr->current_floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
915 /* If within bounds */
916 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
917 && (j > fill_data.ymin) && (j < fill_data.ymax))
919 /* If not a wall or floor done before */
920 if (hack_isnt_wall(p_ptr->current_floor_ptr, j, i,
921 fill_data.c1, fill_data.c2, fill_data.c3,
922 fill_data.feat1, fill_data.feat2, fill_data.feat3,
923 fill_data.info1, fill_data.info2, fill_data.info3))
925 /* Enqueue that entry */
926 tmp_pos.y[flow_tail] = (byte_hack)j;
927 tmp_pos.x[flow_tail] = (byte_hack)i;
929 /* Advance the queue */
930 if (++flow_tail == TEMP_MAX) flow_tail = 0;
932 /* Hack -- Overflow by forgetting new entry */
933 if (flow_tail == flow_head)
935 flow_tail = old_head;
939 /* keep tally of size of p_ptr->current_floor_ptr->grid_array system */
940 (fill_data.amount)++;
946 /* affect boundary */
947 p_ptr->current_floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
954 bool generate_fracave(floor_type *floor_ptr, POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int cutoff, bool light, bool room)
956 POSITION x, y, xhsize, yhsize;
959 /* offsets to middle from corner */
965 * select region connected to center of floor_ptr->grid_array system
966 * this gets rid of alot of isolated one-sqaures that
967 * can make teleport traps instadeaths...
971 fill_data.c1 = cutoff;
975 /* features to fill with */
976 fill_data.feat1 = feat_ground_type[randint0(100)];
977 fill_data.feat2 = feat_ground_type[randint0(100)];
978 fill_data.feat3 = feat_ground_type[randint0(100)];
980 fill_data.info1 = CAVE_FLOOR;
981 fill_data.info2 = CAVE_FLOOR;
982 fill_data.info3 = CAVE_FLOOR;
984 /* number of filled squares */
985 fill_data.amount = 0;
987 cave_fill((byte)y0, (byte)x0);
989 /* if tally too small, try again */
990 if (fill_data.amount < 10)
992 /* too small - clear area and try again later */
993 for (x = 0; x <= xsize; ++x)
995 for (y = 0; y <= ysize; ++y)
997 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
998 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1005 * Do boundarys-check to see if they are next to a filled region
1006 * If not then they are set to normal granite
1007 * If so then they are marked as room walls.
1009 for (i = 0; i <= xsize; ++i)
1012 if ((floor_ptr->grid_array[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1014 /* Next to a 'filled' region? - set to be room walls */
1015 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1016 if (light) floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
1017 floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
1018 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1022 /* set to be normal granite */
1023 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1026 /* bottom boundary */
1027 if ((floor_ptr->grid_array[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1029 /* Next to a 'filled' region? - set to be room walls */
1030 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1031 if (light) floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
1032 floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
1033 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1037 /* set to be normal granite */
1038 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1041 /* clear the icky flag-don't need it any more */
1042 floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1043 floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1046 /* Do the left and right boundaries minus the corners (done above) */
1047 for (i = 1; i < ysize; ++i)
1050 if ((floor_ptr->grid_array[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
1053 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1054 if (light) floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
1055 floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
1056 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1061 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1063 /* right boundary */
1064 if ((floor_ptr->grid_array[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
1067 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1068 if (light) floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
1069 floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
1070 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1075 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1078 /* clear icky flag -done with it */
1079 floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1080 floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1084 /* Do the rest: convert back to the normal format */
1085 for (x = 1; x < xsize; ++x)
1087 for (y = 1; y < ysize; ++y)
1089 if (is_floor_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize) &&
1090 (floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1092 /* Clear the icky flag in the filled region */
1093 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
1095 /* Set appropriate flags */
1096 if (light) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1097 if (room) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1099 else if (is_outer_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize) &&
1100 (floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1103 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1104 if (light) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1107 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1112 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1113 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
1118 /* Clear the unconnected regions */
1119 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1120 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1126 * There is a slight problem when tunnels pierce the caves:
1127 * Extra doors appear inside the system. (Its not very noticeable though.)
1128 * This can be removed by "filling" from the outside in. This allows a separation
1129 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
1130 * The extra effort for what seems to be only a minor thing (even non-existant if you
1131 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
1139 #ifdef ALLOW_CAVERNS_AND_LAKES
1141 * Builds a cave system in the center of the dungeon.
1143 void build_cavern(floor_type *floor_ptr)
1145 int grd, roug, cutoff;
1146 POSITION xsize, ysize, x0, y0;
1149 light = done = FALSE;
1150 if ((floor_ptr->dun_level <= randint1(50)) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) light = TRUE;
1152 /* Make a cave the size of the dungeon */
1153 xsize = floor_ptr->width - 1;
1154 ysize = floor_ptr->height - 1;
1158 /* Paranoia: make size even */
1164 /* testing values for these parameters: feel free to adjust */
1165 grd = randint1(4) + 4;
1167 /* want average of about 16 */
1168 roug = randint1(8) * randint1(4);
1174 generate_hmap(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
1176 /* Convert to normal format+ clean up */
1177 done = generate_fracave(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
1181 bool generate_lake(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int c1, int c2, int c3, int type)
1183 POSITION x, y, xhsize, yhsize;
1185 FEAT_IDX feat1, feat2, feat3;
1187 /* offsets to middle from corner */
1191 /* Get features based on type */
1194 case LAKE_T_LAVA: /* Lava */
1195 feat1 = feat_deep_lava;
1196 feat2 = feat_shallow_lava;
1197 feat3 = feat_ground_type[randint0(100)];
1199 case LAKE_T_WATER: /* Water */
1200 feat1 = feat_deep_water;
1201 feat2 = feat_shallow_water;
1202 feat3 = feat_ground_type[randint0(100)];
1204 case LAKE_T_CAVE: /* Collapsed p_ptr->current_floor_ptr->grid_array */
1205 feat1 = feat_ground_type[randint0(100)];
1206 feat2 = feat_ground_type[randint0(100)];
1207 feat3 = feat_rubble;
1209 case LAKE_T_EARTH_VAULT: /* Earth vault */
1210 feat1 = feat_rubble;
1211 feat2 = feat_ground_type[randint0(100)];
1212 feat3 = feat_rubble;
1214 case LAKE_T_AIR_VAULT: /* Air vault */
1219 case LAKE_T_WATER_VAULT: /* Water vault */
1220 feat1 = feat_shallow_water;
1221 feat2 = feat_deep_water;
1222 feat3 = feat_shallow_water;
1224 case LAKE_T_FIRE_VAULT: /* Fire Vault */
1225 feat1 = feat_shallow_lava;
1226 feat2 = feat_deep_lava;
1227 feat3 = feat_shallow_lava;
1229 default: return FALSE;
1233 * select region connected to center of p_ptr->current_floor_ptr->grid_array system
1234 * this gets rid of alot of isolated one-sqaures that
1235 * can make teleport traps instadeaths...
1243 /* features to fill with */
1244 fill_data.feat1 = feat1;
1245 fill_data.feat2 = feat2;
1246 fill_data.feat3 = feat3;
1248 fill_data.info1 = 0;
1249 fill_data.info2 = 0;
1250 fill_data.info3 = 0;
1252 /* number of filled squares */
1253 fill_data.amount = 0;
1255 /* select region connected to center of p_ptr->current_floor_ptr->grid_array system
1256 * this gets rid of alot of isolated one-sqaures that
1257 * can make teleport traps instadeaths... */
1258 cave_fill((byte)y0, (byte)x0);
1260 /* if tally too small, try again */
1261 if (fill_data.amount < 10)
1263 /* too small -clear area and try again later */
1264 for (x = 0; x <= xsize; ++x)
1266 for (y = 0; y <= ysize; ++y)
1268 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
1269 p_ptr->current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1275 /* Do boundarys- set to normal granite */
1276 for (i = 0; i <= xsize; ++i)
1278 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1279 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1281 /* clear the icky flag-don't need it any more */
1282 p_ptr->current_floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1283 p_ptr->current_floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1286 /* Do the left and right boundaries minus the corners (done above) */
1288 for (i = 1; i < ysize; ++i)
1290 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1291 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1293 /* clear icky flag -done with it */
1294 p_ptr->current_floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1295 p_ptr->current_floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1299 /* Do the rest: convert back to the normal format */
1300 for (x = 1; x < xsize; ++x)
1302 for (y = 1; y < ysize; ++y)
1304 /* Fill unconnected regions with granite */
1305 if ((!(p_ptr->current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
1306 is_outer_bold(p_ptr->current_floor_ptr, y0 + y - yhsize, x0 + x - xhsize))
1307 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1309 /* current_world_ptr->game_turn off icky flag (no longer needed.) */
1310 p_ptr->current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1313 if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
1315 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) p_ptr->current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
1325 * makes a lake/collapsed p_ptr->current_floor_ptr->grid_array system in the center of the dungeon
1327 void build_lake(int type)
1329 int grd, roug, xsize, ysize, x0, y0;
1333 /* paranoia - exit if lake type out of range. */
1334 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
1336 msg_format("Invalid lake type (%d)", type);
1340 /* Make the size of the dungeon */
1341 xsize = p_ptr->current_floor_ptr->width - 1;
1342 ysize = p_ptr->current_floor_ptr->height - 1;
1346 /* Paranoia: make size even */
1352 /* testing values for these parameters: feel free to adjust */
1353 grd = randint1(3) + 4;
1355 /* want average of about 16 */
1356 roug = randint1(8) * randint1(4);
1358 /* Make up size of various componants */
1362 /* Deep water/lava */
1363 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
1365 /* Shallow boundary */
1369 generate_hmap(p_ptr->current_floor_ptr, y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
1371 /* Convert to normal format+ clean up */
1372 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
1375 #endif /* ALLOW_CAVERNS_AND_LAKES */
1380 * Routine that fills the empty areas of a room with treasure and monsters.
1382 void fill_treasure(floor_type *floor_ptr, POSITION x1, POSITION x2, POSITION y1, POSITION y2, int difficulty)
1384 POSITION x, y, cx, cy, size;
1387 /* center of room:*/
1391 /* Rough measure of size of vault= sum of lengths of sides */
1392 size = abs(x2 - x1) + abs(y2 - y1);
1394 for (x = x1; x <= x2; x++)
1396 for (y = y1; y <= y2; y++)
1398 /* Thing added based on distance to center of vault
1399 * Difficulty is 1-easy to 10-hard */
1400 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
1402 /* hack- empty square part of the time */
1403 if ((randint1(100) - difficulty * 3) > 50) value = 20;
1405 /* if floor, shallow water and lava */
1406 if (is_floor_bold(p_ptr->current_floor_ptr, y, x) ||
1407 (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
1409 /* The smaller 'value' is, the better the stuff */
1412 /* Meanest monster + treasure */
1413 floor_ptr->monster_level = floor_ptr->base_level + 40;
1414 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1415 floor_ptr->monster_level = floor_ptr->base_level;
1416 floor_ptr->object_level = floor_ptr->base_level + 20;
1417 place_object(y, x, AM_GOOD);
1418 floor_ptr->object_level = floor_ptr->base_level;
1422 /* Mean monster +treasure */
1423 floor_ptr->monster_level = floor_ptr->base_level + 20;
1424 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1425 floor_ptr->monster_level = floor_ptr->base_level;
1426 floor_ptr->object_level = floor_ptr->base_level + 10;
1427 place_object(y, x, AM_GOOD);
1428 floor_ptr->object_level = floor_ptr->base_level;
1430 else if (value < 10)
1432 floor_ptr->monster_level = floor_ptr->base_level + 9;
1433 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1434 floor_ptr->monster_level = floor_ptr->base_level;
1436 else if (value < 17)
1438 /* Intentional Blank space */
1441 * (Want some of the vault to be empty
1442 * so have room for group monsters.
1443 * This is used in the hack above to lower
1444 * the density of stuff in the vault.)
1447 else if (value < 23)
1449 /* Object or trap */
1450 if (randint0(100) < 25)
1452 place_object(y, x, 0L);
1459 else if (value < 30)
1461 /* Monster and trap */
1462 floor_ptr->monster_level = floor_ptr->base_level + 5;
1463 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1464 floor_ptr->monster_level = floor_ptr->base_level;
1467 else if (value < 40)
1469 /* Monster or object */
1470 if (randint0(100) < 50)
1472 floor_ptr->monster_level = floor_ptr->base_level + 3;
1473 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1474 floor_ptr->monster_level = floor_ptr->base_level;
1476 if (randint0(100) < 50)
1478 floor_ptr->object_level = floor_ptr->base_level + 7;
1479 place_object(y, x, 0L);
1480 floor_ptr->object_level = floor_ptr->base_level;
1483 else if (value < 50)
1492 /* 20% monster, 40% trap, 20% object, 20% blank space */
1493 if (randint0(100) < 20)
1495 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1497 else if (randint0(100) < 50)
1501 else if (randint0(100) < 50)
1503 place_object(y, x, 0L);
1515 * Overlay a rectangular room given its bounds
1516 * This routine is used by build_room_vault
1517 * The area inside the walls is not touched:
1518 * only granite is removed- normal walls stay
1520 void build_room(floor_type *floor_ptr, POSITION x1, POSITION x2, POSITION y1, POSITION y2)
1522 POSITION x, y, xsize, ysize;
1525 /* Check if rectangle has no width */
1526 if ((x1 == x2) || (y1 == y2)) return;
1530 /* Swap boundaries if in wrong order */
1538 /* Swap boundaries if in wrong order */
1544 /* get total widths */
1549 /* Top and bottom boundaries */
1550 for (i = 0; i <= xsize; i++)
1552 place_outer_noperm_bold(y1, x1 + i);
1553 floor_ptr->grid_array[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1554 place_outer_noperm_bold(y2, x1 + i);
1555 floor_ptr->grid_array[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1558 /* Left and right boundaries */
1559 for (i = 1; i < ysize; i++)
1561 place_outer_noperm_bold(y1 + i, x1);
1562 floor_ptr->grid_array[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
1563 place_outer_noperm_bold(y1 + i, x2);
1564 floor_ptr->grid_array[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
1568 for (x = 1; x < xsize; x++)
1570 for (y = 1; y < ysize; y++)
1572 if (is_extra_bold(floor_ptr, y1+y, x1+x))
1574 /* clear the untouched region */
1575 place_floor_bold(y1 + y, x1 + x);
1576 floor_ptr->grid_array[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1580 /* make it a room- but don't touch */
1581 floor_ptr->grid_array[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1590 * maze vault -- rectangular labyrinthine rooms
1592 * maze vault uses two routines:
1593 * r_visit - a recursive routine that builds the labyrinth
1594 * build_maze_vault - a driver routine that calls r_visit and adds
1595 * monsters, traps and treasure
1597 * The labyrinth is built by creating a spanning tree of a graph.
1598 * The graph vertices are at
1599 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
1600 * and the edges are the vertical and horizontal nearest neighbors.
1602 * The spanning tree is created by performing a suitably randomized
1603 * depth-first traversal of the graph. The only adjustable parameter
1604 * is the randint0(3) below; it governs the relative density of
1605 * twists and turns in the labyrinth: smaller number, more twists.
1607 void r_visit(POSITION y1, POSITION x1, POSITION y2, POSITION x2, int node, DIRECTION dir, int *visited)
1609 int i, j, m, n, temp, x, y, adj[4];
1611 /* dimensions of vertex array */
1612 m = (x2 - x1) / 2 + 1;
1613 n = (y2 - y1) / 2 + 1;
1615 /* mark node visited and set it to a floor */
1617 x = 2 * (node % m) + x1;
1618 y = 2 * (node / m) + y1;
1619 place_floor_bold(y, x);
1621 /* setup order of adjacent node visits */
1624 /* pick a random ordering */
1625 for (i = 0; i < 4; i++)
1627 for (i = 0; i < 4; i++)
1638 /* pick a random ordering with dir first */
1640 for (i = 1; i < 4; i++)
1642 for (i = 1; i < 4; i++)
1644 j = 1 + randint0(3);
1651 for (i = 0; i < 4; i++)
1656 /* (0,+) - check for bottom boundary */
1657 if ((node / m < n - 1) && (visited[node + m] == 0))
1659 place_floor_bold(y + 1, x);
1660 r_visit(y1, x1, y2, x2, node + m, dir, visited);
1664 /* (0,-) - check for top boundary */
1665 if ((node / m > 0) && (visited[node - m] == 0))
1667 place_floor_bold(y - 1, x);
1668 r_visit(y1, x1, y2, x2, node - m, dir, visited);
1672 /* (+,0) - check for right boundary */
1673 if ((node % m < m - 1) && (visited[node + 1] == 0))
1675 place_floor_bold(y, x + 1);
1676 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
1680 /* (-,0) - check for left boundary */
1681 if ((node % m > 0) && (visited[node - 1] == 0))
1683 place_floor_bold(y, x - 1);
1684 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
1691 void build_maze_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize, bool is_vault)
1693 POSITION y, x, dy, dx;
1694 POSITION y1, x1, y2, x2;
1695 int m, n, num_vertices, *visited;
1699 msg_print_wizard(CHEAT_DUNGEON, _("迷路ランダムVaultを生成しました。", "Maze Vault."));
1701 /* Choose lite or dark */
1702 light = ((p_ptr->current_floor_ptr->dun_level <= randint1(25)) && is_vault && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS));
1704 /* Pick a random room size - randomized by calling routine */
1713 /* generate the room */
1714 for (y = y1 - 1; y <= y2 + 1; y++)
1716 for (x = x1 - 1; x <= x2 + 1; x++)
1718 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1719 g_ptr->info |= CAVE_ROOM;
1720 if (is_vault) g_ptr->info |= CAVE_ICKY;
1721 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
1723 place_outer_grid(g_ptr);
1727 place_extra_grid(g_ptr);
1731 place_inner_grid(g_ptr);
1733 if (light) g_ptr->info |= (CAVE_GLOW);
1737 /* dimensions of vertex array */
1740 num_vertices = m * n;
1742 /* initialize array of visited vertices */
1743 C_MAKE(visited, num_vertices, int);
1745 /* traverse the graph to create a spaning tree, pick a random root */
1746 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
1748 /* Fill with monsters and treasure, low difficulty */
1749 if (is_vault) fill_treasure(p_ptr->current_floor_ptr, x1, x2, y1, y2, randint1(5));
1751 C_KILL(visited, num_vertices, int);
1755 /* Build a town/ castle by using a recursive algorithm.
1756 * Basically divide each region in a probalistic way to create
1757 * smaller regions. When the regions get too small stop.
1759 * The power variable is a measure of how well defended a region is.
1760 * This alters the possible choices.
1762 void build_recursive_room(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int power)
1764 POSITION xsize, ysize;
1768 /* Temp variables */
1774 if ((power < 3) && (xsize > 12) && (ysize > 12))
1776 /* Need outside wall +keep */
1783 /* Make rooms + subdivide */
1784 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
1790 choice = randint1(2) + 1;
1795 /* Mostly subdivide */
1796 choice = randint1(3) + 1;
1800 /* Based on the choice made above, do something */
1808 /* top and bottom */
1809 for (x = x1; x <= x2; x++)
1811 place_outer_bold(y1, x);
1812 place_outer_bold(y2, x);
1815 /* left and right */
1816 for (y = y1 + 1; y < y2; y++)
1818 place_outer_bold(y, x1);
1819 place_outer_bold(y, x2);
1822 /* Make a couple of entrances */
1825 /* left and right */
1826 y = randint1(ysize) + y1;
1827 place_floor_bold(y, x1);
1828 place_floor_bold(y, x2);
1832 /* top and bottom */
1833 x = randint1(xsize) + x1;
1834 place_floor_bold(y1, x);
1835 place_floor_bold(y2, x);
1838 /* Select size of keep */
1839 t1 = randint1(ysize / 3) + y1;
1840 t2 = y2 - randint1(ysize / 3);
1841 t3 = randint1(xsize / 3) + x1;
1842 t4 = x2 - randint1(xsize / 3);
1844 /* Do outside areas */
1846 /* Above and below keep */
1847 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
1848 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
1850 /* Left and right of keep */
1851 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
1852 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
1854 /* Make the keep itself: */
1867 /* Try to build a room */
1868 if ((xsize < 3) || (ysize < 3))
1870 for (y = y1; y < y2; y++)
1872 for (x = x1; x < x2; x++)
1874 place_inner_bold(y, x);
1882 /* Make outside walls */
1883 /* top and bottom */
1884 for (x = x1 + 1; x <= x2 - 1; x++)
1886 place_inner_bold(y1 + 1, x);
1887 place_inner_bold(y2 - 1, x);
1890 /* left and right */
1891 for (y = y1 + 1; y <= y2 - 1; y++)
1893 place_inner_bold(y, x1 + 1);
1894 place_inner_bold(y, x2 - 1);
1898 y = randint1(ysize - 3) + y1 + 1;
1903 place_floor_bold(y, x1 + 1);
1908 place_floor_bold(y, x2 - 1);
1911 /* Build the room */
1912 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
1917 /* Try and divide vertically */
1921 for (y = y1; y < y2; y++)
1923 for (x = x1; x < x2; x++)
1925 place_inner_bold(y, x);
1931 t1 = randint1(xsize - 2) + x1 + 1;
1932 build_recursive_room(x1, y1, t1, y2, power - 2);
1933 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
1938 /* Try and divide horizontally */
1942 for (y = y1; y < y2; y++)
1944 for (x = x1; x < x2; x++)
1946 place_inner_bold(y, x);
1952 t1 = randint1(ysize - 2) + y1 + 1;
1953 build_recursive_room(x1, y1, x2, t1, power - 2);
1954 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
1962 * Add outer wall to a floored region
1963 * Note: no range checking is done so must be inside dungeon
1964 * This routine also stomps on doors
1966 void add_outer_wall(POSITION x, POSITION y, int light, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
1969 feature_type *f_ptr;
1972 if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
1974 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1976 /* hack- check to see if square has been visited before
1977 * if so, then exit (use room flag to do this) */
1978 if (g_ptr->info & CAVE_ROOM) return;
1981 g_ptr->info |= CAVE_ROOM;
1983 f_ptr = &f_info[g_ptr->feat];
1985 if (is_floor_bold(p_ptr->current_floor_ptr, y, x))
1987 for (i = -1; i <= 1; i++)
1989 for (j = -1; j <= 1; j++)
1991 if ((x + i >= x1) && (x + i <= x2) &&
1992 (y + j >= y1) && (y + j <= y2))
1994 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
1995 if (light) g_ptr->info |= CAVE_GLOW;
2000 else if (is_extra_bold(p_ptr->current_floor_ptr, y, x))
2002 /* Set bounding walls */
2003 place_outer_bold(y, x);
2004 if (light) g_ptr->info |= CAVE_GLOW;
2006 else if (permanent_wall(f_ptr))
2008 /* Set bounding walls */
2009 if (light) g_ptr->info |= CAVE_GLOW;
2015 * Hacked distance formula - gives the 'wrong' answer.
2016 * Used to build crypts
2018 POSITION dist2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, POSITION h1, POSITION h2, POSITION h3, POSITION h4)
2024 /* Basically this works by taking the normal pythagorean formula
2025 * and using an expansion to express this in a way without the
2026 * square root. This approximate formula is then perturbed to give
2027 * the distorted results. (I found this by making a mistake when I was
2028 * trying to fix the circular rooms.)
2031 /* h1-h4 are constants that describe the metric */
2032 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
2033 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
2034 return (((dx + dy) * 128) / 181 +
2035 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
2036 /* 128/181 is approx. 1/sqrt(2) */
2042 /* Create a new floor room with optional light */
2043 void generate_room_floor(POSITION y1, POSITION x1, POSITION y2, POSITION x2, int light)
2049 for (y = y1; y <= y2; y++)
2051 for (x = x1; x <= x2; x++)
2054 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
2055 place_floor_grid(g_ptr);
2056 g_ptr->info |= (CAVE_ROOM);
2057 if (light) g_ptr->info |= (CAVE_GLOW);
2062 void generate_fill_perm_bold(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
2066 for (y = y1; y <= y2; y++)
2068 for (x = x1; x <= x2; x++)
2071 place_inner_perm_bold(y, x);
2078 * @brief 与えられた部屋型IDに応じて部屋の生成処理分岐を行い結果を返す / Attempt to build a room of the given type at the given block
2080 * @note that we restrict the number of "crowded" rooms to reduce the chance of overflowing the monster list during level creation.
2081 * @return 部屋の精製に成功した場合 TRUE を返す。
2083 static bool room_build(EFFECT_ID typ)
2088 /* Build an appropriate room */
2089 case ROOM_T_NORMAL: return build_type1(p_ptr->current_floor_ptr);
2090 case ROOM_T_OVERLAP: return build_type2(p_ptr->current_floor_ptr);
2091 case ROOM_T_CROSS: return build_type3(p_ptr->current_floor_ptr);
2092 case ROOM_T_INNER_FEAT: return build_type4(p_ptr->current_floor_ptr);
2093 case ROOM_T_NEST: return build_type5(p_ptr->current_floor_ptr);
2094 case ROOM_T_PIT: return build_type6(p_ptr->current_floor_ptr);
2095 case ROOM_T_LESSER_VAULT: return build_type7();
2096 case ROOM_T_GREATER_VAULT: return build_type8();
2097 case ROOM_T_FRACAVE: return build_type9();
2098 case ROOM_T_RANDOM_VAULT: return build_type10();
2099 case ROOM_T_OVAL: return build_type11(p_ptr->current_floor_ptr);
2100 case ROOM_T_CRYPT: return build_type12(p_ptr->current_floor_ptr);
2101 case ROOM_T_TRAP_PIT: return build_type13(p_ptr->current_floor_ptr);
2102 case ROOM_T_TRAP: return build_type14();
2103 case ROOM_T_GLASS: return build_type15();
2104 case ROOM_T_ARCADE: return build_type16();
2105 case ROOM_T_FIXED: return build_type17();
2111 * @brief 指定した部屋の生成確率を別の部屋に加算し、指定した部屋の生成率を0にする
2112 * @param dst 確率を移す先の部屋種ID
2113 * @param src 確率を与える元の部屋種ID
2115 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
2118 * @brief 部屋生成処理のメインルーチン(Sangbandを経由してOangbandからの実装を引用) / Generate rooms in dungeon. Build bigger rooms at first. [from SAngband (originally from OAngband)]
2119 * @return 部屋生成に成功した場合 TRUE を返す。
2121 bool generate_rooms(void)
2127 int prob_list[ROOM_T_MAX];
2128 int rooms_built = 0;
2129 int area_size = 100 * (p_ptr->current_floor_ptr->height*p_ptr->current_floor_ptr->width) / (MAX_HGT*MAX_WID);
2130 int level_index = MIN(10, div_round(p_ptr->current_floor_ptr->dun_level, 10));
2132 /* Number of each type of room on this level */
2133 s16b room_num[ROOM_T_MAX];
2135 /* Limit number of rooms */
2136 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
2138 /* Assume normal p_ptr->current_floor_ptr->grid_array */
2139 room_info_type *room_info_ptr = room_info_normal;
2142 * Initialize probability list.
2144 for (i = 0; i < ROOM_T_MAX; i++)
2146 /* No rooms allowed above their minimum depth. */
2147 if (p_ptr->current_floor_ptr->dun_level < room_info_ptr[i].min_level)
2153 prob_list[i] = room_info_ptr[i].prob[level_index];
2158 * XXX -- Various dungeon types and options.
2161 /*! @details ダンジョンにBEGINNER、CHAMELEON、SMALLESTいずれのフラグもなく、
2162 * かつ「常に通常でない部屋を生成する」フラグがONならば、
2163 * GRATER_VAULTのみを生成対象とする。 / Ironman sees only Greater Vaults */
2164 if (ironman_rooms && !((d_info[p_ptr->dungeon_idx].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
2166 for (i = 0; i < ROOM_T_MAX; i++)
2168 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
2169 else prob_list[i] = 0;
2173 /*! @details ダンジョンにNO_VAULTフラグがあるならば、LESSER_VAULT / GREATER_VAULT/ RANDOM_VAULTを除外 / Forbidden vaults */
2174 else if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_VAULT)
2176 prob_list[ROOM_T_LESSER_VAULT] = 0;
2177 prob_list[ROOM_T_GREATER_VAULT] = 0;
2178 prob_list[ROOM_T_RANDOM_VAULT] = 0;
2181 /*! @details ダンジョンにBEGINNERフラグがあるならば、FIXED_ROOMを除外 / Forbidden vaults */
2182 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER)
2184 prob_list[ROOM_T_FIXED] = 0;
2187 /*! @details ダンジョンにNO_CAVEフラグがある場合、FRACAVEの生成枠がNORMALに与えられる。CRIPT、OVALの生成枠がINNER_Fに与えられる。/ NO_CAVE dungeon (Castle)*/
2188 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE)
2190 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
2191 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
2192 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
2195 /*! @details ダンジョンにCAVEフラグがある場合、NORMALの生成枠がFRACAVEに与えられる。/ CAVE dungeon (Orc p_ptr->current_floor_ptr->grid_array etc.) */
2196 else if (d_info[p_ptr->dungeon_idx].flags1 & DF1_CAVE)
2198 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
2201 /*! @details ダンジョンの基本地形が最初から渓谷かアリーナ型の場合 FRACAVE は生成から除外。 / No caves when a (random) cavern exists: they look bad */
2202 else if (dun->cavern || dun->empty_level)
2204 prob_list[ROOM_T_FRACAVE] = 0;
2207 /*! @details ダンジョンに最初からGLASS_ROOMフラグがある場合、GLASS を生成から除外。/ Forbidden glass rooms */
2208 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_ROOM))
2210 prob_list[ROOM_T_GLASS] = 0;
2213 /*! @details ARCADEは同フラグがダンジョンにないと生成されない。 / Forbidden glass rooms */
2214 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_ARCADE))
2216 prob_list[ROOM_T_ARCADE] = 0;
2220 * Initialize number of rooms,
2221 * And calcurate total probability.
2223 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
2226 total_prob += prob_list[i];
2230 * Prepare the number of rooms, of all types, we should build
2233 for (i = dun_rooms; i > 0; i--)
2236 int rand = randint0(total_prob);
2238 /* Get room_type randomly */
2239 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
2241 if (rand < prob_list[room_type]) break;
2242 else rand -= prob_list[room_type];
2244 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
2246 /* Increase the number of rooms of that type we should build. */
2247 room_num[room_type]++;
2253 case ROOM_T_LESSER_VAULT:
2254 case ROOM_T_TRAP_PIT:
2262 case ROOM_T_GREATER_VAULT:
2263 case ROOM_T_RANDOM_VAULT:
2272 * Build each type of room one by one until we cannot build any more.
2273 * [from SAngband (originally from OAngband)]
2277 /* Assume no remaining rooms */
2280 for (i = 0; i < ROOM_T_MAX; i++)
2282 /* What type of room are we building now? */
2283 int room_type = room_build_order[i];
2285 /* Go next if none available */
2286 if (!room_num[room_type]) continue;
2288 /* Use up one unit */
2289 room_num[room_type]--;
2291 /* Build the room. */
2292 if (room_build(room_type))
2294 /* Increase the room built count. */
2297 /* Mark as there was some remaining rooms */
2304 case ROOM_T_TRAP_PIT:
2306 /* Avoid too many monsters */
2309 room_num[ROOM_T_PIT] = 0;
2310 room_num[ROOM_T_NEST] = 0;
2311 room_num[ROOM_T_TRAP_PIT] = 0;
2317 /* Avoid double-town */
2318 room_num[ROOM_T_ARCADE] = 0;
2324 /* End loop if no room remain */
2328 /*! @details 部屋生成数が2未満の場合生成失敗を返す */
2329 if (rooms_built < 2)
2331 msg_format_wizard(CHEAT_DUNGEON, _("部屋数が2未満でした。生成を再試行します。", "Number of rooms was under 2. Retry."), rooms_built);
2335 msg_format_wizard(CHEAT_DUNGEON, _("このダンジョンの部屋数は %d です。", "Number of Rooms: %d"), rooms_built);