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
79 static room_info_type room_info_normal[ROOM_T_MAX] =
82 /* 0 10 20 30 40 50 60 70 80 90 100 min limit */
83 {{999,900,800,700,600,500,400,300,200,100, 0}, 0}, /*NORMAL */
84 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 1}, /*OVERLAP */
85 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*CROSS */
86 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*INNER_F */
87 {{ 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 13}, 10}, /*NEST */
88 {{ 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 16}, 10}, /*PIT */
89 {{ 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 10}, 10}, /*LESSER_V */
90 {{ 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4}, 20}, /*GREATER_V*/
91 {{ 0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE */
92 {{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}, 10}, /*RANDOM_V */
93 {{ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40}, 3}, /*OVAL */
94 {{ 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT */
95 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP_PIT */
96 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP */
97 {{ 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2}, 40}, /*GLASS */
98 {{ 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3}, 1}, /*ARCADE */
99 {{ 1, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80}, 1}, /*FIX */
102 /*! 部屋の生成処理順 / Build rooms in descending order of difficulty. */
103 static byte room_build_order[ROOM_T_MAX] = {
104 ROOM_T_GREATER_VAULT,
124 * @brief 1マスだけの部屋を作成し、上下左右いずれか一つに隠しドアを配置する。
125 * @param player_ptr プレーヤーへの参照ポインタ
126 * @param y0 配置したい中心のY座標
127 * @param x0 配置したい中心のX座標
129 * This funtion makes a very small room centred at (x0, y0)
130 * This is used in crypts, and random elemental vaults.
132 * Note - this should be used only on allocated regions
133 * within another room.
135 void build_small_room(player_type *player_ptr, POSITION x0, POSITION y0)
139 floor_type *floor_ptr = player_ptr->current_floor_ptr;
140 for (y = y0 - 1; y <= y0 + 1; y++)
142 place_bold(player_ptr, y, x0 - 1, gb_inner);
143 place_bold(player_ptr, y, x0 + 1, gb_inner);
146 for (x = x0 - 1; x <= x0 + 1; x++)
148 place_bold(player_ptr, y0 - 1, x, gb_inner);
149 place_bold(player_ptr, y0 + 1, x, gb_inner);
152 /* Place a secret door on one side */
155 case 0: place_secret_door(player_ptr, y0, x0 - 1, DOOR_DEFAULT); break;
156 case 1: place_secret_door(player_ptr, y0, x0 + 1, DOOR_DEFAULT); break;
157 case 2: place_secret_door(player_ptr, y0 - 1, x0, DOOR_DEFAULT); break;
158 case 3: place_secret_door(player_ptr, y0 + 1, x0, DOOR_DEFAULT); break;
161 /* Clear mimic type */
162 floor_ptr->grid_array[y0][x0].mimic = 0;
164 /* Add inner open space */
165 place_bold(player_ptr, y0, x0, gb_floor);
170 * 指定範囲に通路が通っていることを確認した上で床で埋める
171 * This function tunnels around a room if it will cut off part of a grid system.
172 * @param player_ptr プレーヤーへの参照ポインタ
179 static void check_room_boundary(player_type *player_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
183 bool old_is_floor, new_is_floor;
186 floor_type *floor_ptr = player_ptr->current_floor_ptr;
187 old_is_floor = get_is_floor(floor_ptr, x1 - 1, y1);
190 * Count the number of floor-wall boundaries around the room
191 * Note: diagonal squares are ignored since the player can move diagonally
192 * to bypass these if needed.
195 /* Above the top boundary */
196 for (x = x1; x <= x2; x++)
198 new_is_floor = get_is_floor(floor_ptr, x, y1 - 1);
200 /* Increment counter if they are different */
201 if (new_is_floor != old_is_floor) count++;
203 old_is_floor = new_is_floor;
207 for (y = y1; y <= y2; y++)
209 new_is_floor = get_is_floor(floor_ptr, x2 + 1, y);
211 /* increment counter if they are different */
212 if (new_is_floor != old_is_floor) count++;
214 old_is_floor = new_is_floor;
217 /* Bottom boundary */
218 for (x = x2; x >= x1; x--)
220 new_is_floor = get_is_floor(floor_ptr, x, y2 + 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 = y2; y >= y1; y--)
231 new_is_floor = get_is_floor(floor_ptr, x1 - 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 /* If all the same, or only one connection exit. */
240 if (count <= 2) return;
243 /* Tunnel around the room so to prevent problems with caves */
244 for (y = y1; y <= y2; y++)
246 for (x = x1; x <= x2; x++)
248 set_floor(player_ptr, x, y);
256 * find_space()の予備処理として部屋の生成が可能かを判定する /
257 * Helper function for find_space(). Is this a good location?
258 * @param blocks_high 範囲の高さ
259 * @param blocks_wide 範囲の幅
260 * @param block_y 範囲の上端
261 * @param block_x 範囲の左端
264 static bool find_space_aux(POSITION blocks_high, POSITION blocks_wide, POSITION block_y, POSITION block_x)
266 POSITION by1, bx1, by2, bx2, by, bx;
268 /* Itty-bitty rooms must shift about within their rectangle */
271 if ((blocks_wide == 2) && (block_x % 3) == 2)
275 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
276 else if ((blocks_wide % 3) == 0)
278 /* Must be aligned to the left edge of a 11x33 rectangle. */
279 if ((block_x % 3) != 0)
284 * Big rooms that do not have a width divisible by 3 must be
285 * aligned towards the edge of the dungeon closest to them.
289 /* Shift towards left edge of dungeon. */
290 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
292 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
294 if ((block_x % 3) == 1)
298 /* Shift toward right edge of dungeon. */
301 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
303 if ((block_x % 3) == 1)
311 by2 = block_y + blocks_high;
312 bx2 = block_x + blocks_wide;
314 /* Never run off the screen */
315 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
316 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
318 /* Verify available space */
319 for (by = by1; by < by2; by++)
321 for (bx = bx1; bx < bx2; bx++)
323 if (dun->room_map[by][bx])
330 /* This location is okay */
336 * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room. -LM-
337 * @param player_ptr プレーヤーへの参照ポインタ
338 * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
339 * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
340 * @param height 確保したい領域の高さ
341 * @param width 確保したい領域の幅
342 * @return 所定の範囲が確保できた場合TRUEを返す
344 * Find and allocate a free space in the dungeon large enough to hold\n
345 * the room calling this function.\n
347 * We allocate space in 11x11 blocks, but want to make sure that rooms\n
348 * align neatly on the standard screen. Therefore, we make them use\n
349 * blocks in few 11x33 rectangles as possible.\n
351 * Be careful to include the edges of the room in height and width!\n
353 * Return TRUE and values for the center of the room if all went well.\n
354 * Otherwise, return FALSE.\n
356 bool find_space(player_type *player_ptr, POSITION *y, POSITION *x, POSITION height, POSITION width)
358 int candidates, pick;
359 POSITION by, bx, by1, bx1, by2, bx2;
360 POSITION block_y = 0, block_x = 0;
362 /* Find out how many blocks we need. */
363 POSITION blocks_high = 1 + ((height - 1) / BLOCK_HGT);
364 POSITION blocks_wide = 1 + ((width - 1) / BLOCK_WID);
366 /* There are no way to allocate such huge space */
367 if (dun->row_rooms < blocks_high) return FALSE;
368 if (dun->col_rooms < blocks_wide) return FALSE;
373 /* Count the number of valid places */
374 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
376 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
378 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
380 /* Find a valid place */
393 if (!(d_info[player_ptr->current_floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE))
395 /* Choose a random one */
396 pick = randint1(candidates);
399 /* NO_CAVE dungeon (Castle) */
402 /* Always choose the center one */
403 pick = candidates / 2 + 1;
406 /* Pick up the choosen location */
407 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
409 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
411 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
415 /* This one is picked? */
426 by2 = block_y + blocks_high;
427 bx2 = block_x + blocks_wide;
430 * It is *extremely* important that the following calculation
431 * be *exactly* correct to prevent memory errors
434 /* Acquire the location of the room */
435 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
436 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
438 /* Save the room location */
439 if (dun->cent_n < CENT_MAX)
441 dun->cent[dun->cent_n].y = (byte_hack)*y;
442 dun->cent[dun->cent_n].x = (byte_hack)*x;
446 /* Reserve some blocks. */
447 for (by = by1; by < by2; by++)
449 for (bx = bx1; bx < bx2; bx++)
451 dun->room_map[by][bx] = TRUE;
456 * Hack- See if room will cut off a cavern.
458 * If so, fix by tunneling outside the room in such a
459 * way as to connect the caves.
461 check_room_boundary(player_ptr, *x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
469 * Structure to hold all "fill" data
472 typedef struct fill_data_type fill_data_type;
474 struct fill_data_type
487 /* features to fill with */
496 /* number of filled squares */
500 static fill_data_type fill_data;
503 /* Store routine for the fractal floor generator */
504 /* this routine probably should be an inline function or a macro. */
505 static void store_height(floor_type *floor_ptr, POSITION x, POSITION y, FEAT_IDX val)
507 /* if on boundary set val > cutoff so walls are not as square */
508 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
509 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
510 (val <= fill_data.c1)) val = fill_data.c1 + 1;
512 /* store the value in height-map format */
513 floor_ptr->grid_array[y][x].feat = val;
520 * Explanation of the plasma fractal algorithm:
522 * A grid of points is created with the properties of a 'height-map'
523 * This is done by making the corners of the grid have a random value.
524 * The grid is then subdivided into one with twice the resolution.
525 * The new points midway between two 'known' points can be calculated
526 * by taking the average value of the 'known' ones and randomly adding
527 * or subtracting an amount proportional to the distance between those
528 * points. The final 'middle' points of the grid are then calculated
529 * by averaging all four of the originally 'known' corner points. An
530 * random amount is added or subtracted from this to get a value of the
531 * height at that point. The scaling factor here is adjusted to the
532 * slightly larger distance diagonally as compared to orthogonally.
534 * This is then repeated recursively to fill an entire 'height-map'
535 * A rectangular map is done the same way, except there are different
536 * scaling factors along the x and y directions.
538 * A hack to change the amount of correlation between points is done using
539 * the grd variable. If the current step size is greater than grd then
540 * the point will be random, otherwise it will be calculated by the
541 * above algorithm. This makes a maximum distance at which two points on
542 * the height map can affect each other.
544 * How fractal caves are made:
546 * When the map is complete, a cut-off value is used to create a floor.
547 * Heights below this value are "floor", and heights above are "wall".
548 * This also can be used to create lakes, by adding more height levels
549 * representing shallow and deep water/ lava etc.
551 * The grd variable affects the width of passages.
552 * The roug variable affects the roughness of those passages
554 * The tricky part is making sure the created floor is connected. This
555 * is done by 'filling' from the inside and only keeping the 'filled'
556 * floor. Walls bounding the 'filled' floor are also kept. Everything
557 * else is converted to the normal _extra_.
562 * Note that this uses the floor array in a very hackish way
563 * the values are first set to zero, and then each array location
564 * is used as a "heightmap"
565 * The heightmap then needs to be converted back into the "feat" format.
567 * grd=level at which fractal turns on. smaller gives more mazelike caves
568 * roug=roughness level. 16=normal. higher values make things more convoluted
569 * small values are good for smooth walls.
570 * size=length of the side of the square grid system.
572 void generate_hmap(floor_type *floor_ptr, POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int grd, int roug, int cutoff)
574 POSITION xhsize, yhsize, xsize, ysize, maxsize;
577 * fixed point variables- these are stored as 256 x normal value
578 * this gives 8 binary places of fractional part + 8 places of normal part
581 POSITION xstep, xhstep, ystep, yhstep;
582 POSITION xstep2, xhstep2, ystep2, yhstep2;
583 POSITION i, j, ii, jj, diagsize, xxsize, yysize;
585 /* Cache for speed */
586 POSITION xm, xp, ym, yp;
588 /* redefine size so can change the value if out of range */
592 /* Paranoia about size of the system of caves */
593 if (xsize > 254) xsize = 254;
594 if (xsize < 4) xsize = 4;
595 if (ysize > 254) ysize = 254;
596 if (ysize < 4) ysize = 4;
598 /* get offsets to middle of array */
602 /* fix rounding problem */
606 /* get limits of region */
607 fill_data.xmin = x0 - xhsize;
608 fill_data.ymin = y0 - yhsize;
609 fill_data.xmax = x0 + xhsize;
610 fill_data.ymax = y0 + yhsize;
612 /* Store cutoff in global for quick access */
613 fill_data.c1 = cutoff;
616 * Scale factor for middle points:
617 * About sqrt(2) * 256 - correct for a square lattice
618 * approximately correct for everything else.
622 /* maximum of xsize and ysize */
623 maxsize = (xsize > ysize) ? xsize : ysize;
625 /* Clear the section */
626 for (i = 0; i <= xsize; i++)
628 for (j = 0; j <= ysize; j++)
630 /* -1 is a flag for "not done yet" */
631 floor_ptr->grid_array[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
632 /* Clear icky flag because may be redoing the floor_ptr->grid_array */
633 floor_ptr->grid_array[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
637 /* Boundaries are walls */
638 floor_ptr->grid_array[fill_data.ymin][fill_data.xmin].feat = (s16b)maxsize;
639 floor_ptr->grid_array[fill_data.ymax][fill_data.xmin].feat = (s16b)maxsize;
640 floor_ptr->grid_array[fill_data.ymin][fill_data.xmax].feat = (s16b)maxsize;
641 floor_ptr->grid_array[fill_data.ymax][fill_data.xmax].feat = (s16b)maxsize;
643 /* Set the middle square to be an open area. */
644 floor_ptr->grid_array[y0][x0].feat = 0;
646 /* Initialize the step sizes */
647 xstep = xhstep = xsize * 256;
648 ystep = yhstep = ysize * 256;
649 xxsize = xsize * 256;
650 yysize = ysize * 256;
653 * Fill in the rectangle with fractal height data -
654 * like the 'plasma fractal' in fractint.
656 while ((xhstep > 256) || (yhstep > 256))
658 /* Halve the step sizes */
664 /* cache well used values */
665 xstep2 = xstep / 256;
666 ystep2 = ystep / 256;
668 xhstep2 = xhstep / 256;
669 yhstep2 = yhstep / 256;
671 /* middle top to bottom. */
672 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
674 for (j = 0; j <= yysize; j += ystep)
676 /* cache often used values */
677 ii = i / 256 + fill_data.xmin;
678 jj = j / 256 + fill_data.ymin;
681 if (floor_ptr->grid_array[jj][ii].feat == -1)
685 /* If greater than 'grid' level then is random */
686 store_height(floor_ptr, ii, jj, randint1(maxsize));
690 /* Average of left and right points +random bit */
691 store_height(floor_ptr, ii, jj,
692 (floor_ptr->grid_array[jj][fill_data.xmin + (i - xhstep) / 256].feat
693 + floor_ptr->grid_array[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
694 + (randint1(xstep2) - xhstep2) * roug / 16);
701 /* middle left to right. */
702 for (j = yhstep; j <= yysize - yhstep; j += ystep)
704 for (i = 0; i <= xxsize; i += xstep)
706 /* cache often used values */
707 ii = i / 256 + fill_data.xmin;
708 jj = j / 256 + fill_data.ymin;
711 if (floor_ptr->grid_array[jj][ii].feat == -1)
715 /* If greater than 'grid' level then is random */
716 store_height(floor_ptr, ii, jj, randint1(maxsize));
720 /* Average of up and down points +random bit */
721 store_height(floor_ptr, ii, jj,
722 (floor_ptr->grid_array[fill_data.ymin + (j - yhstep) / 256][ii].feat
723 + floor_ptr->grid_array[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
724 + (randint1(ystep2) - yhstep2) * roug / 16);
731 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
733 for (j = yhstep; j <= yysize - yhstep; j += ystep)
735 /* cache often used values */
736 ii = i / 256 + fill_data.xmin;
737 jj = j / 256 + fill_data.ymin;
740 if (floor_ptr->grid_array[jj][ii].feat == -1)
744 /* If greater than 'grid' level then is random */
745 store_height(floor_ptr, ii, jj, randint1(maxsize));
749 /* Cache reused values. */
750 xm = fill_data.xmin + (i - xhstep) / 256;
751 xp = fill_data.xmin + (i + xhstep) / 256;
752 ym = fill_data.ymin + (j - yhstep) / 256;
753 yp = fill_data.ymin + (j + yhstep) / 256;
756 * Average over all four corners + scale by diagsize to
757 * reduce the effect of the square grid on the shape of the fractal
759 store_height(floor_ptr, ii, jj,
760 (floor_ptr->grid_array[ym][xm].feat + floor_ptr->grid_array[yp][xm].feat
761 + floor_ptr->grid_array[ym][xp].feat + floor_ptr->grid_array[yp][xp].feat) / 4
762 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
771 static bool hack_isnt_wall(player_type *player_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)
774 * function used to convert from height-map back to the
775 * normal angband floor_ptr->grid_array format
777 floor_type *floor_ptr = player_ptr->current_floor_ptr;
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_bold(player_ptr, y, x, gb_outer);
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(player_type *player_ptr, POSITION y, POSITION x)
859 /* Enqueue that entry */
863 /* Now process the queue */
864 floor_type *floor_ptr = player_ptr->current_floor_ptr;
865 while (flow_head != flow_tail)
867 /* Extract the next entry */
868 ty = tmp_pos.y[flow_head];
869 tx = tmp_pos.x[flow_head];
871 /* Forget that entry */
872 if (++flow_head == TEMP_MAX) flow_head = 0;
874 /* Add the "children" */
875 for (d = 0; d < 8; d++)
877 int old_head = flow_tail;
883 /* Paranoia Don't leave the floor_ptr->grid_array */
884 if (!in_bounds(floor_ptr, j, i))
886 /* affect boundary */
887 floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
891 /* If within bounds */
892 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
893 && (j > fill_data.ymin) && (j < fill_data.ymax))
895 /* If not a wall or floor done before */
896 if (hack_isnt_wall(player_ptr, j, i,
897 fill_data.c1, fill_data.c2, fill_data.c3,
898 fill_data.feat1, fill_data.feat2, fill_data.feat3,
899 fill_data.info1, fill_data.info2, fill_data.info3))
901 /* Enqueue that entry */
902 tmp_pos.y[flow_tail] = (byte_hack)j;
903 tmp_pos.x[flow_tail] = (byte_hack)i;
905 /* Advance the queue */
906 if (++flow_tail == TEMP_MAX) flow_tail = 0;
908 /* Hack -- Overflow by forgetting new entry */
909 if (flow_tail == flow_head)
911 flow_tail = old_head;
915 /* keep tally of size of floor_ptr->grid_array system */
916 (fill_data.amount)++;
922 /* affect boundary */
923 floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
930 bool generate_fracave(player_type *player_ptr, POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int cutoff, bool light, bool room)
932 POSITION x, y, xhsize, yhsize;
935 /* offsets to middle from corner */
941 * select region connected to center of floor_ptr->grid_array system
942 * this gets rid of alot of isolated one-sqaures that
943 * can make teleport traps instadeaths...
947 fill_data.c1 = cutoff;
951 /* features to fill with */
952 fill_data.feat1 = feat_ground_type[randint0(100)];
953 fill_data.feat2 = feat_ground_type[randint0(100)];
954 fill_data.feat3 = feat_ground_type[randint0(100)];
956 fill_data.info1 = CAVE_FLOOR;
957 fill_data.info2 = CAVE_FLOOR;
958 fill_data.info3 = CAVE_FLOOR;
960 /* number of filled squares */
961 fill_data.amount = 0;
963 floor_type *floor_ptr = player_ptr->current_floor_ptr;
964 cave_fill(player_ptr, (byte)y0, (byte)x0);
966 /* if tally too small, try again */
967 if (fill_data.amount < 10)
969 /* too small - clear area and try again later */
970 for (x = 0; x <= xsize; ++x)
972 for (y = 0; y <= ysize; ++y)
974 place_bold(player_ptr, y0 + y - yhsize, x0 + x - xhsize, gb_extra);
975 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
982 * Do boundarys-check to see if they are next to a filled region
983 * If not then they are set to normal granite
984 * If so then they are marked as room walls.
986 for (i = 0; i <= xsize; ++i)
989 if ((floor_ptr->grid_array[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
991 /* Next to a 'filled' region? - set to be room walls */
992 place_bold(player_ptr, y0 + 0 - yhsize, x0 + i - xhsize, gb_outer);
993 if (light) floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
994 floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
995 place_bold(player_ptr, y0 + 0 - yhsize, x0 + i - xhsize, gb_outer);
999 /* set to be normal granite */
1000 place_bold(player_ptr, y0 + 0 - yhsize, x0 + i - xhsize, gb_extra);
1003 /* bottom boundary */
1004 if ((floor_ptr->grid_array[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1006 /* Next to a 'filled' region? - set to be room walls */
1007 place_bold(player_ptr, y0 + ysize - yhsize, x0 + i - xhsize, gb_outer);
1008 if (light) floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
1009 floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
1010 place_bold(player_ptr, y0 + ysize - yhsize, x0 + i - xhsize, gb_outer);
1014 /* set to be normal granite */
1015 place_bold(player_ptr, y0 + ysize - yhsize, x0 + i - xhsize, gb_extra);
1018 /* clear the icky flag-don't need it any more */
1019 floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1020 floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1023 /* Do the left and right boundaries minus the corners (done above) */
1024 for (i = 1; i < ysize; ++i)
1027 if ((floor_ptr->grid_array[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
1030 place_bold(player_ptr, y0 + i - yhsize, x0 + 0 - xhsize, gb_outer);
1031 if (light) floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
1032 floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
1033 place_bold(player_ptr, y0 + i - yhsize, x0 + 0 - xhsize, gb_outer);
1038 place_bold(player_ptr, y0 + i - yhsize, x0 + 0 - xhsize, gb_extra);
1040 /* right boundary */
1041 if ((floor_ptr->grid_array[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
1044 place_bold(player_ptr, y0 + i - yhsize, x0 + xsize - xhsize, gb_outer);
1045 if (light) floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
1046 floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
1047 place_bold(player_ptr, y0 + i - yhsize, x0 + xsize - xhsize, gb_outer);
1052 place_bold(player_ptr, y0 + i - yhsize, x0 + xsize - xhsize, gb_extra);
1055 /* clear icky flag -done with it */
1056 floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1057 floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1061 /* Do the rest: convert back to the normal format */
1062 for (x = 1; x < xsize; ++x)
1064 for (y = 1; y < ysize; ++y)
1066 if (is_floor_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize) &&
1067 (floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1069 /* Clear the icky flag in the filled region */
1070 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
1072 /* Set appropriate flags */
1073 if (light) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1074 if (room) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1076 else if (is_outer_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize) &&
1077 (floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1080 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1081 if (light) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1084 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1089 place_bold(player_ptr, y0 + y - yhsize, x0 + x - xhsize, gb_extra);
1090 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
1095 /* Clear the unconnected regions */
1096 place_bold(player_ptr, y0 + y - yhsize, x0 + x - xhsize, gb_extra);
1097 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1103 * There is a slight problem when tunnels pierce the caves:
1104 * Extra doors appear inside the system. (Its not very noticeable though.)
1105 * This can be removed by "filling" from the outside in. This allows a separation
1106 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
1107 * The extra effort for what seems to be only a minor thing (even non-existant if you
1108 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
1117 * Builds a cave system in the center of the dungeon.
1119 void build_cavern(player_type *player_ptr)
1121 int grd, roug, cutoff;
1122 POSITION xsize, ysize, x0, y0;
1125 light = done = FALSE;
1126 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1127 if ((floor_ptr->dun_level <= randint1(50)) && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) light = TRUE;
1129 /* Make a cave the size of the dungeon */
1130 xsize = floor_ptr->width - 1;
1131 ysize = floor_ptr->height - 1;
1135 /* Paranoia: make size even */
1141 /* testing values for these parameters: feel free to adjust */
1142 grd = randint1(4) + 4;
1144 /* want average of about 16 */
1145 roug = randint1(8) * randint1(4);
1151 generate_hmap(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
1153 /* Convert to normal format+ clean up */
1154 done = generate_fracave(player_ptr, y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
1159 bool generate_lake(player_type *player_ptr, POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int c1, int c2, int c3, int type)
1161 POSITION x, y, xhsize, yhsize;
1163 FEAT_IDX feat1, feat2, feat3;
1165 /* offsets to middle from corner */
1169 /* Get features based on type */
1172 case LAKE_T_LAVA: /* Lava */
1173 feat1 = feat_deep_lava;
1174 feat2 = feat_shallow_lava;
1175 feat3 = feat_ground_type[randint0(100)];
1177 case LAKE_T_WATER: /* Water */
1178 feat1 = feat_deep_water;
1179 feat2 = feat_shallow_water;
1180 feat3 = feat_ground_type[randint0(100)];
1182 case LAKE_T_CAVE: /* Collapsed floor_ptr->grid_array */
1183 feat1 = feat_ground_type[randint0(100)];
1184 feat2 = feat_ground_type[randint0(100)];
1185 feat3 = feat_rubble;
1187 case LAKE_T_EARTH_VAULT: /* Earth vault */
1188 feat1 = feat_rubble;
1189 feat2 = feat_ground_type[randint0(100)];
1190 feat3 = feat_rubble;
1192 case LAKE_T_AIR_VAULT: /* Air vault */
1197 case LAKE_T_WATER_VAULT: /* Water vault */
1198 feat1 = feat_shallow_water;
1199 feat2 = feat_deep_water;
1200 feat3 = feat_shallow_water;
1202 case LAKE_T_FIRE_VAULT: /* Fire Vault */
1203 feat1 = feat_shallow_lava;
1204 feat2 = feat_deep_lava;
1205 feat3 = feat_shallow_lava;
1207 default: return FALSE;
1211 * select region connected to center of floor_ptr->grid_array system
1212 * this gets rid of alot of isolated one-sqaures that
1213 * can make teleport traps instadeaths...
1221 /* features to fill with */
1222 fill_data.feat1 = feat1;
1223 fill_data.feat2 = feat2;
1224 fill_data.feat3 = feat3;
1226 fill_data.info1 = 0;
1227 fill_data.info2 = 0;
1228 fill_data.info3 = 0;
1230 /* number of filled squares */
1231 fill_data.amount = 0;
1233 /* select region connected to center of floor_ptr->grid_array system
1234 * this gets rid of alot of isolated one-sqaures that
1235 * can make teleport traps instadeaths... */
1236 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1237 cave_fill(player_ptr, (byte)y0, (byte)x0);
1239 /* if tally too small, try again */
1240 if (fill_data.amount < 10)
1242 /* too small -clear area and try again later */
1243 for (x = 0; x <= xsize; ++x)
1245 for (y = 0; y <= ysize; ++y)
1247 place_bold(player_ptr, y0 + y - yhsize, x0 + x - xhsize, gb_floor);
1248 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1254 /* Do boundarys- set to normal granite */
1255 for (i = 0; i <= xsize; ++i)
1257 place_bold(player_ptr, y0 + 0 - yhsize, x0 + i - xhsize, gb_extra);
1258 place_bold(player_ptr, y0 + ysize - yhsize, x0 + i - xhsize, gb_extra);
1260 /* clear the icky flag-don't need it any more */
1261 floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1262 floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1265 /* Do the left and right boundaries minus the corners (done above) */
1267 for (i = 1; i < ysize; ++i)
1269 place_bold(player_ptr, y0 + i - yhsize, x0 + 0 - xhsize, gb_extra);
1270 place_bold(player_ptr, y0 + i - yhsize, x0 + xsize - xhsize, gb_extra);
1272 /* clear icky flag -done with it */
1273 floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1274 floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1278 /* Do the rest: convert back to the normal format */
1279 for (x = 1; x < xsize; ++x)
1281 for (y = 1; y < ysize; ++y)
1283 /* Fill unconnected regions with granite */
1284 if ((!(floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
1285 is_outer_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize))
1286 place_bold(player_ptr, y0 + y - yhsize, x0 + x - xhsize, gb_extra);
1288 /* turn off icky flag (no longer needed.) */
1289 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1292 if (cave_have_flag_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
1294 if (!(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
1304 * makes a lake/collapsed floor in the center of the dungeon
1306 void build_lake(player_type *player_ptr, int type)
1308 int grd, roug, xsize, ysize, x0, y0;
1312 /* paranoia - exit if lake type out of range. */
1313 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
1315 msg_format("Invalid lake type (%d)", type);
1319 /* Make the size of the dungeon */
1320 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1321 xsize = floor_ptr->width - 1;
1322 ysize = floor_ptr->height - 1;
1326 /* Paranoia: make size even */
1332 /* testing values for these parameters: feel free to adjust */
1333 grd = randint1(3) + 4;
1335 /* want average of about 16 */
1336 roug = randint1(8) * randint1(4);
1338 /* Make up size of various componants */
1342 /* Deep water/lava */
1343 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
1345 /* Shallow boundary */
1349 generate_hmap(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
1351 /* Convert to normal format+ clean up */
1352 done = generate_lake(player_ptr, y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
1358 * Routine that fills the empty areas of a room with treasure and monsters.
1360 void fill_treasure(player_type *player_ptr, POSITION x1, POSITION x2, POSITION y1, POSITION y2, int difficulty)
1362 POSITION x, y, cx, cy, size;
1365 /* center of room:*/
1369 /* Rough measure of size of vault= sum of lengths of sides */
1370 size = abs(x2 - x1) + abs(y2 - y1);
1372 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1373 for (x = x1; x <= x2; x++)
1375 for (y = y1; y <= y2; y++)
1377 /* Thing added based on distance to center of vault
1378 * Difficulty is 1-easy to 10-hard */
1379 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
1381 /* hack- empty square part of the time */
1382 if ((randint1(100) - difficulty * 3) > 50) value = 20;
1384 /* if floor, shallow water and lava */
1385 if (is_floor_bold(floor_ptr, y, x) ||
1386 (cave_have_flag_bold(floor_ptr, y, x, FF_PLACE) && cave_have_flag_bold(floor_ptr, y, x, FF_DROP)))
1388 /* The smaller 'value' is, the better the stuff */
1391 /* Meanest monster + treasure */
1392 floor_ptr->monster_level = floor_ptr->base_level + 40;
1393 place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1394 floor_ptr->monster_level = floor_ptr->base_level;
1395 floor_ptr->object_level = floor_ptr->base_level + 20;
1396 place_object(player_ptr, y, x, AM_GOOD);
1397 floor_ptr->object_level = floor_ptr->base_level;
1401 /* Mean monster +treasure */
1402 floor_ptr->monster_level = floor_ptr->base_level + 20;
1403 place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1404 floor_ptr->monster_level = floor_ptr->base_level;
1405 floor_ptr->object_level = floor_ptr->base_level + 10;
1406 place_object(player_ptr, y, x, AM_GOOD);
1407 floor_ptr->object_level = floor_ptr->base_level;
1409 else if (value < 10)
1411 floor_ptr->monster_level = floor_ptr->base_level + 9;
1412 place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1413 floor_ptr->monster_level = floor_ptr->base_level;
1415 else if (value < 17)
1417 /* Intentional Blank space */
1420 * (Want some of the vault to be empty
1421 * so have room for group monsters.
1422 * This is used in the hack above to lower
1423 * the density of stuff in the vault.)
1426 else if (value < 23)
1428 /* Object or trap */
1429 if (randint0(100) < 25)
1431 place_object(player_ptr, y, x, 0L);
1435 place_trap(player_ptr, y, x);
1438 else if (value < 30)
1440 /* Monster and trap */
1441 floor_ptr->monster_level = floor_ptr->base_level + 5;
1442 place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1443 floor_ptr->monster_level = floor_ptr->base_level;
1444 place_trap(player_ptr, y, x);
1446 else if (value < 40)
1448 /* Monster or object */
1449 if (randint0(100) < 50)
1451 floor_ptr->monster_level = floor_ptr->base_level + 3;
1452 place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1453 floor_ptr->monster_level = floor_ptr->base_level;
1455 if (randint0(100) < 50)
1457 floor_ptr->object_level = floor_ptr->base_level + 7;
1458 place_object(player_ptr, y, x, 0L);
1459 floor_ptr->object_level = floor_ptr->base_level;
1462 else if (value < 50)
1465 place_trap(player_ptr, y, x);
1471 /* 20% monster, 40% trap, 20% object, 20% blank space */
1472 if (randint0(100) < 20)
1474 place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1476 else if (randint0(100) < 50)
1478 place_trap(player_ptr, y, x);
1480 else if (randint0(100) < 50)
1482 place_object(player_ptr, y, x, 0L);
1493 * Overlay a rectangular room given its bounds
1494 * This routine is used by build_room_vault
1495 * The area inside the walls is not touched:
1496 * only granite is removed- normal walls stay
1498 void build_room(player_type *player_ptr, POSITION x1, POSITION x2, POSITION y1, POSITION y2)
1500 POSITION x, y, xsize, ysize;
1503 /* Check if rectangle has no width */
1504 if ((x1 == x2) || (y1 == y2)) return;
1508 /* Swap boundaries if in wrong order */
1516 /* Swap boundaries if in wrong order */
1522 /* get total widths */
1527 /* Top and bottom boundaries */
1528 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1529 for (i = 0; i <= xsize; i++)
1531 place_bold(player_ptr, y1, x1 + i, gb_outer_noperm);
1532 floor_ptr->grid_array[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1533 place_bold(player_ptr, y2, x1 + i, gb_outer_noperm);
1534 floor_ptr->grid_array[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1537 /* Left and right boundaries */
1538 for (i = 1; i < ysize; i++)
1540 place_bold(player_ptr, y1 + i, x1, gb_outer_noperm);
1541 floor_ptr->grid_array[y1 + i][x1].info |= (CAVE_ROOM | CAVE_ICKY);
1542 place_bold(player_ptr, y1 + i, x2, gb_outer_noperm);
1543 floor_ptr->grid_array[y1 + i][x2].info |= (CAVE_ROOM | CAVE_ICKY);
1547 for (x = 1; x < xsize; x++)
1549 for (y = 1; y < ysize; y++)
1551 if (is_extra_bold(floor_ptr, y1 + y, x1 + x))
1553 /* clear the untouched region */
1554 place_bold(player_ptr, y1 + y, x1 + x, gb_floor);
1555 floor_ptr->grid_array[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1559 /* make it a room- but don't touch */
1560 floor_ptr->grid_array[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1569 * maze vault -- rectangular labyrinthine rooms
1571 * maze vault uses two routines:
1572 * r_visit - a recursive routine that builds the labyrinth
1573 * build_maze_vault - a driver routine that calls r_visit and adds
1574 * monsters, traps and treasure
1576 * The labyrinth is built by creating a spanning tree of a graph.
1577 * The graph vertices are at
1578 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
1579 * and the edges are the vertical and horizontal nearest neighbors.
1581 * The spanning tree is created by performing a suitably randomized
1582 * depth-first traversal of the graph. The only adjustable parameter
1583 * is the randint0(3) below; it governs the relative density of
1584 * twists and turns in the labyrinth: smaller number, more twists.
1586 void r_visit(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, int node, DIRECTION dir, int *visited)
1588 int i, j, m, n, temp, x, y, adj[4];
1590 /* dimensions of vertex array */
1591 m = (x2 - x1) / 2 + 1;
1592 n = (y2 - y1) / 2 + 1;
1594 /* mark node visited and set it to a floor */
1596 x = 2 * (node % m) + x1;
1597 y = 2 * (node / m) + y1;
1598 place_bold(player_ptr, y, x, gb_floor);
1600 /* setup order of adjacent node visits */
1603 /* pick a random ordering */
1604 for (i = 0; i < 4; i++)
1606 for (i = 0; i < 4; i++)
1617 /* pick a random ordering with dir first */
1619 for (i = 1; i < 4; i++)
1621 for (i = 1; i < 4; i++)
1623 j = 1 + randint0(3);
1630 for (i = 0; i < 4; i++)
1635 /* (0,+) - check for bottom boundary */
1636 if ((node / m < n - 1) && (visited[node + m] == 0))
1638 place_bold(player_ptr, y + 1, x, gb_floor);
1639 r_visit(player_ptr, y1, x1, y2, x2, node + m, dir, visited);
1643 /* (0,-) - check for top boundary */
1644 if ((node / m > 0) && (visited[node - m] == 0))
1646 place_bold(player_ptr, y - 1, x, gb_floor);
1647 r_visit(player_ptr, y1, x1, y2, x2, node - m, dir, visited);
1651 /* (+,0) - check for right boundary */
1652 if ((node % m < m - 1) && (visited[node + 1] == 0))
1654 place_bold(player_ptr, y, x + 1, gb_floor);
1655 r_visit(player_ptr, y1, x1, y2, x2, node + 1, dir, visited);
1659 /* (-,0) - check for left boundary */
1660 if ((node % m > 0) && (visited[node - 1] == 0))
1662 place_bold(player_ptr, y, x - 1, gb_floor);
1663 r_visit(player_ptr, y1, x1, y2, x2, node - 1, dir, visited);
1670 void build_maze_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize, bool is_vault)
1672 POSITION y, x, dy, dx;
1673 POSITION y1, x1, y2, x2;
1674 int m, n, num_vertices, *visited;
1678 msg_print_wizard(CHEAT_DUNGEON, _("迷路ランダムVaultを生成しました。", "Maze Vault."));
1680 /* Choose lite or dark */
1681 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1682 light = ((floor_ptr->dun_level <= randint1(25)) && is_vault && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS));
1684 /* Pick a random room size - randomized by calling routine */
1693 /* generate the room */
1694 for (y = y1 - 1; y <= y2 + 1; y++)
1696 for (x = x1 - 1; x <= x2 + 1; x++)
1698 g_ptr = &floor_ptr->grid_array[y][x];
1699 g_ptr->info |= CAVE_ROOM;
1700 if (is_vault) g_ptr->info |= CAVE_ICKY;
1701 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
1703 place_grid(player_ptr, g_ptr, gb_outer);
1707 place_grid(player_ptr, g_ptr, gb_extra);
1711 place_grid(player_ptr, g_ptr, gb_inner);
1713 if (light) g_ptr->info |= (CAVE_GLOW);
1717 /* dimensions of vertex array */
1720 num_vertices = m * n;
1722 /* initialize array of visited vertices */
1723 C_MAKE(visited, num_vertices, int);
1725 /* traverse the graph to create a spaning tree, pick a random root */
1726 r_visit(player_ptr, y1, x1, y2, x2, randint0(num_vertices), 0, visited);
1728 /* Fill with monsters and treasure, low difficulty */
1729 if (is_vault) fill_treasure(player_ptr, x1, x2, y1, y2, randint1(5));
1731 C_KILL(visited, num_vertices, int);
1735 /* Build a town/ castle by using a recursive algorithm.
1736 * Basically divide each region in a probalistic way to create
1737 * smaller regions. When the regions get too small stop.
1739 * The power variable is a measure of how well defended a region is.
1740 * This alters the possible choices.
1742 void build_recursive_room(player_type *player_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int power)
1744 POSITION xsize, ysize;
1748 /* Temp variables */
1754 if ((power < 3) && (xsize > 12) && (ysize > 12))
1756 /* Need outside wall +keep */
1763 /* Make rooms + subdivide */
1764 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
1770 choice = randint1(2) + 1;
1775 /* Mostly subdivide */
1776 choice = randint1(3) + 1;
1780 /* Based on the choice made above, do something */
1787 /* top and bottom */
1788 for (x = x1; x <= x2; x++)
1790 place_bold(player_ptr, y1, x, gb_outer);
1791 place_bold(player_ptr, y2, x, gb_outer);
1794 /* left and right */
1795 for (y = y1 + 1; y < y2; y++)
1797 place_bold(player_ptr, y, x1, gb_outer);
1798 place_bold(player_ptr, y, x2, gb_outer);
1801 /* Make a couple of entrances */
1804 /* left and right */
1805 y = randint1(ysize) + y1;
1806 place_bold(player_ptr, y, x1, gb_floor);
1807 place_bold(player_ptr, y, x2, gb_floor);
1811 /* top and bottom */
1812 x = randint1(xsize) + x1;
1813 place_bold(player_ptr, y1, x, gb_floor);
1814 place_bold(player_ptr, y2, x, gb_floor);
1817 /* Select size of keep */
1818 t1 = randint1(ysize / 3) + y1;
1819 t2 = y2 - randint1(ysize / 3);
1820 t3 = randint1(xsize / 3) + x1;
1821 t4 = x2 - randint1(xsize / 3);
1823 /* Do outside areas */
1825 /* Above and below keep */
1826 build_recursive_room(player_ptr, x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
1827 build_recursive_room(player_ptr, x1 + 1, t2, x2 - 1, y2, power + 1);
1829 /* Left and right of keep */
1830 build_recursive_room(player_ptr, x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
1831 build_recursive_room(player_ptr, t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
1833 /* Make the keep itself: */
1846 /* Try to build a room */
1847 if ((xsize < 3) || (ysize < 3))
1849 for (y = y1; y < y2; y++)
1851 for (x = x1; x < x2; x++)
1853 place_bold(player_ptr, y, x, gb_inner);
1861 /* Make outside walls */
1862 /* top and bottom */
1863 for (x = x1 + 1; x <= x2 - 1; x++)
1865 place_bold(player_ptr, y1 + 1, x, gb_inner);
1866 place_bold(player_ptr, y2 - 1, x, gb_inner);
1869 /* left and right */
1870 for (y = y1 + 1; y <= y2 - 1; y++)
1872 place_bold(player_ptr, y, x1 + 1, gb_inner);
1873 place_bold(player_ptr, y, x2 - 1, gb_inner);
1877 y = randint1(ysize - 3) + y1 + 1;
1882 place_bold(player_ptr, y, x1 + 1, gb_floor);
1887 place_bold(player_ptr, y, x2 - 1, gb_floor);
1890 /* Build the room */
1891 build_recursive_room(player_ptr, x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
1896 /* Try and divide vertically */
1900 for (y = y1; y < y2; y++)
1902 for (x = x1; x < x2; x++)
1904 place_bold(player_ptr, y, x, gb_inner);
1910 t1 = randint1(xsize - 2) + x1 + 1;
1911 build_recursive_room(player_ptr, x1, y1, t1, y2, power - 2);
1912 build_recursive_room(player_ptr, t1 + 1, y1, x2, y2, power - 2);
1917 /* Try and divide horizontally */
1921 for (y = y1; y < y2; y++)
1923 for (x = x1; x < x2; x++)
1925 place_bold(player_ptr, y, x, gb_inner);
1931 t1 = randint1(ysize - 2) + y1 + 1;
1932 build_recursive_room(player_ptr, x1, y1, x2, t1, power - 2);
1933 build_recursive_room(player_ptr, x1, t1 + 1, x2, y2, power - 2);
1941 * Add outer wall to a floored region
1942 * Note: no range checking is done so must be inside dungeon
1943 * This routine also stomps on doors
1945 void add_outer_wall(player_type *player_ptr, POSITION x, POSITION y, int light, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
1948 feature_type *f_ptr;
1951 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1952 if (!in_bounds(floor_ptr, y, x)) return;
1954 g_ptr = &floor_ptr->grid_array[y][x];
1956 /* hack- check to see if square has been visited before
1957 * if so, then exit (use room flag to do this) */
1958 if (g_ptr->info & CAVE_ROOM) return;
1961 g_ptr->info |= CAVE_ROOM;
1963 f_ptr = &f_info[g_ptr->feat];
1965 if (is_floor_bold(floor_ptr, y, x))
1967 for (i = -1; i <= 1; i++)
1969 for (j = -1; j <= 1; j++)
1971 if ((x + i >= x1) && (x + i <= x2) && (y + j >= y1) && (y + j <= y2))
1973 add_outer_wall(player_ptr, x + i, y + j, light, x1, y1, x2, y2);
1974 if (light) g_ptr->info |= CAVE_GLOW;
1979 else if (is_extra_bold(floor_ptr, y, x))
1981 /* Set bounding walls */
1982 place_bold(player_ptr, y, x, gb_outer);
1983 if (light) g_ptr->info |= CAVE_GLOW;
1985 else if (permanent_wall(f_ptr))
1987 /* Set bounding walls */
1988 if (light) g_ptr->info |= CAVE_GLOW;
1994 * Hacked distance formula - gives the 'wrong' answer.
1995 * Used to build crypts
1997 POSITION dist2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, POSITION h1, POSITION h2, POSITION h3, POSITION h4)
2003 /* Basically this works by taking the normal pythagorean formula
2004 * and using an expansion to express this in a way without the
2005 * square root. This approximate formula is then perturbed to give
2006 * the distorted results. (I found this by making a mistake when I was
2007 * trying to fix the circular rooms.)
2010 /* h1-h4 are constants that describe the metric */
2011 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
2012 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
2013 return (((dx + dy) * 128) / 181 +
2014 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
2015 /* 128/181 is approx. 1/sqrt(2) */
2021 /* Create a new floor room with optional light */
2022 void generate_room_floor(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, int light)
2028 for (y = y1; y <= y2; y++)
2030 for (x = x1; x <= x2; x++)
2033 g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
2034 place_grid(player_ptr, g_ptr, gb_floor);
2035 g_ptr->info |= (CAVE_ROOM);
2036 if (light) g_ptr->info |= (CAVE_GLOW);
2041 void generate_fill_perm_bold(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
2045 for (y = y1; y <= y2; y++)
2047 for (x = x1; x <= x2; x++)
2050 place_bold(player_ptr, y, x, gb_inner_perm);
2057 * @brief 与えられた部屋型IDに応じて部屋の生成処理分岐を行い結果を返す / Attempt to build a room of the given type at the given block
2058 * @param player_ptr プレーヤーへの参照ポインタ
2060 * @note that we restrict the number of "crowded" rooms to reduce the chance of overflowing the monster list during level creation.
2061 * @return 部屋の生成に成功した場合 TRUE を返す。
2063 static bool room_build(player_type *player_ptr, EFFECT_ID typ)
2067 /* Build an appropriate room */
2068 case ROOM_T_NORMAL: return build_type1(player_ptr);
2069 case ROOM_T_OVERLAP: return build_type2(player_ptr);
2070 case ROOM_T_CROSS: return build_type3(player_ptr);
2071 case ROOM_T_INNER_FEAT: return build_type4(player_ptr);
2072 case ROOM_T_NEST: return build_type5(player_ptr);
2073 case ROOM_T_PIT: return build_type6(player_ptr);
2074 case ROOM_T_LESSER_VAULT: return build_type7(player_ptr);
2075 case ROOM_T_GREATER_VAULT: return build_type8(player_ptr);
2076 case ROOM_T_FRACAVE: return build_type9(player_ptr);
2077 case ROOM_T_RANDOM_VAULT: return build_type10(player_ptr);
2078 case ROOM_T_OVAL: return build_type11(player_ptr);
2079 case ROOM_T_CRYPT: return build_type12(player_ptr);
2080 case ROOM_T_TRAP_PIT: return build_type13(player_ptr);
2081 case ROOM_T_TRAP: return build_type14(player_ptr);
2082 case ROOM_T_GLASS: return build_type15(player_ptr);
2083 case ROOM_T_ARCADE: return build_type16(player_ptr);
2084 case ROOM_T_FIXED: return build_type17(player_ptr);
2090 * @brief 指定した部屋の生成確率を別の部屋に加算し、指定した部屋の生成率を0にする
2091 * @param dst 確率を移す先の部屋種ID
2092 * @param src 確率を与える元の部屋種ID
2094 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
2097 * @brief 部屋生成処理のメインルーチン(Sangbandを経由してOangbandからの実装を引用) / Generate rooms in dungeon. Build bigger rooms at first. [from SAngband (originally from OAngband)]
2098 * @param player_ptr プレーヤーへの参照ポインタ
2099 * @return 部屋生成に成功した場合 TRUE を返す。
2101 bool generate_rooms(player_type *player_ptr)
2103 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2108 int prob_list[ROOM_T_MAX];
2109 int rooms_built = 0;
2110 int area_size = 100 * (floor_ptr->height*floor_ptr->width) / (MAX_HGT*MAX_WID);
2111 int level_index = MIN(10, div_round(floor_ptr->dun_level, 10));
2113 /* Number of each type of room on this level */
2114 s16b room_num[ROOM_T_MAX];
2116 /* Limit number of rooms */
2117 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
2119 /* Assume normal floor_ptr->grid_array */
2120 room_info_type *room_info_ptr = room_info_normal;
2123 * Initialize probability list.
2125 for (i = 0; i < ROOM_T_MAX; i++)
2127 /* No rooms allowed above their minimum depth. */
2128 if (floor_ptr->dun_level < room_info_ptr[i].min_level)
2134 prob_list[i] = room_info_ptr[i].prob[level_index];
2139 * XXX -- Various dungeon types and options.
2142 /*! @details ダンジョンにBEGINNER、CHAMELEON、SMALLESTいずれのフラグもなく、
2143 * かつ「常に通常でない部屋を生成する」フラグがONならば、
2144 * GRATER_VAULTのみを生成対象とする。 / Ironman sees only Greater Vaults */
2145 if (ironman_rooms && !((d_info[floor_ptr->dungeon_idx].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
2147 for (i = 0; i < ROOM_T_MAX; i++)
2149 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
2150 else prob_list[i] = 0;
2154 /*! @details ダンジョンにNO_VAULTフラグがあるならば、LESSER_VAULT / GREATER_VAULT/ RANDOM_VAULTを除外 / Forbidden vaults */
2155 else if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_VAULT)
2157 prob_list[ROOM_T_LESSER_VAULT] = 0;
2158 prob_list[ROOM_T_GREATER_VAULT] = 0;
2159 prob_list[ROOM_T_RANDOM_VAULT] = 0;
2162 /*! @details ダンジョンにBEGINNERフラグがあるならば、FIXED_ROOMを除外 / Forbidden vaults */
2163 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_BEGINNER)
2165 prob_list[ROOM_T_FIXED] = 0;
2168 /*! @details ダンジョンにNO_CAVEフラグがある場合、FRACAVEの生成枠がNORMALに与えられる。CRIPT、OVALの生成枠がINNER_Fに与えられる。/ NO_CAVE dungeon (Castle)*/
2169 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE)
2171 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
2172 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
2173 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
2176 /*! @details ダンジョンにCAVEフラグがある場合、NORMALの生成枠がFRACAVEに与えられる。/ CAVE dungeon (Orc floor_ptr->grid_array etc.) */
2177 else if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_CAVE)
2179 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
2182 /*! @details ダンジョンの基本地形が最初から渓谷かアリーナ型の場合 FRACAVE は生成から除外。 / No caves when a (random) cavern exists: they look bad */
2183 else if (dun->cavern || dun->empty_level)
2185 prob_list[ROOM_T_FRACAVE] = 0;
2188 /*! @details ダンジョンに最初からGLASS_ROOMフラグがある場合、GLASS を生成から除外。/ Forbidden glass rooms */
2189 if (!(d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_ROOM))
2191 prob_list[ROOM_T_GLASS] = 0;
2194 /*! @details ARCADEは同フラグがダンジョンにないと生成されない。 / Forbidden glass rooms */
2195 if (!(d_info[floor_ptr->dungeon_idx].flags1 & DF1_ARCADE))
2197 prob_list[ROOM_T_ARCADE] = 0;
2201 * Initialize number of rooms,
2202 * And calcurate total probability.
2204 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
2207 total_prob += prob_list[i];
2211 * Prepare the number of rooms, of all types, we should build
2214 for (i = dun_rooms; i > 0; i--)
2217 int rand = randint0(total_prob);
2219 /* Get room_type randomly */
2220 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
2222 if (rand < prob_list[room_type]) break;
2223 else rand -= prob_list[room_type];
2225 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
2227 /* Increase the number of rooms of that type we should build. */
2228 room_num[room_type]++;
2234 case ROOM_T_LESSER_VAULT:
2235 case ROOM_T_TRAP_PIT:
2243 case ROOM_T_GREATER_VAULT:
2244 case ROOM_T_RANDOM_VAULT:
2253 * Build each type of room one by one until we cannot build any more.
2254 * [from SAngband (originally from OAngband)]
2258 /* Assume no remaining rooms */
2261 for (i = 0; i < ROOM_T_MAX; i++)
2263 /* What type of room are we building now? */
2264 int room_type = room_build_order[i];
2266 /* Go next if none available */
2267 if (!room_num[room_type]) continue;
2269 /* Use up one unit */
2270 room_num[room_type]--;
2272 /* Build the room. */
2273 if (room_build(player_ptr, room_type))
2275 /* Increase the room built count. */
2278 /* Mark as there was some remaining rooms */
2285 case ROOM_T_TRAP_PIT:
2287 /* Avoid too many monsters */
2290 room_num[ROOM_T_PIT] = 0;
2291 room_num[ROOM_T_NEST] = 0;
2292 room_num[ROOM_T_TRAP_PIT] = 0;
2298 /* Avoid double-town */
2299 room_num[ROOM_T_ARCADE] = 0;
2305 /* End loop if no room remain */
2309 /*! @details 部屋生成数が2未満の場合生成失敗を返す */
2310 if (rooms_built < 2)
2312 msg_format_wizard(CHEAT_DUNGEON, _("部屋数が2未満でした。生成を再試行します。", "Number of rooms was under 2. Retry."), rooms_built);
2316 msg_format_wizard(CHEAT_DUNGEON, _("このダンジョンの部屋数は %d です。", "Number of Rooms: %d"), rooms_built);