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 */
106 /*! 部屋の生成処理順 / Build rooms in descending order of difficulty. */
107 static byte room_build_order[ROOM_T_MAX] = {
108 ROOM_T_GREATER_VAULT,
128 * @brief 1マスだけの部屋を作成し、上下左右いずれか一つに隠しドアを配置する。
129 * @param player_ptr プレーヤーへの参照ポインタ
130 * @param y0 配置したい中心のY座標
131 * @param x0 配置したい中心のX座標
133 * This funtion makes a very small room centred at (x0, y0)
134 * This is used in crypts, and random elemental vaults.
136 * Note - this should be used only on allocated regions
137 * within another room.
139 void build_small_room(player_type *player_ptr, POSITION x0, POSITION y0)
143 floor_type *floor_ptr = player_ptr->current_floor_ptr;
144 for (y = y0 - 1; y <= y0 + 1; y++)
146 place_inner_bold(floor_ptr, y, x0 - 1);
147 place_inner_bold(floor_ptr, y, x0 + 1);
150 for (x = x0 - 1; x <= x0 + 1; x++)
152 place_inner_bold(floor_ptr, y0 - 1, x);
153 place_inner_bold(floor_ptr, y0 + 1, x);
156 /* Place a secret door on one side */
159 case 0: place_secret_door(player_ptr, y0, x0 - 1, DOOR_DEFAULT); break;
160 case 1: place_secret_door(player_ptr, y0, x0 + 1, DOOR_DEFAULT); break;
161 case 2: place_secret_door(player_ptr, y0 - 1, x0, DOOR_DEFAULT); break;
162 case 3: place_secret_door(player_ptr, y0 + 1, x0, DOOR_DEFAULT); break;
165 /* Clear mimic type */
166 floor_ptr->grid_array[y0][x0].mimic = 0;
168 /* Add inner open space */
169 place_floor_bold(floor_ptr, y0, x0);
174 * 指定範囲に通路が通っていることを確認した上で床で埋める
175 * This function tunnels around a room if it will cut off part of a grid system.
182 static void check_room_boundary(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
186 bool old_is_floor, new_is_floor;
189 old_is_floor = get_is_floor(floor_ptr, x1 - 1, y1);
192 * Count the number of floor-wall boundaries around the room
193 * Note: diagonal squares are ignored since the player can move diagonally
194 * to bypass these if needed.
197 /* Above the top boundary */
198 for (x = x1; x <= x2; x++)
200 new_is_floor = get_is_floor(floor_ptr, x, y1 - 1);
202 /* Increment counter if they are different */
203 if (new_is_floor != old_is_floor) count++;
205 old_is_floor = new_is_floor;
209 for (y = y1; y <= y2; y++)
211 new_is_floor = get_is_floor(floor_ptr, x2 + 1, y);
213 /* increment counter if they are different */
214 if (new_is_floor != old_is_floor) count++;
216 old_is_floor = new_is_floor;
219 /* Bottom boundary */
220 for (x = x2; x >= x1; x--)
222 new_is_floor = get_is_floor(floor_ptr, x, y2 + 1);
224 /* increment counter if they are different */
225 if (new_is_floor != old_is_floor) count++;
227 old_is_floor = new_is_floor;
231 for (y = y2; y >= y1; y--)
233 new_is_floor = get_is_floor(floor_ptr, x1 - 1, y);
235 /* increment counter if they are different */
236 if (new_is_floor != old_is_floor) count++;
238 old_is_floor = new_is_floor;
241 /* If all the same, or only one connection exit. */
242 if (count <= 2) return;
245 /* Tunnel around the room so to prevent problems with caves */
246 for (y = y1; y <= y2; y++)
248 for (x = x1; x <= x2; x++)
250 set_floor(floor_ptr, x, y);
258 * find_space()の予備処理として部屋の生成が可能かを判定する /
259 * Helper function for find_space(). Is this a good location?
260 * @param blocks_high 範囲の高さ
261 * @param blocks_wide 範囲の幅
262 * @param block_y 範囲の上端
263 * @param block_x 範囲の左端
266 static bool find_space_aux(POSITION blocks_high, POSITION blocks_wide, POSITION block_y, POSITION block_x)
268 POSITION by1, bx1, by2, bx2, by, bx;
270 /* Itty-bitty rooms must shift about within their rectangle */
273 if ((blocks_wide == 2) && (block_x % 3) == 2)
277 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
278 else if ((blocks_wide % 3) == 0)
280 /* Must be aligned to the left edge of a 11x33 rectangle. */
281 if ((block_x % 3) != 0)
286 * Big rooms that do not have a width divisible by 3 must be
287 * aligned towards the edge of the dungeon closest to them.
291 /* Shift towards left edge of dungeon. */
292 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
294 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
296 if ((block_x % 3) == 1)
300 /* Shift toward right edge of dungeon. */
303 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
305 if ((block_x % 3) == 1)
313 by2 = block_y + blocks_high;
314 bx2 = block_x + blocks_wide;
316 /* Never run off the screen */
317 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
318 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
320 /* Verify available space */
321 for (by = by1; by < by2; by++)
323 for (bx = bx1; bx < bx2; bx++)
325 if (dun->room_map[by][bx])
332 /* This location is okay */
338 * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room. -LM-
339 * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
340 * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
341 * @param height 確保したい領域の高さ
342 * @param width 確保したい領域の幅
343 * @return 所定の範囲が確保できた場合TRUEを返す
345 * Find and allocate a free space in the dungeon large enough to hold\n
346 * the room calling this function.\n
348 * We allocate space in 11x11 blocks, but want to make sure that rooms\n
349 * align neatly on the standard screen. Therefore, we make them use\n
350 * blocks in few 11x33 rectangles as possible.\n
352 * Be careful to include the edges of the room in height and width!\n
354 * Return TRUE and values for the center of the room if all went well.\n
355 * Otherwise, return FALSE.\n
357 bool find_space(floor_type *floor_ptr, POSITION *y, POSITION *x, POSITION height, POSITION width)
359 int candidates, pick;
360 POSITION by, bx, by1, bx1, by2, bx2;
361 POSITION block_y = 0, block_x = 0;
363 /* Find out how many blocks we need. */
364 POSITION blocks_high = 1 + ((height - 1) / BLOCK_HGT);
365 POSITION blocks_wide = 1 + ((width - 1) / BLOCK_WID);
367 /* There are no way to allocate such huge space */
368 if (dun->row_rooms < blocks_high) return FALSE;
369 if (dun->col_rooms < blocks_wide) return FALSE;
374 /* Count the number of valid places */
375 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
377 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
379 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
381 /* Find a valid place */
394 if (!(d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE))
396 /* Choose a random one */
397 pick = randint1(candidates);
400 /* NO_CAVE dungeon (Castle) */
403 /* Always choose the center one */
404 pick = candidates/2 + 1;
407 /* Pick up the choosen location */
408 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
410 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
412 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
416 /* This one is picked? */
427 by2 = block_y + blocks_high;
428 bx2 = block_x + blocks_wide;
431 * It is *extremely* important that the following calculation
432 * be *exactly* correct to prevent memory errors
435 /* Acquire the location of the room */
436 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
437 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
439 /* Save the room location */
440 if (dun->cent_n < CENT_MAX)
442 dun->cent[dun->cent_n].y = (byte_hack)*y;
443 dun->cent[dun->cent_n].x = (byte_hack)*x;
447 /* Reserve some blocks. */
448 for (by = by1; by < by2; by++)
450 for (bx = bx1; bx < bx2; bx++)
452 dun->room_map[by][bx] = TRUE;
457 * Hack- See if room will cut off a cavern.
459 * If so, fix by tunneling outside the room in such a
460 * way as to connect the caves.
462 check_room_boundary(floor_ptr, *x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
470 * Structure to hold all "fill" data
473 typedef struct fill_data_type fill_data_type;
475 struct fill_data_type
488 /* features to fill with */
497 /* number of filled squares */
501 static fill_data_type fill_data;
504 /* Store routine for the fractal floor generator */
505 /* this routine probably should be an inline function or a macro. */
506 static void store_height(floor_type *floor_ptr, POSITION x, POSITION y, FEAT_IDX val)
508 /* if on boundary set val > cutoff so walls are not as square */
509 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
510 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
511 (val <= fill_data.c1)) val = fill_data.c1 + 1;
513 /* store the value in height-map format */
514 floor_ptr->grid_array[y][x].feat = val;
521 * Explanation of the plasma fractal algorithm:
523 * A grid of points is created with the properties of a 'height-map'
524 * This is done by making the corners of the grid have a random value.
525 * The grid is then subdivided into one with twice the resolution.
526 * The new points midway between two 'known' points can be calculated
527 * by taking the average value of the 'known' ones and randomly adding
528 * or subtracting an amount proportional to the distance between those
529 * points. The final 'middle' points of the grid are then calculated
530 * by averaging all four of the originally 'known' corner points. An
531 * random amount is added or subtracted from this to get a value of the
532 * height at that point. The scaling factor here is adjusted to the
533 * slightly larger distance diagonally as compared to orthogonally.
535 * This is then repeated recursively to fill an entire 'height-map'
536 * A rectangular map is done the same way, except there are different
537 * scaling factors along the x and y directions.
539 * A hack to change the amount of correlation between points is done using
540 * the grd variable. If the current step size is greater than grd then
541 * the point will be random, otherwise it will be calculated by the
542 * above algorithm. This makes a maximum distance at which two points on
543 * the height map can affect each other.
545 * How fractal caves are made:
547 * When the map is complete, a cut-off value is used to create a floor.
548 * Heights below this value are "floor", and heights above are "wall".
549 * This also can be used to create lakes, by adding more height levels
550 * representing shallow and deep water/ lava etc.
552 * The grd variable affects the width of passages.
553 * The roug variable affects the roughness of those passages
555 * The tricky part is making sure the created floor is connected. This
556 * is done by 'filling' from the inside and only keeping the 'filled'
557 * floor. Walls bounding the 'filled' floor are also kept. Everything
558 * else is converted to the normal _extra_.
563 * Note that this uses the floor array in a very hackish way
564 * the values are first set to zero, and then each array location
565 * is used as a "heightmap"
566 * The heightmap then needs to be converted back into the "feat" format.
568 * grd=level at which fractal turns on. smaller gives more mazelike caves
569 * roug=roughness level. 16=normal. higher values make things more convoluted
570 * small values are good for smooth walls.
571 * size=length of the side of the square grid system.
573 void generate_hmap(floor_type *floor_ptr, POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int grd, int roug, int cutoff)
575 POSITION xhsize, yhsize, xsize, ysize, maxsize;
578 * fixed point variables- these are stored as 256 x normal value
579 * this gives 8 binary places of fractional part + 8 places of normal part
582 POSITION xstep, xhstep, ystep, yhstep;
583 POSITION xstep2, xhstep2, ystep2, yhstep2;
584 POSITION i, j, ii, jj, diagsize, xxsize, yysize;
586 /* Cache for speed */
587 POSITION xm, xp, ym, yp;
589 /* redefine size so can change the value if out of range */
593 /* Paranoia about size of the system of caves */
594 if (xsize > 254) xsize = 254;
595 if (xsize < 4) xsize = 4;
596 if (ysize > 254) ysize = 254;
597 if (ysize < 4) ysize = 4;
599 /* get offsets to middle of array */
603 /* fix rounding problem */
607 /* get limits of region */
608 fill_data.xmin = x0 - xhsize;
609 fill_data.ymin = y0 - yhsize;
610 fill_data.xmax = x0 + xhsize;
611 fill_data.ymax = y0 + yhsize;
613 /* Store cutoff in global for quick access */
614 fill_data.c1 = cutoff;
617 * Scale factor for middle points:
618 * About sqrt(2) * 256 - correct for a square lattice
619 * approximately correct for everything else.
623 /* maximum of xsize and ysize */
624 maxsize = (xsize > ysize) ? xsize : ysize;
626 /* Clear the section */
627 for (i = 0; i <= xsize; i++)
629 for (j = 0; j <= ysize; j++)
631 /* -1 is a flag for "not done yet" */
632 floor_ptr->grid_array[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
633 /* Clear icky flag because may be redoing the floor_ptr->grid_array */
634 floor_ptr->grid_array[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
638 /* Boundaries are walls */
639 floor_ptr->grid_array[fill_data.ymin][fill_data.xmin].feat = (s16b)maxsize;
640 floor_ptr->grid_array[fill_data.ymax][fill_data.xmin].feat = (s16b)maxsize;
641 floor_ptr->grid_array[fill_data.ymin][fill_data.xmax].feat = (s16b)maxsize;
642 floor_ptr->grid_array[fill_data.ymax][fill_data.xmax].feat = (s16b)maxsize;
644 /* Set the middle square to be an open area. */
645 floor_ptr->grid_array[y0][x0].feat = 0;
647 /* Initialize the step sizes */
648 xstep = xhstep = xsize * 256;
649 ystep = yhstep = ysize * 256;
650 xxsize = xsize * 256;
651 yysize = ysize * 256;
654 * Fill in the rectangle with fractal height data -
655 * like the 'plasma fractal' in fractint.
657 while ((xhstep > 256) || (yhstep > 256))
659 /* Halve the step sizes */
665 /* cache well used values */
666 xstep2 = xstep / 256;
667 ystep2 = ystep / 256;
669 xhstep2 = xhstep / 256;
670 yhstep2 = yhstep / 256;
672 /* middle top to bottom. */
673 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
675 for (j = 0; j <= yysize; j += ystep)
677 /* cache often used values */
678 ii = i / 256 + fill_data.xmin;
679 jj = j / 256 + fill_data.ymin;
682 if (floor_ptr->grid_array[jj][ii].feat == -1)
686 /* If greater than 'grid' level then is random */
687 store_height(floor_ptr, ii, jj, randint1(maxsize));
691 /* Average of left and right points +random bit */
692 store_height(floor_ptr, ii, jj,
693 (floor_ptr->grid_array[jj][fill_data.xmin + (i - xhstep) / 256].feat
694 + floor_ptr->grid_array[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
695 + (randint1(xstep2) - xhstep2) * roug / 16);
702 /* middle left to right. */
703 for (j = yhstep; j <= yysize - yhstep; j += ystep)
705 for (i = 0; i <= xxsize; i += xstep)
707 /* cache often used values */
708 ii = i / 256 + fill_data.xmin;
709 jj = j / 256 + fill_data.ymin;
712 if (floor_ptr->grid_array[jj][ii].feat == -1)
716 /* If greater than 'grid' level then is random */
717 store_height(floor_ptr, ii, jj, randint1(maxsize));
721 /* Average of up and down points +random bit */
722 store_height(floor_ptr, ii, jj,
723 (floor_ptr->grid_array[fill_data.ymin + (j - yhstep) / 256][ii].feat
724 + floor_ptr->grid_array[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
725 + (randint1(ystep2) - yhstep2) * roug / 16);
732 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
734 for (j = yhstep; j <= yysize - yhstep; j += ystep)
736 /* cache often used values */
737 ii = i / 256 + fill_data.xmin;
738 jj = j / 256 + fill_data.ymin;
741 if (floor_ptr->grid_array[jj][ii].feat == -1)
745 /* If greater than 'grid' level then is random */
746 store_height(floor_ptr, ii, jj, randint1(maxsize));
750 /* Cache reused values. */
751 xm = fill_data.xmin + (i - xhstep) / 256;
752 xp = fill_data.xmin + (i + xhstep) / 256;
753 ym = fill_data.ymin + (j - yhstep) / 256;
754 yp = fill_data.ymin + (j + yhstep) / 256;
757 * Average over all four corners + scale by diagsize to
758 * reduce the effect of the square grid on the shape of the fractal
760 store_height(floor_ptr, ii, jj,
761 (floor_ptr->grid_array[ym][xm].feat + floor_ptr->grid_array[yp][xm].feat
762 + floor_ptr->grid_array[ym][xp].feat + floor_ptr->grid_array[yp][xp].feat) / 4
763 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
772 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)
775 * function used to convert from height-map back to the
776 * normal angband floor_ptr->grid_array format
778 if (floor_ptr->grid_array[y][x].info & CAVE_ICKY)
785 /* Show that have looked at this square */
786 floor_ptr->grid_array[y][x].info|= (CAVE_ICKY);
788 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
789 if (floor_ptr->grid_array[y][x].feat <= c1)
791 /* 25% of the time use the other tile : it looks better this way */
792 if (randint1(100) < 75)
794 floor_ptr->grid_array[y][x].feat = feat1;
795 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
796 floor_ptr->grid_array[y][x].info |= info1;
801 floor_ptr->grid_array[y][x].feat = feat2;
802 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
803 floor_ptr->grid_array[y][x].info |= info2;
807 else if (floor_ptr->grid_array[y][x].feat <= c2)
809 /* 25% of the time use the other tile : it looks better this way */
810 if (randint1(100) < 75)
812 floor_ptr->grid_array[y][x].feat = feat2;
813 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
814 floor_ptr->grid_array[y][x].info |= info2;
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;
825 else if (floor_ptr->grid_array[y][x].feat <= c3)
827 floor_ptr->grid_array[y][x].feat = feat3;
828 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
829 floor_ptr->grid_array[y][x].info |= info3;
832 /* if greater than cutoff then is a wall */
835 place_outer_bold(floor_ptr, y, x);
845 * Quick and nasty fill routine used to find the connected region
846 * of floor in the middle of the grids
848 static void cave_fill(floor_type *floor_ptr, POSITION y, POSITION x)
859 /* Enqueue that entry */
863 /* Now process the queue */
864 while (flow_head != flow_tail)
866 /* Extract the next entry */
867 ty = tmp_pos.y[flow_head];
868 tx = tmp_pos.x[flow_head];
870 /* Forget that entry */
871 if (++flow_head == TEMP_MAX) flow_head = 0;
873 /* Add the "children" */
874 for (d = 0; d < 8; d++)
876 int old_head = flow_tail;
882 /* Paranoia Don't leave the floor_ptr->grid_array */
883 if (!in_bounds(floor_ptr, j, i))
885 /* affect boundary */
886 floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
890 /* If within bounds */
891 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
892 && (j > fill_data.ymin) && (j < fill_data.ymax))
894 /* If not a wall or floor done before */
895 if (hack_isnt_wall(floor_ptr, j, i,
896 fill_data.c1, fill_data.c2, fill_data.c3,
897 fill_data.feat1, fill_data.feat2, fill_data.feat3,
898 fill_data.info1, fill_data.info2, fill_data.info3))
900 /* Enqueue that entry */
901 tmp_pos.y[flow_tail] = (byte_hack)j;
902 tmp_pos.x[flow_tail] = (byte_hack)i;
904 /* Advance the queue */
905 if (++flow_tail == TEMP_MAX) flow_tail = 0;
907 /* Hack -- Overflow by forgetting new entry */
908 if (flow_tail == flow_head)
910 flow_tail = old_head;
914 /* keep tally of size of floor_ptr->grid_array system */
915 (fill_data.amount)++;
921 /* affect boundary */
922 floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
929 bool generate_fracave(floor_type *floor_ptr, POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int cutoff, bool light, bool room)
931 POSITION x, y, xhsize, yhsize;
934 /* offsets to middle from corner */
940 * select region connected to center of floor_ptr->grid_array system
941 * this gets rid of alot of isolated one-sqaures that
942 * can make teleport traps instadeaths...
946 fill_data.c1 = cutoff;
950 /* features to fill with */
951 fill_data.feat1 = feat_ground_type[randint0(100)];
952 fill_data.feat2 = feat_ground_type[randint0(100)];
953 fill_data.feat3 = feat_ground_type[randint0(100)];
955 fill_data.info1 = CAVE_FLOOR;
956 fill_data.info2 = CAVE_FLOOR;
957 fill_data.info3 = CAVE_FLOOR;
959 /* number of filled squares */
960 fill_data.amount = 0;
962 cave_fill(floor_ptr, (byte)y0, (byte)x0);
964 /* if tally too small, try again */
965 if (fill_data.amount < 10)
967 /* too small - clear area and try again later */
968 for (x = 0; x <= xsize; ++x)
970 for (y = 0; y <= ysize; ++y)
972 place_extra_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
973 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
980 * Do boundarys-check to see if they are next to a filled region
981 * If not then they are set to normal granite
982 * If so then they are marked as room walls.
984 for (i = 0; i <= xsize; ++i)
987 if ((floor_ptr->grid_array[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
989 /* Next to a 'filled' region? - set to be room walls */
990 place_outer_bold(floor_ptr, y0 + 0 - yhsize, x0 + i - xhsize);
991 if (light) floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
992 floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
993 place_outer_bold(floor_ptr, y0 + 0 - yhsize, x0 + i - xhsize);
997 /* set to be normal granite */
998 place_extra_bold(floor_ptr, y0 + 0 - yhsize, x0 + i - xhsize);
1001 /* bottom boundary */
1002 if ((floor_ptr->grid_array[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1004 /* Next to a 'filled' region? - set to be room walls */
1005 place_outer_bold(floor_ptr, y0 + ysize - yhsize, x0 + i - xhsize);
1006 if (light) floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
1007 floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
1008 place_outer_bold(floor_ptr, y0 + ysize - yhsize, x0 + i - xhsize);
1012 /* set to be normal granite */
1013 place_extra_bold(floor_ptr, y0 + ysize - yhsize, x0 + i - xhsize);
1016 /* clear the icky flag-don't need it any more */
1017 floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1018 floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1021 /* Do the left and right boundaries minus the corners (done above) */
1022 for (i = 1; i < ysize; ++i)
1025 if ((floor_ptr->grid_array[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
1028 place_outer_bold(floor_ptr, y0 + i - yhsize, x0 + 0 - xhsize);
1029 if (light) floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
1030 floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
1031 place_outer_bold(floor_ptr, y0 + i - yhsize, x0 + 0 - xhsize);
1036 place_extra_bold(floor_ptr, y0 + i - yhsize, x0 + 0 - xhsize);
1038 /* right boundary */
1039 if ((floor_ptr->grid_array[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
1042 place_outer_bold(floor_ptr, y0 + i - yhsize, x0 + xsize - xhsize);
1043 if (light) floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
1044 floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
1045 place_outer_bold(floor_ptr, y0 + i - yhsize, x0 + xsize - xhsize);
1050 place_extra_bold(floor_ptr, y0 + i - yhsize, x0 + xsize - xhsize);
1053 /* clear icky flag -done with it */
1054 floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1055 floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1059 /* Do the rest: convert back to the normal format */
1060 for (x = 1; x < xsize; ++x)
1062 for (y = 1; y < ysize; ++y)
1064 if (is_floor_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize) &&
1065 (floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1067 /* Clear the icky flag in the filled region */
1068 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
1070 /* Set appropriate flags */
1071 if (light) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1072 if (room) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1074 else if (is_outer_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize) &&
1075 (floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1078 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1079 if (light) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1082 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1087 place_extra_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
1088 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
1093 /* Clear the unconnected regions */
1094 place_extra_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
1095 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1101 * There is a slight problem when tunnels pierce the caves:
1102 * Extra doors appear inside the system. (Its not very noticeable though.)
1103 * This can be removed by "filling" from the outside in. This allows a separation
1104 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
1105 * The extra effort for what seems to be only a minor thing (even non-existant if you
1106 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
1114 #ifdef ALLOW_CAVERNS_AND_LAKES
1116 * Builds a cave system in the center of the dungeon.
1118 void build_cavern(floor_type *floor_ptr)
1120 int grd, roug, cutoff;
1121 POSITION xsize, ysize, x0, y0;
1124 light = done = FALSE;
1125 if ((floor_ptr->dun_level <= randint1(50)) && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) light = TRUE;
1127 /* Make a cave the size of the dungeon */
1128 xsize = floor_ptr->width - 1;
1129 ysize = floor_ptr->height - 1;
1133 /* Paranoia: make size even */
1139 /* testing values for these parameters: feel free to adjust */
1140 grd = randint1(4) + 4;
1142 /* want average of about 16 */
1143 roug = randint1(8) * randint1(4);
1149 generate_hmap(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
1151 /* Convert to normal format+ clean up */
1152 done = generate_fracave(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
1156 bool generate_lake(floor_type *floor_ptr, POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int c1, int c2, int c3, int type)
1158 POSITION x, y, xhsize, yhsize;
1160 FEAT_IDX feat1, feat2, feat3;
1162 /* offsets to middle from corner */
1166 /* Get features based on type */
1169 case LAKE_T_LAVA: /* Lava */
1170 feat1 = feat_deep_lava;
1171 feat2 = feat_shallow_lava;
1172 feat3 = feat_ground_type[randint0(100)];
1174 case LAKE_T_WATER: /* Water */
1175 feat1 = feat_deep_water;
1176 feat2 = feat_shallow_water;
1177 feat3 = feat_ground_type[randint0(100)];
1179 case LAKE_T_CAVE: /* Collapsed floor_ptr->grid_array */
1180 feat1 = feat_ground_type[randint0(100)];
1181 feat2 = feat_ground_type[randint0(100)];
1182 feat3 = feat_rubble;
1184 case LAKE_T_EARTH_VAULT: /* Earth vault */
1185 feat1 = feat_rubble;
1186 feat2 = feat_ground_type[randint0(100)];
1187 feat3 = feat_rubble;
1189 case LAKE_T_AIR_VAULT: /* Air vault */
1194 case LAKE_T_WATER_VAULT: /* Water vault */
1195 feat1 = feat_shallow_water;
1196 feat2 = feat_deep_water;
1197 feat3 = feat_shallow_water;
1199 case LAKE_T_FIRE_VAULT: /* Fire Vault */
1200 feat1 = feat_shallow_lava;
1201 feat2 = feat_deep_lava;
1202 feat3 = feat_shallow_lava;
1204 default: return FALSE;
1208 * select region connected to center of floor_ptr->grid_array system
1209 * this gets rid of alot of isolated one-sqaures that
1210 * can make teleport traps instadeaths...
1218 /* features to fill with */
1219 fill_data.feat1 = feat1;
1220 fill_data.feat2 = feat2;
1221 fill_data.feat3 = feat3;
1223 fill_data.info1 = 0;
1224 fill_data.info2 = 0;
1225 fill_data.info3 = 0;
1227 /* number of filled squares */
1228 fill_data.amount = 0;
1230 /* select region connected to center of floor_ptr->grid_array system
1231 * this gets rid of alot of isolated one-sqaures that
1232 * can make teleport traps instadeaths... */
1233 cave_fill(floor_ptr, (byte)y0, (byte)x0);
1235 /* if tally too small, try again */
1236 if (fill_data.amount < 10)
1238 /* too small -clear area and try again later */
1239 for (x = 0; x <= xsize; ++x)
1241 for (y = 0; y <= ysize; ++y)
1243 place_floor_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
1244 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1250 /* Do boundarys- set to normal granite */
1251 for (i = 0; i <= xsize; ++i)
1253 place_extra_bold(floor_ptr, y0 + 0 - yhsize, x0 + i - xhsize);
1254 place_extra_bold(floor_ptr, y0 + ysize - yhsize, x0 + i - xhsize);
1256 /* clear the icky flag-don't need it any more */
1257 floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1258 floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1261 /* Do the left and right boundaries minus the corners (done above) */
1263 for (i = 1; i < ysize; ++i)
1265 place_extra_bold(floor_ptr, y0 + i - yhsize, x0 + 0 - xhsize);
1266 place_extra_bold(floor_ptr, y0 + i - yhsize, x0 + xsize - xhsize);
1268 /* clear icky flag -done with it */
1269 floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1270 floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1274 /* Do the rest: convert back to the normal format */
1275 for (x = 1; x < xsize; ++x)
1277 for (y = 1; y < ysize; ++y)
1279 /* Fill unconnected regions with granite */
1280 if ((!(floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
1281 is_outer_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize))
1282 place_extra_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
1284 /* turn off icky flag (no longer needed.) */
1285 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1288 if (cave_have_flag_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
1290 if (!(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
1300 * makes a lake/collapsed floor in the center of the dungeon
1302 void build_lake(floor_type *floor_ptr, int type)
1304 int grd, roug, xsize, ysize, x0, y0;
1308 /* paranoia - exit if lake type out of range. */
1309 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
1311 msg_format("Invalid lake type (%d)", type);
1315 /* Make the size of the dungeon */
1316 xsize = floor_ptr->width - 1;
1317 ysize = floor_ptr->height - 1;
1321 /* Paranoia: make size even */
1327 /* testing values for these parameters: feel free to adjust */
1328 grd = randint1(3) + 4;
1330 /* want average of about 16 */
1331 roug = randint1(8) * randint1(4);
1333 /* Make up size of various componants */
1337 /* Deep water/lava */
1338 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
1340 /* Shallow boundary */
1344 generate_hmap(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
1346 /* Convert to normal format+ clean up */
1347 done = generate_lake(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
1350 #endif /* ALLOW_CAVERNS_AND_LAKES */
1355 * Routine that fills the empty areas of a room with treasure and monsters.
1357 void fill_treasure(player_type *player_ptr, POSITION x1, POSITION x2, POSITION y1, POSITION y2, int difficulty)
1359 POSITION x, y, cx, cy, size;
1362 /* center of room:*/
1366 /* Rough measure of size of vault= sum of lengths of sides */
1367 size = abs(x2 - x1) + abs(y2 - y1);
1369 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1370 for (x = x1; x <= x2; x++)
1372 for (y = y1; y <= y2; y++)
1374 /* Thing added based on distance to center of vault
1375 * Difficulty is 1-easy to 10-hard */
1376 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
1378 /* hack- empty square part of the time */
1379 if ((randint1(100) - difficulty * 3) > 50) value = 20;
1381 /* if floor, shallow water and lava */
1382 if (is_floor_bold(floor_ptr, y, x) ||
1383 (cave_have_flag_bold(floor_ptr, y, x, FF_PLACE) && cave_have_flag_bold(floor_ptr, y, x, FF_DROP)))
1385 /* The smaller 'value' is, the better the stuff */
1388 /* Meanest monster + treasure */
1389 floor_ptr->monster_level = floor_ptr->base_level + 40;
1390 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1391 floor_ptr->monster_level = floor_ptr->base_level;
1392 floor_ptr->object_level = floor_ptr->base_level + 20;
1393 place_object(player_ptr, y, x, AM_GOOD);
1394 floor_ptr->object_level = floor_ptr->base_level;
1398 /* Mean monster +treasure */
1399 floor_ptr->monster_level = floor_ptr->base_level + 20;
1400 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1401 floor_ptr->monster_level = floor_ptr->base_level;
1402 floor_ptr->object_level = floor_ptr->base_level + 10;
1403 place_object(player_ptr, y, x, AM_GOOD);
1404 floor_ptr->object_level = floor_ptr->base_level;
1406 else if (value < 10)
1408 floor_ptr->monster_level = floor_ptr->base_level + 9;
1409 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1410 floor_ptr->monster_level = floor_ptr->base_level;
1412 else if (value < 17)
1414 /* Intentional Blank space */
1417 * (Want some of the vault to be empty
1418 * so have room for group monsters.
1419 * This is used in the hack above to lower
1420 * the density of stuff in the vault.)
1423 else if (value < 23)
1425 /* Object or trap */
1426 if (randint0(100) < 25)
1428 place_object(player_ptr, y, x, 0L);
1432 place_trap(player_ptr, y, x);
1435 else if (value < 30)
1437 /* Monster and trap */
1438 floor_ptr->monster_level = floor_ptr->base_level + 5;
1439 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1440 floor_ptr->monster_level = floor_ptr->base_level;
1441 place_trap(player_ptr, y, x);
1443 else if (value < 40)
1445 /* Monster or object */
1446 if (randint0(100) < 50)
1448 floor_ptr->monster_level = floor_ptr->base_level + 3;
1449 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1450 floor_ptr->monster_level = floor_ptr->base_level;
1452 if (randint0(100) < 50)
1454 floor_ptr->object_level = floor_ptr->base_level + 7;
1455 place_object(player_ptr, y, x, 0L);
1456 floor_ptr->object_level = floor_ptr->base_level;
1459 else if (value < 50)
1462 place_trap(player_ptr, y, x);
1468 /* 20% monster, 40% trap, 20% object, 20% blank space */
1469 if (randint0(100) < 20)
1471 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1473 else if (randint0(100) < 50)
1475 place_trap(player_ptr, y, x);
1477 else if (randint0(100) < 50)
1479 place_object(player_ptr, y, x, 0L);
1490 * Overlay a rectangular room given its bounds
1491 * This routine is used by build_room_vault
1492 * The area inside the walls is not touched:
1493 * only granite is removed- normal walls stay
1495 void build_room(floor_type *floor_ptr, POSITION x1, POSITION x2, POSITION y1, POSITION y2)
1497 POSITION x, y, xsize, ysize;
1500 /* Check if rectangle has no width */
1501 if ((x1 == x2) || (y1 == y2)) return;
1505 /* Swap boundaries if in wrong order */
1513 /* Swap boundaries if in wrong order */
1519 /* get total widths */
1524 /* Top and bottom boundaries */
1525 for (i = 0; i <= xsize; i++)
1527 place_outer_noperm_bold(floor_ptr, y1, x1 + i);
1528 floor_ptr->grid_array[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1529 place_outer_noperm_bold(floor_ptr, y2, x1 + i);
1530 floor_ptr->grid_array[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1533 /* Left and right boundaries */
1534 for (i = 1; i < ysize; i++)
1536 place_outer_noperm_bold(floor_ptr, y1 + i, x1);
1537 floor_ptr->grid_array[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
1538 place_outer_noperm_bold(floor_ptr, y1 + i, x2);
1539 floor_ptr->grid_array[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
1543 for (x = 1; x < xsize; x++)
1545 for (y = 1; y < ysize; y++)
1547 if (is_extra_bold(floor_ptr, y1+y, x1+x))
1549 /* clear the untouched region */
1550 place_floor_bold(floor_ptr, y1 + y, x1 + x);
1551 floor_ptr->grid_array[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1555 /* make it a room- but don't touch */
1556 floor_ptr->grid_array[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1565 * maze vault -- rectangular labyrinthine rooms
1567 * maze vault uses two routines:
1568 * r_visit - a recursive routine that builds the labyrinth
1569 * build_maze_vault - a driver routine that calls r_visit and adds
1570 * monsters, traps and treasure
1572 * The labyrinth is built by creating a spanning tree of a graph.
1573 * The graph vertices are at
1574 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
1575 * and the edges are the vertical and horizontal nearest neighbors.
1577 * The spanning tree is created by performing a suitably randomized
1578 * depth-first traversal of the graph. The only adjustable parameter
1579 * is the randint0(3) below; it governs the relative density of
1580 * twists and turns in the labyrinth: smaller number, more twists.
1582 void r_visit(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, int node, DIRECTION dir, int *visited)
1584 int i, j, m, n, temp, x, y, adj[4];
1586 /* dimensions of vertex array */
1587 m = (x2 - x1) / 2 + 1;
1588 n = (y2 - y1) / 2 + 1;
1590 /* mark node visited and set it to a floor */
1592 x = 2 * (node % m) + x1;
1593 y = 2 * (node / m) + y1;
1594 place_floor_bold(floor_ptr, y, x);
1596 /* setup order of adjacent node visits */
1599 /* pick a random ordering */
1600 for (i = 0; i < 4; i++)
1602 for (i = 0; i < 4; i++)
1613 /* pick a random ordering with dir first */
1615 for (i = 1; i < 4; i++)
1617 for (i = 1; i < 4; i++)
1619 j = 1 + randint0(3);
1626 for (i = 0; i < 4; i++)
1631 /* (0,+) - check for bottom boundary */
1632 if ((node / m < n - 1) && (visited[node + m] == 0))
1634 place_floor_bold(floor_ptr, y + 1, x);
1635 r_visit(floor_ptr, y1, x1, y2, x2, node + m, dir, visited);
1639 /* (0,-) - check for top boundary */
1640 if ((node / m > 0) && (visited[node - m] == 0))
1642 place_floor_bold(floor_ptr, y - 1, x);
1643 r_visit(floor_ptr, y1, x1, y2, x2, node - m, dir, visited);
1647 /* (+,0) - check for right boundary */
1648 if ((node % m < m - 1) && (visited[node + 1] == 0))
1650 place_floor_bold(floor_ptr, y, x + 1);
1651 r_visit(floor_ptr, y1, x1, y2, x2, node + 1, dir, visited);
1655 /* (-,0) - check for left boundary */
1656 if ((node % m > 0) && (visited[node - 1] == 0))
1658 place_floor_bold(floor_ptr, y, x - 1);
1659 r_visit(floor_ptr, y1, x1, y2, x2, node - 1, dir, visited);
1666 void build_maze_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize, bool is_vault)
1668 POSITION y, x, dy, dx;
1669 POSITION y1, x1, y2, x2;
1670 int m, n, num_vertices, *visited;
1674 msg_print_wizard(CHEAT_DUNGEON, _("迷路ランダムVaultを生成しました。", "Maze Vault."));
1676 /* Choose lite or dark */
1677 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1678 light = ((floor_ptr->dun_level <= randint1(25)) && is_vault && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS));
1680 /* Pick a random room size - randomized by calling routine */
1689 /* generate the room */
1690 for (y = y1 - 1; y <= y2 + 1; y++)
1692 for (x = x1 - 1; x <= x2 + 1; x++)
1694 g_ptr = &floor_ptr->grid_array[y][x];
1695 g_ptr->info |= CAVE_ROOM;
1696 if (is_vault) g_ptr->info |= CAVE_ICKY;
1697 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
1699 place_outer_grid(g_ptr);
1703 place_extra_grid(g_ptr);
1707 place_inner_grid(g_ptr);
1709 if (light) g_ptr->info |= (CAVE_GLOW);
1713 /* dimensions of vertex array */
1716 num_vertices = m * n;
1718 /* initialize array of visited vertices */
1719 C_MAKE(visited, num_vertices, int);
1721 /* traverse the graph to create a spaning tree, pick a random root */
1722 r_visit(floor_ptr, y1, x1, y2, x2, randint0(num_vertices), 0, visited);
1724 /* Fill with monsters and treasure, low difficulty */
1725 if (is_vault) fill_treasure(player_ptr, x1, x2, y1, y2, randint1(5));
1727 C_KILL(visited, num_vertices, int);
1731 /* Build a town/ castle by using a recursive algorithm.
1732 * Basically divide each region in a probalistic way to create
1733 * smaller regions. When the regions get too small stop.
1735 * The power variable is a measure of how well defended a region is.
1736 * This alters the possible choices.
1738 void build_recursive_room(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int power)
1740 POSITION xsize, ysize;
1744 /* Temp variables */
1750 if ((power < 3) && (xsize > 12) && (ysize > 12))
1752 /* Need outside wall +keep */
1759 /* Make rooms + subdivide */
1760 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
1766 choice = randint1(2) + 1;
1771 /* Mostly subdivide */
1772 choice = randint1(3) + 1;
1776 /* Based on the choice made above, do something */
1784 /* top and bottom */
1785 for (x = x1; x <= x2; x++)
1787 place_outer_bold(floor_ptr, y1, x);
1788 place_outer_bold(floor_ptr, y2, x);
1791 /* left and right */
1792 for (y = y1 + 1; y < y2; y++)
1794 place_outer_bold(floor_ptr, y, x1);
1795 place_outer_bold(floor_ptr, y, x2);
1798 /* Make a couple of entrances */
1801 /* left and right */
1802 y = randint1(ysize) + y1;
1803 place_floor_bold(floor_ptr, y, x1);
1804 place_floor_bold(floor_ptr, y, x2);
1808 /* top and bottom */
1809 x = randint1(xsize) + x1;
1810 place_floor_bold(floor_ptr, y1, x);
1811 place_floor_bold(floor_ptr, y2, x);
1814 /* Select size of keep */
1815 t1 = randint1(ysize / 3) + y1;
1816 t2 = y2 - randint1(ysize / 3);
1817 t3 = randint1(xsize / 3) + x1;
1818 t4 = x2 - randint1(xsize / 3);
1820 /* Do outside areas */
1822 /* Above and below keep */
1823 build_recursive_room(floor_ptr, x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
1824 build_recursive_room(floor_ptr, x1 + 1, t2, x2 - 1, y2, power + 1);
1826 /* Left and right of keep */
1827 build_recursive_room(floor_ptr, x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
1828 build_recursive_room(floor_ptr, t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
1830 /* Make the keep itself: */
1843 /* Try to build a room */
1844 if ((xsize < 3) || (ysize < 3))
1846 for (y = y1; y < y2; y++)
1848 for (x = x1; x < x2; x++)
1850 place_inner_bold(floor_ptr, y, x);
1858 /* Make outside walls */
1859 /* top and bottom */
1860 for (x = x1 + 1; x <= x2 - 1; x++)
1862 place_inner_bold(floor_ptr, y1 + 1, x);
1863 place_inner_bold(floor_ptr, y2 - 1, x);
1866 /* left and right */
1867 for (y = y1 + 1; y <= y2 - 1; y++)
1869 place_inner_bold(floor_ptr, y, x1 + 1);
1870 place_inner_bold(floor_ptr, y, x2 - 1);
1874 y = randint1(ysize - 3) + y1 + 1;
1879 place_floor_bold(floor_ptr, y, x1 + 1);
1884 place_floor_bold(floor_ptr, y, x2 - 1);
1887 /* Build the room */
1888 build_recursive_room(floor_ptr, x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
1893 /* Try and divide vertically */
1897 for (y = y1; y < y2; y++)
1899 for (x = x1; x < x2; x++)
1901 place_inner_bold(floor_ptr, y, x);
1907 t1 = randint1(xsize - 2) + x1 + 1;
1908 build_recursive_room(floor_ptr, x1, y1, t1, y2, power - 2);
1909 build_recursive_room(floor_ptr, t1 + 1, y1, x2, y2, power - 2);
1914 /* Try and divide horizontally */
1918 for (y = y1; y < y2; y++)
1920 for (x = x1; x < x2; x++)
1922 place_inner_bold(floor_ptr, y, x);
1928 t1 = randint1(ysize - 2) + y1 + 1;
1929 build_recursive_room(floor_ptr, x1, y1, x2, t1, power - 2);
1930 build_recursive_room(floor_ptr, x1, t1 + 1, x2, y2, power - 2);
1938 * Add outer wall to a floored region
1939 * Note: no range checking is done so must be inside dungeon
1940 * This routine also stomps on doors
1942 void add_outer_wall(floor_type *floor_ptr, POSITION x, POSITION y, int light, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
1945 feature_type *f_ptr;
1948 if (!in_bounds(floor_ptr, y, x)) return;
1950 g_ptr = &floor_ptr->grid_array[y][x];
1952 /* hack- check to see if square has been visited before
1953 * if so, then exit (use room flag to do this) */
1954 if (g_ptr->info & CAVE_ROOM) return;
1957 g_ptr->info |= CAVE_ROOM;
1959 f_ptr = &f_info[g_ptr->feat];
1961 if (is_floor_bold(floor_ptr, y, x))
1963 for (i = -1; i <= 1; i++)
1965 for (j = -1; j <= 1; j++)
1967 if ((x + i >= x1) && (x + i <= x2) && (y + j >= y1) && (y + j <= y2))
1969 add_outer_wall(floor_ptr, x + i, y + j, light, x1, y1, x2, y2);
1970 if (light) g_ptr->info |= CAVE_GLOW;
1975 else if (is_extra_bold(floor_ptr, y, x))
1977 /* Set bounding walls */
1978 place_outer_bold(floor_ptr, y, x);
1979 if (light) g_ptr->info |= CAVE_GLOW;
1981 else if (permanent_wall(f_ptr))
1983 /* Set bounding walls */
1984 if (light) g_ptr->info |= CAVE_GLOW;
1990 * Hacked distance formula - gives the 'wrong' answer.
1991 * Used to build crypts
1993 POSITION dist2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, POSITION h1, POSITION h2, POSITION h3, POSITION h4)
1999 /* Basically this works by taking the normal pythagorean formula
2000 * and using an expansion to express this in a way without the
2001 * square root. This approximate formula is then perturbed to give
2002 * the distorted results. (I found this by making a mistake when I was
2003 * trying to fix the circular rooms.)
2006 /* h1-h4 are constants that describe the metric */
2007 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
2008 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
2009 return (((dx + dy) * 128) / 181 +
2010 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
2011 /* 128/181 is approx. 1/sqrt(2) */
2017 /* Create a new floor room with optional light */
2018 void generate_room_floor(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, int light)
2024 for (y = y1; y <= y2; y++)
2026 for (x = x1; x <= x2; x++)
2029 g_ptr = &floor_ptr->grid_array[y][x];
2030 place_floor_grid(g_ptr);
2031 g_ptr->info |= (CAVE_ROOM);
2032 if (light) g_ptr->info |= (CAVE_GLOW);
2037 void generate_fill_perm_bold(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
2041 for (y = y1; y <= y2; y++)
2043 for (x = x1; x <= x2; x++)
2046 place_inner_perm_bold(floor_ptr ,y, x);
2053 * @brief 与えられた部屋型IDに応じて部屋の生成処理分岐を行い結果を返す / Attempt to build a room of the given type at the given block
2054 * @param player_ptr プレーヤーへの参照ポインタ
2056 * @note that we restrict the number of "crowded" rooms to reduce the chance of overflowing the monster list during level creation.
2057 * @return 部屋の生成に成功した場合 TRUE を返す。
2059 static bool room_build(player_type *player_ptr, EFFECT_ID typ)
2061 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2064 /* Build an appropriate room */
2065 case ROOM_T_NORMAL: return build_type1(floor_ptr);
2066 case ROOM_T_OVERLAP: return build_type2(floor_ptr);
2067 case ROOM_T_CROSS: return build_type3(player_ptr);
2068 case ROOM_T_INNER_FEAT: return build_type4(player_ptr);
2069 case ROOM_T_NEST: return build_type5(player_ptr);
2070 case ROOM_T_PIT: return build_type6(player_ptr);
2071 case ROOM_T_LESSER_VAULT: return build_type7(player_ptr);
2072 case ROOM_T_GREATER_VAULT: return build_type8(player_ptr);
2073 case ROOM_T_FRACAVE: return build_type9(floor_ptr);
2074 case ROOM_T_RANDOM_VAULT: return build_type10(player_ptr);
2075 case ROOM_T_OVAL: return build_type11(floor_ptr);
2076 case ROOM_T_CRYPT: return build_type12(player_ptr);
2077 case ROOM_T_TRAP_PIT: return build_type13(floor_ptr);
2078 case ROOM_T_TRAP: return build_type14(floor_ptr);
2079 case ROOM_T_GLASS: return build_type15(player_ptr);
2080 case ROOM_T_ARCADE: return build_type16(player_ptr);
2081 case ROOM_T_FIXED: return build_type17(player_ptr);
2087 * @brief 指定した部屋の生成確率を別の部屋に加算し、指定した部屋の生成率を0にする
2088 * @param dst 確率を移す先の部屋種ID
2089 * @param src 確率を与える元の部屋種ID
2091 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
2094 * @brief 部屋生成処理のメインルーチン(Sangbandを経由してOangbandからの実装を引用) / Generate rooms in dungeon. Build bigger rooms at first. [from SAngband (originally from OAngband)]
2095 * @param player_ptr プレーヤーへの参照ポインタ
2096 * @return 部屋生成に成功した場合 TRUE を返す。
2098 bool generate_rooms(player_type *player_ptr)
2100 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2105 int prob_list[ROOM_T_MAX];
2106 int rooms_built = 0;
2107 int area_size = 100 * (floor_ptr->height*floor_ptr->width) / (MAX_HGT*MAX_WID);
2108 int level_index = MIN(10, div_round(floor_ptr->dun_level, 10));
2110 /* Number of each type of room on this level */
2111 s16b room_num[ROOM_T_MAX];
2113 /* Limit number of rooms */
2114 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
2116 /* Assume normal floor_ptr->grid_array */
2117 room_info_type *room_info_ptr = room_info_normal;
2120 * Initialize probability list.
2122 for (i = 0; i < ROOM_T_MAX; i++)
2124 /* No rooms allowed above their minimum depth. */
2125 if (floor_ptr->dun_level < room_info_ptr[i].min_level)
2131 prob_list[i] = room_info_ptr[i].prob[level_index];
2136 * XXX -- Various dungeon types and options.
2139 /*! @details ダンジョンにBEGINNER、CHAMELEON、SMALLESTいずれのフラグもなく、
2140 * かつ「常に通常でない部屋を生成する」フラグがONならば、
2141 * GRATER_VAULTのみを生成対象とする。 / Ironman sees only Greater Vaults */
2142 if (ironman_rooms && !((d_info[floor_ptr->dungeon_idx].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
2144 for (i = 0; i < ROOM_T_MAX; i++)
2146 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
2147 else prob_list[i] = 0;
2151 /*! @details ダンジョンにNO_VAULTフラグがあるならば、LESSER_VAULT / GREATER_VAULT/ RANDOM_VAULTを除外 / Forbidden vaults */
2152 else if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_VAULT)
2154 prob_list[ROOM_T_LESSER_VAULT] = 0;
2155 prob_list[ROOM_T_GREATER_VAULT] = 0;
2156 prob_list[ROOM_T_RANDOM_VAULT] = 0;
2159 /*! @details ダンジョンにBEGINNERフラグがあるならば、FIXED_ROOMを除外 / Forbidden vaults */
2160 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_BEGINNER)
2162 prob_list[ROOM_T_FIXED] = 0;
2165 /*! @details ダンジョンにNO_CAVEフラグがある場合、FRACAVEの生成枠がNORMALに与えられる。CRIPT、OVALの生成枠がINNER_Fに与えられる。/ NO_CAVE dungeon (Castle)*/
2166 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE)
2168 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
2169 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
2170 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
2173 /*! @details ダンジョンにCAVEフラグがある場合、NORMALの生成枠がFRACAVEに与えられる。/ CAVE dungeon (Orc floor_ptr->grid_array etc.) */
2174 else if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_CAVE)
2176 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
2179 /*! @details ダンジョンの基本地形が最初から渓谷かアリーナ型の場合 FRACAVE は生成から除外。 / No caves when a (random) cavern exists: they look bad */
2180 else if (dun->cavern || dun->empty_level)
2182 prob_list[ROOM_T_FRACAVE] = 0;
2185 /*! @details ダンジョンに最初からGLASS_ROOMフラグがある場合、GLASS を生成から除外。/ Forbidden glass rooms */
2186 if (!(d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_ROOM))
2188 prob_list[ROOM_T_GLASS] = 0;
2191 /*! @details ARCADEは同フラグがダンジョンにないと生成されない。 / Forbidden glass rooms */
2192 if (!(d_info[floor_ptr->dungeon_idx].flags1 & DF1_ARCADE))
2194 prob_list[ROOM_T_ARCADE] = 0;
2198 * Initialize number of rooms,
2199 * And calcurate total probability.
2201 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
2204 total_prob += prob_list[i];
2208 * Prepare the number of rooms, of all types, we should build
2211 for (i = dun_rooms; i > 0; i--)
2214 int rand = randint0(total_prob);
2216 /* Get room_type randomly */
2217 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
2219 if (rand < prob_list[room_type]) break;
2220 else rand -= prob_list[room_type];
2222 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
2224 /* Increase the number of rooms of that type we should build. */
2225 room_num[room_type]++;
2231 case ROOM_T_LESSER_VAULT:
2232 case ROOM_T_TRAP_PIT:
2240 case ROOM_T_GREATER_VAULT:
2241 case ROOM_T_RANDOM_VAULT:
2250 * Build each type of room one by one until we cannot build any more.
2251 * [from SAngband (originally from OAngband)]
2255 /* Assume no remaining rooms */
2258 for (i = 0; i < ROOM_T_MAX; i++)
2260 /* What type of room are we building now? */
2261 int room_type = room_build_order[i];
2263 /* Go next if none available */
2264 if (!room_num[room_type]) continue;
2266 /* Use up one unit */
2267 room_num[room_type]--;
2269 /* Build the room. */
2270 if (room_build(player_ptr, room_type))
2272 /* Increase the room built count. */
2275 /* Mark as there was some remaining rooms */
2282 case ROOM_T_TRAP_PIT:
2284 /* Avoid too many monsters */
2287 room_num[ROOM_T_PIT] = 0;
2288 room_num[ROOM_T_NEST] = 0;
2289 room_num[ROOM_T_TRAP_PIT] = 0;
2295 /* Avoid double-town */
2296 room_num[ROOM_T_ARCADE] = 0;
2302 /* End loop if no room remain */
2306 /*! @details 部屋生成数が2未満の場合生成失敗を返す */
2307 if (rooms_built < 2)
2309 msg_format_wizard(CHEAT_DUNGEON, _("部屋数が2未満でした。生成を再試行します。", "Number of rooms was under 2. Retry."), rooms_built);
2313 msg_format_wizard(CHEAT_DUNGEON, _("このダンジョンの部屋数は %d です。", "Number of Rooms: %d"), rooms_built);