3 * @brief ダンジョンフロアの部屋生成処理 / make rooms. Used by generate.c when creating dungeons.
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7 * This software may be copied and distributed for educational, research,\n
8 * and not for profit purposes provided that this copyright and statement\n
9 * are included in all such copies. Other copyrights may also apply.\n
10 * 2014 Deskull rearranged comment for Doxygen. \n
12 * Room building routines.\n
18 * 4 -- large room with features\n
19 * 5 -- monster nests\n
21 * 7 -- simple vaults\n
22 * 8 -- greater vaults\n
23 * 9 -- fractal caves\n
24 * 10 -- random vaults\n
25 * 11 -- circular rooms\n
27 * 13 -- trapped monster pits\n
28 * 14 -- trapped room\n
30 * 16 -- underground arcade\n
32 * Some functions are used to determine if the given monster\n
33 * is appropriate for inclusion in a monster nest or monster pit or\n
36 * None of the pits/nests are allowed to include "unique" monsters.\n
44 #include "rooms-city.h"
45 #include "rooms-fractal.h"
46 #include "rooms-normal.h"
47 #include "rooms-pitnest.h"
48 #include "rooms-special.h"
49 #include "rooms-trap.h"
50 #include "rooms-vault.h"
59 *[from SAngband (originally from OAngband)]\n
61 * Table of values that control how many times each type of room will\n
62 * appear. Each type of room has its own row, and each column\n
63 * corresponds to dungeon levels 0, 10, 20, and so on. The final\n
64 * value is the minimum depth the room can appear at. -LM-\n
66 * Level 101 and below use the values for level 100.\n
68 * Rooms with lots of monsters or loot may not be generated if the\n
69 * object or monster lists are already nearly full. Rooms will not\n
70 * appear above their minimum depth. Tiny levels will not have space\n
71 * for all the rooms you ask for.\n
76 static room_info_type room_info_normal[ROOM_T_MAX] =
79 /* 0 10 20 30 40 50 60 70 80 90 100 min limit */
80 {{999,900,800,700,600,500,400,300,200,100, 0}, 0}, /*NORMAL */
81 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 1}, /*OVERLAP */
82 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*CROSS */
83 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*INNER_F */
84 {{ 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 13}, 10}, /*NEST */
85 {{ 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 16}, 10}, /*PIT */
86 {{ 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 10}, 10}, /*LESSER_V */
87 {{ 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4}, 20}, /*GREATER_V*/
88 {{ 0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE */
89 {{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}, 10}, /*RANDOM_V */
90 {{ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40}, 3}, /*OVAL */
91 {{ 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT */
92 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP_PIT */
93 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP */
94 {{ 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2}, 40}, /*GLASS */
95 {{ 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3}, 1}, /*ARCADE */
96 {{ 1, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80}, 1}, /*FIX */
102 static room_info_type room_info_normal[ROOM_T_MAX] =
105 { {999, 900, 800, 700, 600, 500, 400, 300, 200, 100, 0}, 0}, /*NORMAL */
106 { { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0}, 1 }, /*OVERLAP */
107 { { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0}, 3 }, /*CROSS */
108 { { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0}, 3 }, /*INNER_F */
109 { { 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 0}, 10 }, /*NEST */
110 { { 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 0}, 10 }, /*PIT */
111 { { 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 0}, 10 }, /*LESSER_V */
112 { { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 0}, 20 }, /*GREATER_V*/
113 { { 0,100,200,300,400,500,600,700,800,900, 0}, 10 }, /*FRACAVE */
114 { { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0}, 10 }, /*RANDOM_V */
115 { { 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 0}, 3 }, /*OVAL */
116 { { 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 0}, 10 }, /*CRYPT */
117 { { 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 0}, 20 }, /*TRAP_PIT */
118 { { 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 0}, 20 }, /*TRAP */
119 { { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 0}, 40 }, /*GLASS */
120 { { 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 0}, 1 }, /*ARCADE */
121 { { 20, 40, 60, 80,100,100,100,100,100,100,100}, 1 }, /*FIX */
128 /*! 部屋の生成処理順 / Build rooms in descending order of difficulty. */
129 static byte room_build_order[ROOM_T_MAX] = {
130 ROOM_T_GREATER_VAULT,
150 * @brief 1マスだけの部屋を作成し、上下左右いずれか一つに隠しドアを配置する。
151 * @param y0 配置したい中心のY座標
152 * @param x0 配置したい中心のX座標
154 * This funtion makes a very small room centred at (x0, y0)
155 * This is used in crypts, and random elemental vaults.
157 * Note - this should be used only on allocated regions
158 * within another room.
160 void build_small_room(POSITION x0, POSITION y0)
164 for (y = y0 - 1; y <= y0 + 1; y++)
166 place_inner_bold(y, x0 - 1);
167 place_inner_bold(y, x0 + 1);
170 for (x = x0 - 1; x <= x0 + 1; x++)
172 place_inner_bold(y0 - 1, x);
173 place_inner_bold(y0 + 1, x);
176 /* Place a secret door on one side */
179 case 0: place_secret_door(y0, x0 - 1, DOOR_DEFAULT); break;
180 case 1: place_secret_door(y0, x0 + 1, DOOR_DEFAULT); break;
181 case 2: place_secret_door(y0 - 1, x0, DOOR_DEFAULT); break;
182 case 3: place_secret_door(y0 + 1, x0, DOOR_DEFAULT); break;
185 /* Clear mimic type */
186 current_floor_ptr->grid_array[y0][x0].mimic = 0;
188 /* Add inner open space */
189 place_floor_bold(y0, x0);
194 * 指定範囲に通路が通っていることを確認した上で床で埋める
195 * This function tunnels around a room if it will cut off part of a current_floor_ptr->grid_array system.
202 static void check_room_boundary(POSITION x1, POSITION y1, POSITION x2, POSITION y2)
206 bool old_is_floor, new_is_floor;
209 old_is_floor = get_is_floor(x1 - 1, y1);
212 * Count the number of floor-wall boundaries around the room
213 * Note: diagonal squares are ignored since the player can move diagonally
214 * to bypass these if needed.
217 /* Above the top boundary */
218 for (x = x1; x <= x2; x++)
220 new_is_floor = get_is_floor(x, y1 - 1);
222 /* Increment counter if they are different */
223 if (new_is_floor != old_is_floor) count++;
225 old_is_floor = new_is_floor;
229 for (y = y1; y <= y2; y++)
231 new_is_floor = get_is_floor(x2 + 1, y);
233 /* increment counter if they are different */
234 if (new_is_floor != old_is_floor) count++;
236 old_is_floor = new_is_floor;
239 /* Bottom boundary */
240 for (x = x2; x >= x1; x--)
242 new_is_floor = get_is_floor(x, y2 + 1);
244 /* increment counter if they are different */
245 if (new_is_floor != old_is_floor) count++;
247 old_is_floor = new_is_floor;
251 for (y = y2; y >= y1; y--)
253 new_is_floor = get_is_floor(x1 - 1, y);
255 /* increment counter if they are different */
256 if (new_is_floor != old_is_floor) count++;
258 old_is_floor = new_is_floor;
261 /* If all the same, or only one connection exit. */
262 if (count <= 2) return;
265 /* Tunnel around the room so to prevent problems with caves */
266 for (y = y1; y <= y2; y++)
268 for (x = x1; x <= x2; x++)
278 * find_space()の予備処理として部屋の生成が可能かを判定する /
279 * Helper function for find_space(). Is this a good location?
280 * @param blocks_high 範囲の高さ
281 * @param blocks_wide 範囲の幅
282 * @param block_y 範囲の上端
283 * @param block_x 範囲の左端
286 static bool find_space_aux(POSITION blocks_high, POSITION blocks_wide, POSITION block_y, POSITION block_x)
288 POSITION by1, bx1, by2, bx2, by, bx;
290 /* Itty-bitty rooms must shift about within their rectangle */
293 if ((blocks_wide == 2) && (block_x % 3) == 2)
297 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
298 else if ((blocks_wide % 3) == 0)
300 /* Must be aligned to the left edge of a 11x33 rectangle. */
301 if ((block_x % 3) != 0)
306 * Big rooms that do not have a width divisible by 3 must be
307 * aligned towards the edge of the dungeon closest to them.
311 /* Shift towards left edge of dungeon. */
312 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
314 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
316 if ((block_x % 3) == 1)
320 /* Shift toward right edge of dungeon. */
323 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
325 if ((block_x % 3) == 1)
333 by2 = block_y + blocks_high;
334 bx2 = block_x + blocks_wide;
336 /* Never run off the screen */
337 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
338 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
340 /* Verify available space */
341 for (by = by1; by < by2; by++)
343 for (bx = bx1; bx < bx2; bx++)
345 if (dun->room_map[by][bx])
352 /* This location is okay */
358 * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room. -LM-
359 * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
360 * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
361 * @param height 確保したい領域の高さ
362 * @param width 確保したい領域の幅
363 * @return 所定の範囲が確保できた場合TRUEを返す
365 * Find and allocate a free space in the dungeon large enough to hold\n
366 * the room calling this function.\n
368 * We allocate space in 11x11 blocks, but want to make sure that rooms\n
369 * align neatly on the standard screen. Therefore, we make them use\n
370 * blocks in few 11x33 rectangles as possible.\n
372 * Be careful to include the edges of the room in height and width!\n
374 * Return TRUE and values for the center of the room if all went well.\n
375 * Otherwise, return FALSE.\n
377 bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
379 int candidates, pick;
380 POSITION by, bx, by1, bx1, by2, bx2;
381 POSITION block_y = 0, block_x = 0;
383 /* Find out how many blocks we need. */
384 POSITION blocks_high = 1 + ((height - 1) / BLOCK_HGT);
385 POSITION blocks_wide = 1 + ((width - 1) / BLOCK_WID);
387 /* There are no way to allocate such huge space */
388 if (dun->row_rooms < blocks_high) return FALSE;
389 if (dun->col_rooms < blocks_wide) return FALSE;
394 /* Count the number of valid places */
395 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
397 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
399 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
401 /* Find a valid place */
414 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE))
416 /* Choose a random one */
417 pick = randint1(candidates);
420 /* NO_CAVE dungeon (Castle) */
423 /* Always choose the center one */
424 pick = candidates/2 + 1;
427 /* Pick up the choosen location */
428 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
430 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
432 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
436 /* This one is picked? */
447 by2 = block_y + blocks_high;
448 bx2 = block_x + blocks_wide;
451 * It is *extremely* important that the following calculation
452 * be *exactly* correct to prevent memory errors
455 /* Acquire the location of the room */
456 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
457 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
459 /* Save the room location */
460 if (dun->cent_n < CENT_MAX)
462 dun->cent[dun->cent_n].y = (byte_hack)*y;
463 dun->cent[dun->cent_n].x = (byte_hack)*x;
467 /* Reserve some blocks. */
468 for (by = by1; by < by2; by++)
470 for (bx = bx1; bx < bx2; bx++)
472 dun->room_map[by][bx] = TRUE;
477 * Hack- See if room will cut off a cavern.
479 * If so, fix by tunneling outside the room in such a
480 * way as to connect the caves.
482 check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
490 * Structure to hold all "fill" data
493 typedef struct fill_data_type fill_data_type;
495 struct fill_data_type
508 /* features to fill with */
517 /* number of filled squares */
521 static fill_data_type fill_data;
524 /* Store routine for the fractal current_floor_ptr->grid_array generator */
525 /* this routine probably should be an inline function or a macro. */
526 static void store_height(POSITION x, POSITION y, FEAT_IDX val)
528 /* if on boundary set val > cutoff so walls are not as square */
529 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
530 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
531 (val <= fill_data.c1)) val = fill_data.c1 + 1;
533 /* store the value in height-map format */
534 current_floor_ptr->grid_array[y][x].feat = val;
541 * Explanation of the plasma fractal algorithm:
543 * A grid of points is created with the properties of a 'height-map'
544 * This is done by making the corners of the grid have a random value.
545 * The grid is then subdivided into one with twice the resolution.
546 * The new points midway between two 'known' points can be calculated
547 * by taking the average value of the 'known' ones and randomly adding
548 * or subtracting an amount proportional to the distance between those
549 * points. The final 'middle' points of the grid are then calculated
550 * by averaging all four of the originally 'known' corner points. An
551 * random amount is added or subtracted from this to get a value of the
552 * height at that point. The scaling factor here is adjusted to the
553 * slightly larger distance diagonally as compared to orthogonally.
555 * This is then repeated recursively to fill an entire 'height-map'
556 * A rectangular map is done the same way, except there are different
557 * scaling factors along the x and y directions.
559 * A hack to change the amount of correlation between points is done using
560 * the grd variable. If the current step size is greater than grd then
561 * the point will be random, otherwise it will be calculated by the
562 * above algorithm. This makes a maximum distance at which two points on
563 * the height map can affect each other.
565 * How fractal caves are made:
567 * When the map is complete, a cut-off value is used to create a current_floor_ptr->grid_array.
568 * Heights below this value are "floor", and heights above are "wall".
569 * This also can be used to create lakes, by adding more height levels
570 * representing shallow and deep water/ lava etc.
572 * The grd variable affects the width of passages.
573 * The roug variable affects the roughness of those passages
575 * The tricky part is making sure the created current_floor_ptr->grid_array is connected. This
576 * is done by 'filling' from the inside and only keeping the 'filled'
577 * floor. Walls bounding the 'filled' floor are also kept. Everything
578 * else is converted to the normal _extra_.
583 * Note that this uses the current_floor_ptr->grid_array.feat array in a very hackish way
584 * the values are first set to zero, and then each array location
585 * is used as a "heightmap"
586 * The heightmap then needs to be converted back into the "feat" format.
588 * grd=level at which fractal turns on. smaller gives more mazelike caves
589 * roug=roughness level. 16=normal. higher values make things more convoluted
590 * small values are good for smooth walls.
591 * size=length of the side of the square current_floor_ptr->grid_array system.
593 void generate_hmap(POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int grd, int roug, int cutoff)
595 POSITION xhsize, yhsize, xsize, ysize, maxsize;
598 * fixed point variables- these are stored as 256 x normal value
599 * this gives 8 binary places of fractional part + 8 places of normal part
602 POSITION xstep, xhstep, ystep, yhstep;
603 POSITION xstep2, xhstep2, ystep2, yhstep2;
604 POSITION i, j, ii, jj, diagsize, xxsize, yysize;
606 /* Cache for speed */
607 POSITION xm, xp, ym, yp;
609 /* redefine size so can change the value if out of range */
613 /* Paranoia about size of the system of caves */
614 if (xsize > 254) xsize = 254;
615 if (xsize < 4) xsize = 4;
616 if (ysize > 254) ysize = 254;
617 if (ysize < 4) ysize = 4;
619 /* get offsets to middle of array */
623 /* fix rounding problem */
627 /* get limits of region */
628 fill_data.xmin = x0 - xhsize;
629 fill_data.ymin = y0 - yhsize;
630 fill_data.xmax = x0 + xhsize;
631 fill_data.ymax = y0 + yhsize;
633 /* Store cutoff in global for quick access */
634 fill_data.c1 = cutoff;
637 * Scale factor for middle points:
638 * About sqrt(2) * 256 - correct for a square lattice
639 * approximately correct for everything else.
643 /* maximum of xsize and ysize */
644 maxsize = (xsize > ysize) ? xsize : ysize;
646 /* Clear the section */
647 for (i = 0; i <= xsize; i++)
649 for (j = 0; j <= ysize; j++)
651 /* -1 is a flag for "not done yet" */
652 current_floor_ptr->grid_array[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
653 /* Clear icky flag because may be redoing the current_floor_ptr->grid_array */
654 current_floor_ptr->grid_array[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
658 /* Boundaries are walls */
659 current_floor_ptr->grid_array[fill_data.ymin][fill_data.xmin].feat = (s16b)maxsize;
660 current_floor_ptr->grid_array[fill_data.ymax][fill_data.xmin].feat = (s16b)maxsize;
661 current_floor_ptr->grid_array[fill_data.ymin][fill_data.xmax].feat = (s16b)maxsize;
662 current_floor_ptr->grid_array[fill_data.ymax][fill_data.xmax].feat = (s16b)maxsize;
664 /* Set the middle square to be an open area. */
665 current_floor_ptr->grid_array[y0][x0].feat = 0;
667 /* Initialize the step sizes */
668 xstep = xhstep = xsize * 256;
669 ystep = yhstep = ysize * 256;
670 xxsize = xsize * 256;
671 yysize = ysize * 256;
674 * Fill in the rectangle with fractal height data -
675 * like the 'plasma fractal' in fractint.
677 while ((xhstep > 256) || (yhstep > 256))
679 /* Halve the step sizes */
685 /* cache well used values */
686 xstep2 = xstep / 256;
687 ystep2 = ystep / 256;
689 xhstep2 = xhstep / 256;
690 yhstep2 = yhstep / 256;
692 /* middle top to bottom. */
693 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
695 for (j = 0; j <= yysize; j += ystep)
697 /* cache often used values */
698 ii = i / 256 + fill_data.xmin;
699 jj = j / 256 + fill_data.ymin;
702 if (current_floor_ptr->grid_array[jj][ii].feat == -1)
706 /* If greater than 'grid' level then is random */
707 store_height(ii, jj, randint1(maxsize));
711 /* Average of left and right points +random bit */
713 (current_floor_ptr->grid_array[jj][fill_data.xmin + (i - xhstep) / 256].feat
714 + current_floor_ptr->grid_array[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
715 + (randint1(xstep2) - xhstep2) * roug / 16);
722 /* middle left to right. */
723 for (j = yhstep; j <= yysize - yhstep; j += ystep)
725 for (i = 0; i <= xxsize; i += xstep)
727 /* cache often used values */
728 ii = i / 256 + fill_data.xmin;
729 jj = j / 256 + fill_data.ymin;
732 if (current_floor_ptr->grid_array[jj][ii].feat == -1)
736 /* If greater than 'grid' level then is random */
737 store_height(ii, jj, randint1(maxsize));
741 /* Average of up and down points +random bit */
743 (current_floor_ptr->grid_array[fill_data.ymin + (j - yhstep) / 256][ii].feat
744 + current_floor_ptr->grid_array[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
745 + (randint1(ystep2) - yhstep2) * roug / 16);
752 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
754 for (j = yhstep; j <= yysize - yhstep; j += ystep)
756 /* cache often used values */
757 ii = i / 256 + fill_data.xmin;
758 jj = j / 256 + fill_data.ymin;
761 if (current_floor_ptr->grid_array[jj][ii].feat == -1)
765 /* If greater than 'grid' level then is random */
766 store_height(ii, jj, randint1(maxsize));
770 /* Cache reused values. */
771 xm = fill_data.xmin + (i - xhstep) / 256;
772 xp = fill_data.xmin + (i + xhstep) / 256;
773 ym = fill_data.ymin + (j - yhstep) / 256;
774 yp = fill_data.ymin + (j + yhstep) / 256;
777 * Average over all four corners + scale by diagsize to
778 * reduce the effect of the square grid on the shape of the fractal
781 (current_floor_ptr->grid_array[ym][xm].feat + current_floor_ptr->grid_array[yp][xm].feat
782 + current_floor_ptr->grid_array[ym][xp].feat + current_floor_ptr->grid_array[yp][xp].feat) / 4
783 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
792 static bool hack_isnt_wall(POSITION y, POSITION x, int c1, int c2, int c3, FEAT_IDX feat1, FEAT_IDX feat2, FEAT_IDX feat3, BIT_FLAGS info1, BIT_FLAGS info2, BIT_FLAGS info3)
795 * function used to convert from height-map back to the
796 * normal angband current_floor_ptr->grid_array format
798 if (current_floor_ptr->grid_array[y][x].info & CAVE_ICKY)
805 /* Show that have looked at this square */
806 current_floor_ptr->grid_array[y][x].info|= (CAVE_ICKY);
808 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
809 if (current_floor_ptr->grid_array[y][x].feat <= c1)
811 /* 25% of the time use the other tile : it looks better this way */
812 if (randint1(100) < 75)
814 current_floor_ptr->grid_array[y][x].feat = feat1;
815 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
816 current_floor_ptr->grid_array[y][x].info |= info1;
821 current_floor_ptr->grid_array[y][x].feat = feat2;
822 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
823 current_floor_ptr->grid_array[y][x].info |= info2;
827 else if (current_floor_ptr->grid_array[y][x].feat <= c2)
829 /* 25% of the time use the other tile : it looks better this way */
830 if (randint1(100) < 75)
832 current_floor_ptr->grid_array[y][x].feat = feat2;
833 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
834 current_floor_ptr->grid_array[y][x].info |= info2;
839 current_floor_ptr->grid_array[y][x].feat = feat1;
840 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
841 current_floor_ptr->grid_array[y][x].info |= info1;
845 else if (current_floor_ptr->grid_array[y][x].feat <= c3)
847 current_floor_ptr->grid_array[y][x].feat = feat3;
848 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
849 current_floor_ptr->grid_array[y][x].info |= info3;
852 /* if greater than cutoff then is a wall */
855 place_outer_bold(y, x);
865 * Quick and nasty fill routine used to find the connected region
866 * of floor in the middle of the current_floor_ptr->grid_array
868 static void cave_fill(POSITION y, POSITION x)
879 /* Enqueue that entry */
883 /* Now process the queue */
884 while (flow_head != flow_tail)
886 /* Extract the next entry */
887 ty = tmp_pos.y[flow_head];
888 tx = tmp_pos.x[flow_head];
890 /* Forget that entry */
891 if (++flow_head == TEMP_MAX) flow_head = 0;
893 /* Add the "children" */
894 for (d = 0; d < 8; d++)
896 int old_head = flow_tail;
902 /* Paranoia Don't leave the current_floor_ptr->grid_array */
903 if (!in_bounds(j, i))
905 /* affect boundary */
906 current_floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
910 /* If within bounds */
911 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
912 && (j > fill_data.ymin) && (j < fill_data.ymax))
914 /* If not a wall or floor done before */
915 if (hack_isnt_wall(j, i,
916 fill_data.c1, fill_data.c2, fill_data.c3,
917 fill_data.feat1, fill_data.feat2, fill_data.feat3,
918 fill_data.info1, fill_data.info2, fill_data.info3))
920 /* Enqueue that entry */
921 tmp_pos.y[flow_tail] = (byte_hack)j;
922 tmp_pos.x[flow_tail] = (byte_hack)i;
924 /* Advance the queue */
925 if (++flow_tail == TEMP_MAX) flow_tail = 0;
927 /* Hack -- Overflow by forgetting new entry */
928 if (flow_tail == flow_head)
930 flow_tail = old_head;
934 /* keep tally of size of current_floor_ptr->grid_array system */
935 (fill_data.amount)++;
941 /* affect boundary */
942 current_floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
949 bool generate_fracave(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int cutoff, bool light, bool room)
951 POSITION x, y, xhsize, yhsize;
954 /* offsets to middle from corner */
960 * select region connected to center of current_floor_ptr->grid_array system
961 * this gets rid of alot of isolated one-sqaures that
962 * can make teleport traps instadeaths...
966 fill_data.c1 = cutoff;
970 /* features to fill with */
971 fill_data.feat1 = feat_ground_type[randint0(100)];
972 fill_data.feat2 = feat_ground_type[randint0(100)];
973 fill_data.feat3 = feat_ground_type[randint0(100)];
975 fill_data.info1 = CAVE_FLOOR;
976 fill_data.info2 = CAVE_FLOOR;
977 fill_data.info3 = CAVE_FLOOR;
979 /* number of filled squares */
980 fill_data.amount = 0;
982 cave_fill((byte)y0, (byte)x0);
984 /* if tally too small, try again */
985 if (fill_data.amount < 10)
987 /* too small - clear area and try again later */
988 for (x = 0; x <= xsize; ++x)
990 for (y = 0; y <= ysize; ++y)
992 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
993 current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1000 * Do boundarys-check to see if they are next to a filled region
1001 * If not then they are set to normal granite
1002 * If so then they are marked as room walls.
1004 for (i = 0; i <= xsize; ++i)
1007 if ((current_floor_ptr->grid_array[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1009 /* Next to a 'filled' region? - set to be room walls */
1010 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1011 if (light) current_floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
1012 current_floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
1013 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1017 /* set to be normal granite */
1018 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1021 /* bottom boundary */
1022 if ((current_floor_ptr->grid_array[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1024 /* Next to a 'filled' region? - set to be room walls */
1025 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1026 if (light) current_floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
1027 current_floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
1028 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1032 /* set to be normal granite */
1033 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1036 /* clear the icky flag-don't need it any more */
1037 current_floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1038 current_floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1041 /* Do the left and right boundaries minus the corners (done above) */
1042 for (i = 1; i < ysize; ++i)
1045 if ((current_floor_ptr->grid_array[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
1048 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1049 if (light) current_floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
1050 current_floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
1051 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1056 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1058 /* right boundary */
1059 if ((current_floor_ptr->grid_array[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
1062 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1063 if (light) current_floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
1064 current_floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
1065 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1070 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1073 /* clear icky flag -done with it */
1074 current_floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1075 current_floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1079 /* Do the rest: convert back to the normal format */
1080 for (x = 1; x < xsize; ++x)
1082 for (y = 1; y < ysize; ++y)
1084 if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
1085 (current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1087 /* Clear the icky flag in the filled region */
1088 current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
1090 /* Set appropriate flags */
1091 if (light) current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1092 if (room) current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1094 else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
1095 (current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1098 current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1099 if (light) current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1102 current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1107 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1108 current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
1113 /* Clear the unconnected regions */
1114 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1115 current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1121 * There is a slight problem when tunnels pierce the caves:
1122 * Extra doors appear inside the system. (Its not very noticeable though.)
1123 * This can be removed by "filling" from the outside in. This allows a separation
1124 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
1125 * The extra effort for what seems to be only a minor thing (even non-existant if you
1126 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
1134 #ifdef ALLOW_CAVERNS_AND_LAKES
1136 * Builds a current_floor_ptr->grid_array system in the center of the dungeon.
1138 void build_cavern(void)
1140 int grd, roug, cutoff;
1141 POSITION xsize, ysize, x0, y0;
1144 light = done = FALSE;
1145 if ((current_floor_ptr->dun_level <= randint1(50)) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) light = TRUE;
1147 /* Make a current_floor_ptr->grid_array the size of the dungeon */
1148 xsize = current_floor_ptr->width - 1;
1149 ysize = current_floor_ptr->height - 1;
1153 /* Paranoia: make size even */
1159 /* testing values for these parameters: feel free to adjust */
1160 grd = randint1(4) + 4;
1162 /* want average of about 16 */
1163 roug = randint1(8) * randint1(4);
1169 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
1171 /* Convert to normal format+ clean up */
1172 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
1176 bool generate_lake(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int c1, int c2, int c3, int type)
1178 POSITION x, y, xhsize, yhsize;
1180 FEAT_IDX feat1, feat2, feat3;
1182 /* offsets to middle from corner */
1186 /* Get features based on type */
1189 case LAKE_T_LAVA: /* Lava */
1190 feat1 = feat_deep_lava;
1191 feat2 = feat_shallow_lava;
1192 feat3 = feat_ground_type[randint0(100)];
1194 case LAKE_T_WATER: /* Water */
1195 feat1 = feat_deep_water;
1196 feat2 = feat_shallow_water;
1197 feat3 = feat_ground_type[randint0(100)];
1199 case LAKE_T_CAVE: /* Collapsed current_floor_ptr->grid_array */
1200 feat1 = feat_ground_type[randint0(100)];
1201 feat2 = feat_ground_type[randint0(100)];
1202 feat3 = feat_rubble;
1204 case LAKE_T_EARTH_VAULT: /* Earth vault */
1205 feat1 = feat_rubble;
1206 feat2 = feat_ground_type[randint0(100)];
1207 feat3 = feat_rubble;
1209 case LAKE_T_AIR_VAULT: /* Air vault */
1214 case LAKE_T_WATER_VAULT: /* Water vault */
1215 feat1 = feat_shallow_water;
1216 feat2 = feat_deep_water;
1217 feat3 = feat_shallow_water;
1219 case LAKE_T_FIRE_VAULT: /* Fire Vault */
1220 feat1 = feat_shallow_lava;
1221 feat2 = feat_deep_lava;
1222 feat3 = feat_shallow_lava;
1224 default: return FALSE;
1228 * select region connected to center of current_floor_ptr->grid_array system
1229 * this gets rid of alot of isolated one-sqaures that
1230 * can make teleport traps instadeaths...
1238 /* features to fill with */
1239 fill_data.feat1 = feat1;
1240 fill_data.feat2 = feat2;
1241 fill_data.feat3 = feat3;
1243 fill_data.info1 = 0;
1244 fill_data.info2 = 0;
1245 fill_data.info3 = 0;
1247 /* number of filled squares */
1248 fill_data.amount = 0;
1250 /* select region connected to center of current_floor_ptr->grid_array system
1251 * this gets rid of alot of isolated one-sqaures that
1252 * can make teleport traps instadeaths... */
1253 cave_fill((byte)y0, (byte)x0);
1255 /* if tally too small, try again */
1256 if (fill_data.amount < 10)
1258 /* too small -clear area and try again later */
1259 for (x = 0; x <= xsize; ++x)
1261 for (y = 0; y <= ysize; ++y)
1263 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
1264 current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1270 /* Do boundarys- set to normal granite */
1271 for (i = 0; i <= xsize; ++i)
1273 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1274 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1276 /* clear the icky flag-don't need it any more */
1277 current_floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1278 current_floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1281 /* Do the left and right boundaries minus the corners (done above) */
1283 for (i = 1; i < ysize; ++i)
1285 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1286 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1288 /* clear icky flag -done with it */
1289 current_floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1290 current_floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1294 /* Do the rest: convert back to the normal format */
1295 for (x = 1; x < xsize; ++x)
1297 for (y = 1; y < ysize; ++y)
1299 /* Fill unconnected regions with granite */
1300 if ((!(current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
1301 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
1302 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1304 /* current_world_ptr->game_turn off icky flag (no longer needed.) */
1305 current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1308 if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
1310 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
1320 * makes a lake/collapsed current_floor_ptr->grid_array system in the center of the dungeon
1322 void build_lake(int type)
1324 int grd, roug, xsize, ysize, x0, y0;
1328 /* paranoia - exit if lake type out of range. */
1329 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
1331 msg_format("Invalid lake type (%d)", type);
1335 /* Make the size of the dungeon */
1336 xsize = current_floor_ptr->width - 1;
1337 ysize = current_floor_ptr->height - 1;
1341 /* Paranoia: make size even */
1347 /* testing values for these parameters: feel free to adjust */
1348 grd = randint1(3) + 4;
1350 /* want average of about 16 */
1351 roug = randint1(8) * randint1(4);
1353 /* Make up size of various componants */
1357 /* Deep water/lava */
1358 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
1360 /* Shallow boundary */
1364 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
1366 /* Convert to normal format+ clean up */
1367 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
1370 #endif /* ALLOW_CAVERNS_AND_LAKES */
1375 * Routine that fills the empty areas of a room with treasure and monsters.
1377 void fill_treasure(POSITION x1, POSITION x2, POSITION y1, POSITION y2, int difficulty)
1379 POSITION x, y, cx, cy, size;
1382 /* center of room:*/
1386 /* Rough measure of size of vault= sum of lengths of sides */
1387 size = abs(x2 - x1) + abs(y2 - y1);
1389 for (x = x1; x <= x2; x++)
1391 for (y = y1; y <= y2; y++)
1393 /* Thing added based on distance to center of vault
1394 * Difficulty is 1-easy to 10-hard */
1395 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
1397 /* hack- empty square part of the time */
1398 if ((randint1(100) - difficulty * 3) > 50) value = 20;
1400 /* if floor, shallow water and lava */
1401 if (is_floor_bold(y, x) ||
1402 (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
1404 /* The smaller 'value' is, the better the stuff */
1407 /* Meanest monster + treasure */
1408 current_floor_ptr->monster_level = current_floor_ptr->base_level + 40;
1409 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1410 current_floor_ptr->monster_level = current_floor_ptr->base_level;
1411 current_floor_ptr->object_level = current_floor_ptr->base_level + 20;
1412 place_object(y, x, AM_GOOD);
1413 current_floor_ptr->object_level = current_floor_ptr->base_level;
1417 /* Mean monster +treasure */
1418 current_floor_ptr->monster_level = current_floor_ptr->base_level + 20;
1419 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1420 current_floor_ptr->monster_level = current_floor_ptr->base_level;
1421 current_floor_ptr->object_level = current_floor_ptr->base_level + 10;
1422 place_object(y, x, AM_GOOD);
1423 current_floor_ptr->object_level = current_floor_ptr->base_level;
1425 else if (value < 10)
1427 current_floor_ptr->monster_level = current_floor_ptr->base_level + 9;
1428 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1429 current_floor_ptr->monster_level = current_floor_ptr->base_level;
1431 else if (value < 17)
1433 /* Intentional Blank space */
1436 * (Want some of the vault to be empty
1437 * so have room for group monsters.
1438 * This is used in the hack above to lower
1439 * the density of stuff in the vault.)
1442 else if (value < 23)
1444 /* Object or trap */
1445 if (randint0(100) < 25)
1447 place_object(y, x, 0L);
1454 else if (value < 30)
1456 /* Monster and trap */
1457 current_floor_ptr->monster_level = current_floor_ptr->base_level + 5;
1458 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1459 current_floor_ptr->monster_level = current_floor_ptr->base_level;
1462 else if (value < 40)
1464 /* Monster or object */
1465 if (randint0(100) < 50)
1467 current_floor_ptr->monster_level = current_floor_ptr->base_level + 3;
1468 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1469 current_floor_ptr->monster_level = current_floor_ptr->base_level;
1471 if (randint0(100) < 50)
1473 current_floor_ptr->object_level = current_floor_ptr->base_level + 7;
1474 place_object(y, x, 0L);
1475 current_floor_ptr->object_level = current_floor_ptr->base_level;
1478 else if (value < 50)
1487 /* 20% monster, 40% trap, 20% object, 20% blank space */
1488 if (randint0(100) < 20)
1490 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1492 else if (randint0(100) < 50)
1496 else if (randint0(100) < 50)
1498 place_object(y, x, 0L);
1510 * Overlay a rectangular room given its bounds
1511 * This routine is used by build_room_vault
1512 * The area inside the walls is not touched:
1513 * only granite is removed- normal walls stay
1515 void build_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2)
1517 POSITION x, y, xsize, ysize;
1520 /* Check if rectangle has no width */
1521 if ((x1 == x2) || (y1 == y2)) return;
1525 /* Swap boundaries if in wrong order */
1533 /* Swap boundaries if in wrong order */
1539 /* get total widths */
1544 /* Top and bottom boundaries */
1545 for (i = 0; i <= xsize; i++)
1547 place_outer_noperm_bold(y1, x1 + i);
1548 current_floor_ptr->grid_array[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1549 place_outer_noperm_bold(y2, x1 + i);
1550 current_floor_ptr->grid_array[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1553 /* Left and right boundaries */
1554 for (i = 1; i < ysize; i++)
1556 place_outer_noperm_bold(y1 + i, x1);
1557 current_floor_ptr->grid_array[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
1558 place_outer_noperm_bold(y1 + i, x2);
1559 current_floor_ptr->grid_array[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
1563 for (x = 1; x < xsize; x++)
1565 for (y = 1; y < ysize; y++)
1567 if (is_extra_bold(y1+y, x1+x))
1569 /* clear the untouched region */
1570 place_floor_bold(y1 + y, x1 + x);
1571 current_floor_ptr->grid_array[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1575 /* make it a room- but don't touch */
1576 current_floor_ptr->grid_array[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1585 * maze vault -- rectangular labyrinthine rooms
1587 * maze vault uses two routines:
1588 * r_visit - a recursive routine that builds the labyrinth
1589 * build_maze_vault - a driver routine that calls r_visit and adds
1590 * monsters, traps and treasure
1592 * The labyrinth is built by creating a spanning tree of a graph.
1593 * The graph vertices are at
1594 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
1595 * and the edges are the vertical and horizontal nearest neighbors.
1597 * The spanning tree is created by performing a suitably randomized
1598 * depth-first traversal of the graph. The only adjustable parameter
1599 * is the randint0(3) below; it governs the relative density of
1600 * twists and turns in the labyrinth: smaller number, more twists.
1602 void r_visit(POSITION y1, POSITION x1, POSITION y2, POSITION x2, int node, DIRECTION dir, int *visited)
1604 int i, j, m, n, temp, x, y, adj[4];
1606 /* dimensions of vertex array */
1607 m = (x2 - x1) / 2 + 1;
1608 n = (y2 - y1) / 2 + 1;
1610 /* mark node visited and set it to a floor */
1612 x = 2 * (node % m) + x1;
1613 y = 2 * (node / m) + y1;
1614 place_floor_bold(y, x);
1616 /* setup order of adjacent node visits */
1619 /* pick a random ordering */
1620 for (i = 0; i < 4; i++)
1622 for (i = 0; i < 4; i++)
1633 /* pick a random ordering with dir first */
1635 for (i = 1; i < 4; i++)
1637 for (i = 1; i < 4; i++)
1639 j = 1 + randint0(3);
1646 for (i = 0; i < 4; i++)
1651 /* (0,+) - check for bottom boundary */
1652 if ((node / m < n - 1) && (visited[node + m] == 0))
1654 place_floor_bold(y + 1, x);
1655 r_visit(y1, x1, y2, x2, node + m, dir, visited);
1659 /* (0,-) - check for top boundary */
1660 if ((node / m > 0) && (visited[node - m] == 0))
1662 place_floor_bold(y - 1, x);
1663 r_visit(y1, x1, y2, x2, node - m, dir, visited);
1667 /* (+,0) - check for right boundary */
1668 if ((node % m < m - 1) && (visited[node + 1] == 0))
1670 place_floor_bold(y, x + 1);
1671 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
1675 /* (-,0) - check for left boundary */
1676 if ((node % m > 0) && (visited[node - 1] == 0))
1678 place_floor_bold(y, x - 1);
1679 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
1686 void build_maze_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize, bool is_vault)
1688 POSITION y, x, dy, dx;
1689 POSITION y1, x1, y2, x2;
1690 int m, n, num_vertices, *visited;
1694 msg_print_wizard(CHEAT_DUNGEON, _("迷路ランダムVaultを生成しました。", "Maze Vault."));
1696 /* Choose lite or dark */
1697 light = ((current_floor_ptr->dun_level <= randint1(25)) && is_vault && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS));
1699 /* Pick a random room size - randomized by calling routine */
1708 /* generate the room */
1709 for (y = y1 - 1; y <= y2 + 1; y++)
1711 for (x = x1 - 1; x <= x2 + 1; x++)
1713 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1714 g_ptr->info |= CAVE_ROOM;
1715 if (is_vault) g_ptr->info |= CAVE_ICKY;
1716 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
1718 place_outer_grid(g_ptr);
1722 place_extra_grid(g_ptr);
1726 place_inner_grid(g_ptr);
1728 if (light) g_ptr->info |= (CAVE_GLOW);
1732 /* dimensions of vertex array */
1735 num_vertices = m * n;
1737 /* initialize array of visited vertices */
1738 C_MAKE(visited, num_vertices, int);
1740 /* traverse the graph to create a spaning tree, pick a random root */
1741 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
1743 /* Fill with monsters and treasure, low difficulty */
1744 if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
1746 C_KILL(visited, num_vertices, int);
1750 /* Build a town/ castle by using a recursive algorithm.
1751 * Basically divide each region in a probalistic way to create
1752 * smaller regions. When the regions get too small stop.
1754 * The power variable is a measure of how well defended a region is.
1755 * This alters the possible choices.
1757 void build_recursive_room(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int power)
1759 POSITION xsize, ysize;
1763 /* Temp variables */
1769 if ((power < 3) && (xsize > 12) && (ysize > 12))
1771 /* Need outside wall +keep */
1778 /* Make rooms + subdivide */
1779 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
1785 choice = randint1(2) + 1;
1790 /* Mostly subdivide */
1791 choice = randint1(3) + 1;
1795 /* Based on the choice made above, do something */
1803 /* top and bottom */
1804 for (x = x1; x <= x2; x++)
1806 place_outer_bold(y1, x);
1807 place_outer_bold(y2, x);
1810 /* left and right */
1811 for (y = y1 + 1; y < y2; y++)
1813 place_outer_bold(y, x1);
1814 place_outer_bold(y, x2);
1817 /* Make a couple of entrances */
1820 /* left and right */
1821 y = randint1(ysize) + y1;
1822 place_floor_bold(y, x1);
1823 place_floor_bold(y, x2);
1827 /* top and bottom */
1828 x = randint1(xsize) + x1;
1829 place_floor_bold(y1, x);
1830 place_floor_bold(y2, x);
1833 /* Select size of keep */
1834 t1 = randint1(ysize / 3) + y1;
1835 t2 = y2 - randint1(ysize / 3);
1836 t3 = randint1(xsize / 3) + x1;
1837 t4 = x2 - randint1(xsize / 3);
1839 /* Do outside areas */
1841 /* Above and below keep */
1842 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
1843 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
1845 /* Left and right of keep */
1846 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
1847 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
1849 /* Make the keep itself: */
1862 /* Try to build a room */
1863 if ((xsize < 3) || (ysize < 3))
1865 for (y = y1; y < y2; y++)
1867 for (x = x1; x < x2; x++)
1869 place_inner_bold(y, x);
1877 /* Make outside walls */
1878 /* top and bottom */
1879 for (x = x1 + 1; x <= x2 - 1; x++)
1881 place_inner_bold(y1 + 1, x);
1882 place_inner_bold(y2 - 1, x);
1885 /* left and right */
1886 for (y = y1 + 1; y <= y2 - 1; y++)
1888 place_inner_bold(y, x1 + 1);
1889 place_inner_bold(y, x2 - 1);
1893 y = randint1(ysize - 3) + y1 + 1;
1898 place_floor_bold(y, x1 + 1);
1903 place_floor_bold(y, x2 - 1);
1906 /* Build the room */
1907 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
1912 /* Try and divide vertically */
1916 for (y = y1; y < y2; y++)
1918 for (x = x1; x < x2; x++)
1920 place_inner_bold(y, x);
1926 t1 = randint1(xsize - 2) + x1 + 1;
1927 build_recursive_room(x1, y1, t1, y2, power - 2);
1928 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
1933 /* Try and divide horizontally */
1937 for (y = y1; y < y2; y++)
1939 for (x = x1; x < x2; x++)
1941 place_inner_bold(y, x);
1947 t1 = randint1(ysize - 2) + y1 + 1;
1948 build_recursive_room(x1, y1, x2, t1, power - 2);
1949 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
1957 * Add outer wall to a floored region
1958 * Note: no range checking is done so must be inside dungeon
1959 * This routine also stomps on doors
1961 void add_outer_wall(POSITION x, POSITION y, int light, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
1964 feature_type *f_ptr;
1967 if (!in_bounds(y, x)) return;
1969 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1971 /* hack- check to see if square has been visited before
1972 * if so, then exit (use room flag to do this) */
1973 if (g_ptr->info & CAVE_ROOM) return;
1976 g_ptr->info |= CAVE_ROOM;
1978 f_ptr = &f_info[g_ptr->feat];
1980 if (is_floor_bold(y, x))
1982 for (i = -1; i <= 1; i++)
1984 for (j = -1; j <= 1; j++)
1986 if ((x + i >= x1) && (x + i <= x2) &&
1987 (y + j >= y1) && (y + j <= y2))
1989 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
1990 if (light) g_ptr->info |= CAVE_GLOW;
1995 else if (is_extra_bold(y, x))
1997 /* Set bounding walls */
1998 place_outer_bold(y, x);
1999 if (light) g_ptr->info |= CAVE_GLOW;
2001 else if (permanent_wall(f_ptr))
2003 /* Set bounding walls */
2004 if (light) g_ptr->info |= CAVE_GLOW;
2010 * Hacked distance formula - gives the 'wrong' answer.
2011 * Used to build crypts
2013 POSITION dist2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, POSITION h1, POSITION h2, POSITION h3, POSITION h4)
2019 /* Basically this works by taking the normal pythagorean formula
2020 * and using an expansion to express this in a way without the
2021 * square root. This approximate formula is then perturbed to give
2022 * the distorted results. (I found this by making a mistake when I was
2023 * trying to fix the circular rooms.)
2026 /* h1-h4 are constants that describe the metric */
2027 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
2028 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
2029 return (((dx + dy) * 128) / 181 +
2030 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
2031 /* 128/181 is approx. 1/sqrt(2) */
2037 /* Create a new floor room with optional light */
2038 void generate_room_floor(POSITION y1, POSITION x1, POSITION y2, POSITION x2, int light)
2044 for (y = y1; y <= y2; y++)
2046 for (x = x1; x <= x2; x++)
2049 g_ptr = ¤t_floor_ptr->grid_array[y][x];
2050 place_floor_grid(g_ptr);
2051 g_ptr->info |= (CAVE_ROOM);
2052 if (light) g_ptr->info |= (CAVE_GLOW);
2057 void generate_fill_perm_bold(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
2061 for (y = y1; y <= y2; y++)
2063 for (x = x1; x <= x2; x++)
2066 place_inner_perm_bold(y, x);
2073 * @brief 与えられた部屋型IDに応じて部屋の生成処理分岐を行い結果を返す / Attempt to build a room of the given type at the given block
2075 * @note that we restrict the number of "crowded" rooms to reduce the chance of overflowing the monster list during level creation.
2076 * @return 部屋の精製に成功した場合 TRUE を返す。
2078 static bool room_build(EFFECT_ID typ)
2083 /* Build an appropriate room */
2084 case ROOM_T_NORMAL: return build_type1();
2085 case ROOM_T_OVERLAP: return build_type2();
2086 case ROOM_T_CROSS: return build_type3();
2087 case ROOM_T_INNER_FEAT: return build_type4();
2088 case ROOM_T_NEST: return build_type5();
2089 case ROOM_T_PIT: return build_type6();
2090 case ROOM_T_LESSER_VAULT: return build_type7();
2091 case ROOM_T_GREATER_VAULT: return build_type8();
2092 case ROOM_T_FRACAVE: return build_type9();
2093 case ROOM_T_RANDOM_VAULT: return build_type10();
2094 case ROOM_T_OVAL: return build_type11();
2095 case ROOM_T_CRYPT: return build_type12();
2096 case ROOM_T_TRAP_PIT: return build_type13();
2097 case ROOM_T_TRAP: return build_type14();
2098 case ROOM_T_GLASS: return build_type15();
2099 case ROOM_T_ARCADE: return build_type16();
2100 case ROOM_T_FIXED: return build_type17();
2106 * @brief 指定した部屋の生成確率を別の部屋に加算し、指定した部屋の生成率を0にする
2107 * @param dst 確率を移す先の部屋種ID
2108 * @param src 確率を与える元の部屋種ID
2110 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
2113 * @brief 部屋生成処理のメインルーチン(Sangbandを経由してOangbandからの実装を引用) / Generate rooms in dungeon. Build bigger rooms at first. [from SAngband (originally from OAngband)]
2114 * @return 部屋生成に成功した場合 TRUE を返す。
2116 bool generate_rooms(void)
2122 int prob_list[ROOM_T_MAX];
2123 int rooms_built = 0;
2124 int area_size = 100 * (current_floor_ptr->height*current_floor_ptr->width) / (MAX_HGT*MAX_WID);
2125 int level_index = MIN(10, div_round(current_floor_ptr->dun_level, 10));
2127 /* Number of each type of room on this level */
2128 s16b room_num[ROOM_T_MAX];
2130 /* Limit number of rooms */
2131 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
2133 /* Assume normal current_floor_ptr->grid_array */
2134 room_info_type *room_info_ptr = room_info_normal;
2137 * Initialize probability list.
2139 for (i = 0; i < ROOM_T_MAX; i++)
2141 /* No rooms allowed above their minimum depth. */
2142 if (current_floor_ptr->dun_level < room_info_ptr[i].min_level)
2148 prob_list[i] = room_info_ptr[i].prob[level_index];
2153 * XXX -- Various dungeon types and options.
2156 /*! @details ダンジョンにBEGINNER、CHAMELEON、SMALLESTいずれのフラグもなく、
2157 * かつ「常に通常でない部屋を生成する」フラグがONならば、
2158 * GRATER_VAULTのみを生成対象とする。 / Ironman sees only Greater Vaults */
2159 if (ironman_rooms && !((d_info[p_ptr->dungeon_idx].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
2161 for (i = 0; i < ROOM_T_MAX; i++)
2163 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
2164 else prob_list[i] = 0;
2168 /*! @details ダンジョンにNO_VAULTフラグがあるならば、LESSER_VAULT / GREATER_VAULT/ RANDOM_VAULTを除外 / Forbidden vaults */
2169 else if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_VAULT)
2171 prob_list[ROOM_T_LESSER_VAULT] = 0;
2172 prob_list[ROOM_T_GREATER_VAULT] = 0;
2173 prob_list[ROOM_T_RANDOM_VAULT] = 0;
2176 /*! @details ダンジョンにBEGINNERフラグがあるならば、FIXED_ROOMを除外 / Forbidden vaults */
2177 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER)
2179 prob_list[ROOM_T_FIXED] = 0;
2182 /*! @details ダンジョンにNO_CAVEフラグがある場合、FRACAVEの生成枠がNORMALに与えられる。CRIPT、OVALの生成枠がINNER_Fに与えられる。/ NO_CAVE dungeon (Castle)*/
2183 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE)
2185 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
2186 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
2187 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
2190 /*! @details ダンジョンにCAVEフラグがある場合、NORMALの生成枠がFRACAVEに与えられる。/ CAVE dungeon (Orc current_floor_ptr->grid_array etc.) */
2191 else if (d_info[p_ptr->dungeon_idx].flags1 & DF1_CAVE)
2193 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
2196 /*! @details ダンジョンの基本地形が最初から渓谷かアリーナ型の場合 FRACAVE は生成から除外。 / No caves when a (random) cavern exists: they look bad */
2197 else if (dun->cavern || dun->empty_level)
2199 prob_list[ROOM_T_FRACAVE] = 0;
2202 /*! @details ダンジョンに最初からGLASS_ROOMフラグがある場合、GLASS を生成から除外。/ Forbidden glass rooms */
2203 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_ROOM))
2205 prob_list[ROOM_T_GLASS] = 0;
2208 /*! @details ARCADEは同フラグがダンジョンにないと生成されない。 / Forbidden glass rooms */
2209 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_ARCADE))
2211 prob_list[ROOM_T_ARCADE] = 0;
2215 * Initialize number of rooms,
2216 * And calcurate total probability.
2218 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
2221 total_prob += prob_list[i];
2225 * Prepare the number of rooms, of all types, we should build
2228 for (i = dun_rooms; i > 0; i--)
2231 int rand = randint0(total_prob);
2233 /* Get room_type randomly */
2234 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
2236 if (rand < prob_list[room_type]) break;
2237 else rand -= prob_list[room_type];
2239 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
2241 /* Increase the number of rooms of that type we should build. */
2242 room_num[room_type]++;
2248 case ROOM_T_LESSER_VAULT:
2249 case ROOM_T_TRAP_PIT:
2257 case ROOM_T_GREATER_VAULT:
2258 case ROOM_T_RANDOM_VAULT:
2267 * Build each type of room one by one until we cannot build any more.
2268 * [from SAngband (originally from OAngband)]
2272 /* Assume no remaining rooms */
2275 for (i = 0; i < ROOM_T_MAX; i++)
2277 /* What type of room are we building now? */
2278 int room_type = room_build_order[i];
2280 /* Go next if none available */
2281 if (!room_num[room_type]) continue;
2283 /* Use up one unit */
2284 room_num[room_type]--;
2286 /* Build the room. */
2287 if (room_build(room_type))
2289 /* Increase the room built count. */
2292 /* Mark as there was some remaining rooms */
2299 case ROOM_T_TRAP_PIT:
2301 /* Avoid too many monsters */
2304 room_num[ROOM_T_PIT] = 0;
2305 room_num[ROOM_T_NEST] = 0;
2306 room_num[ROOM_T_TRAP_PIT] = 0;
2312 /* Avoid double-town */
2313 room_num[ROOM_T_ARCADE] = 0;
2319 /* End loop if no room remain */
2323 /*! @details 部屋生成数が2未満の場合生成失敗を返す */
2324 if (rooms_built < 2)
2326 msg_format_wizard(CHEAT_DUNGEON, _("部屋数が2未満でした。生成を再試行します。", "Number of rooms was under 2. Retry."), rooms_built);
2330 msg_format_wizard(CHEAT_DUNGEON, _("このダンジョンの部屋数は %d です。", "Number of Rooms: %d"), rooms_built);