OSDN Git Service

[Refactor] #37353 地下都市生成処理を rooms.c から rooms-city.c/h へ分離。
[hengband/hengband.git] / src / rooms.c
1 /*!
2  * @file rooms.c
3  * @brief ダンジョンフロアの部屋生成処理 / make rooms. Used by generate.c when creating dungeons.
4  * @date 2014/01/06
5  * @author
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
11  * @details
12  * Room building routines.\n
13  *\n
14  * Room types:\n
15  *   1 -- normal\n
16  *   2 -- overlapping\n
17  *   3 -- cross shaped\n
18  *   4 -- large room with features\n
19  *   5 -- monster nests\n
20  *   6 -- monster pits\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
26  *  12 -- crypts\n
27  *  13 -- trapped monster pits\n
28  *  14 -- trapped room\n
29  *  15 -- glass room\n
30  *  16 -- underground arcade\n
31  *\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
34  * the given type.\n
35  *\n
36  * None of the pits/nests are allowed to include "unique" monsters.\n
37  */
38
39 #include "angband.h"
40 #include "generate.h"
41 #include "grid.h"
42 #include "rooms.h"
43
44 #include "rooms-normal.h"
45 #include "rooms-pitnest.h"
46 #include "rooms-vault.h"
47 #include "rooms-city.h"
48
49
50 /*!
51  * 各部屋タイプの生成比定義
52  *[from SAngband (originally from OAngband)]\n
53  *\n
54  * Table of values that control how many times each type of room will\n
55  * appear.  Each type of room has its own row, and each column\n
56  * corresponds to dungeon levels 0, 10, 20, and so on.  The final\n
57  * value is the minimum depth the room can appear at.  -LM-\n
58  *\n
59  * Level 101 and below use the values for level 100.\n
60  *\n
61  * Rooms with lots of monsters or loot may not be generated if the\n
62  * object or monster lists are already nearly full.  Rooms will not\n
63  * appear above their minimum depth.  Tiny levels will not have space\n
64  * for all the rooms you ask for.\n
65  */
66 static room_info_type room_info_normal[ROOM_T_MAX] =
67 {
68         /* Depth */
69         /*  0  10  20  30  40  50  60  70  80  90 100  min limit */
70
71         {{999,900,800,700,600,500,400,300,200,100,  0},  0}, /*NORMAL   */
72         {{  1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100},  1}, /*OVERLAP  */
73         {{  1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100},  3}, /*CROSS    */
74         {{  1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100},  3}, /*INNER_F  */
75         {{  0,  1,  1,  1,  2,  3,  5,  6,  8, 10, 13}, 10}, /*NEST     */
76         {{  0,  1,  1,  2,  3,  4,  6,  8, 10, 13, 16}, 10}, /*PIT      */
77         {{  0,  1,  1,  1,  2,  2,  3,  5,  6,  8, 10}, 10}, /*LESSER_V */
78         {{  0,  0,  1,  1,  1,  2,  2,  2,  3,  3,  4}, 20}, /*GREATER_V*/
79         {{  0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE  */
80         {{  0,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2}, 10}, /*RANDOM_V */
81         {{  0,  4,  8, 12, 16, 20, 24, 28, 32, 36, 40},  3}, /*OVAL     */
82         {{  1,  6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT    */
83         {{  0,  0,  1,  1,  1,  2,  3,  4,  5,  6,  8}, 20}, /*TRAP_PIT */
84         {{  0,  0,  1,  1,  1,  2,  3,  4,  5,  6,  8}, 20}, /*TRAP     */
85         {{  0,  0,  0,  0,  1,  1,  1,  2,  2,  2,  2}, 40}, /*GLASS    */
86         {{  1,  1,  1,  1,  1,  1,  1,  2,  2,  3,  3},  1}, /*ARCADE   */
87 };
88
89
90 /*! 部屋の生成処理順 / Build rooms in descending order of difficulty. */
91 static byte room_build_order[ROOM_T_MAX] = {
92         ROOM_T_GREATER_VAULT,
93         ROOM_T_ARCADE,
94         ROOM_T_RANDOM_VAULT,
95         ROOM_T_LESSER_VAULT,
96         ROOM_T_TRAP_PIT,
97         ROOM_T_PIT,
98         ROOM_T_NEST,
99         ROOM_T_TRAP,
100         ROOM_T_GLASS,
101         ROOM_T_INNER_FEAT,
102         ROOM_T_OVAL,
103         ROOM_T_CRYPT,
104         ROOM_T_OVERLAP,
105         ROOM_T_CROSS,
106         ROOM_T_FRACAVE,
107         ROOM_T_NORMAL,
108 };
109
110 /*!
111  * @brief 鍵のかかったドアを配置する
112  * @param y 配置したいフロアのY座標
113  * @param x 配置したいフロアのX座標
114  * @return なし
115  */
116 void place_locked_door(int y, int x)
117 {
118         if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
119         {
120                 place_floor_bold(y, x);
121         }
122         else
123         {
124                 set_cave_feat(y, x, feat_locked_door_random((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
125                 cave[y][x].info &= ~(CAVE_FLOOR);
126                 delete_monster(y, x);
127         }
128 }
129
130 /*!
131  * @brief 隠しドアを配置する
132  * @param y 配置したいフロアのY座標
133  * @param x 配置したいフロアのX座標
134  * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
135  * @return なし
136  */
137 void place_secret_door(int y, int x, int type)
138 {
139         if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
140         {
141                 place_floor_bold(y, x);
142         }
143         else
144         {
145                 cave_type *c_ptr = &cave[y][x];
146
147                 if (type == DOOR_DEFAULT)
148                 {
149                         type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
150                                 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
151                                 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
152                 }
153
154                 /* Create secret door */
155                 place_closed_door(y, x, type);
156
157                 if (type != DOOR_CURTAIN)
158                 {
159                         /* Hide by inner wall because this is used in rooms only */
160                         c_ptr->mimic = feat_wall_inner;
161
162                         /* Floor type terrain cannot hide a door */
163                         if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
164                         {
165                                 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
166                                 {
167                                         c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
168                                 }
169                                 c_ptr->mimic = 0;
170                         }
171                 }
172
173                 c_ptr->info &= ~(CAVE_FLOOR);
174                 delete_monster(y, x);
175         }
176 }
177
178 /*!
179  * @brief 1マスだけの部屋を作成し、上下左右いずれか一つに隠しドアを配置する。
180  * @param y0 配置したい中心のY座標
181  * @param x0 配置したい中心のX座標
182  * @details
183  * This funtion makes a very small room centred at (x0, y0)
184  * This is used in crypts, and random elemental vaults.
185  *
186  * Note - this should be used only on allocated regions
187  * within another room.
188  */
189 void build_small_room(int x0, int y0)
190 {
191         int x, y;
192
193         for (y = y0 - 1; y <= y0 + 1; y++)
194         {
195                 place_inner_bold(y, x0 - 1);
196                 place_inner_bold(y, x0 + 1);
197         }
198
199         for (x = x0 - 1; x <= x0 + 1; x++)
200         {
201                 place_inner_bold(y0 - 1, x);
202                 place_inner_bold(y0 + 1, x);
203         }
204
205         /* Place a secret door on one side */
206         switch (randint0(4))
207         {
208                 case 0: place_secret_door(y0, x0 - 1, DOOR_DEFAULT); break;
209                 case 1: place_secret_door(y0, x0 + 1, DOOR_DEFAULT); break;
210                 case 2: place_secret_door(y0 - 1, x0, DOOR_DEFAULT); break;
211                 case 3: place_secret_door(y0 + 1, x0, DOOR_DEFAULT); break;
212         }
213
214         /* Clear mimic type */
215         cave[y0][x0].mimic = 0;
216
217         /* Add inner open space */
218         place_floor_bold(y0, x0);
219 }
220
221 /*!
222  * @brief
223  * 指定範囲に通路が通っていることを確認した上で床で埋める
224  * This function tunnels around a room if it will cut off part of a cave system.
225  * @param x1 範囲の左端
226  * @param y1 範囲の上端
227  * @param x2 範囲の右端
228  * @param y2 範囲の下端
229  * @return なし
230  */
231 static void check_room_boundary(int x1, int y1, int x2, int y2)
232 {
233         int count, x, y;
234         bool old_is_floor, new_is_floor;
235
236
237         /* Initialize */
238         count = 0;
239
240         old_is_floor = get_is_floor(x1 - 1, y1);
241
242         /*
243          * Count the number of floor-wall boundaries around the room
244          * Note: diagonal squares are ignored since the player can move diagonally
245          * to bypass these if needed.
246          */
247
248         /* Above the top boundary */
249         for (x = x1; x <= x2; x++)
250         {
251                 new_is_floor = get_is_floor(x, y1 - 1);
252
253                 /* Increment counter if they are different */
254                 if (new_is_floor != old_is_floor) count++;
255
256                 old_is_floor = new_is_floor;
257         }
258
259         /* Right boundary */
260         for (y = y1; y <= y2; y++)
261         {
262                 new_is_floor = get_is_floor(x2 + 1, y);
263
264                 /* increment counter if they are different */
265                 if (new_is_floor != old_is_floor) count++;
266
267                 old_is_floor = new_is_floor;
268         }
269
270         /* Bottom boundary */
271         for (x = x2; x >= x1; x--)
272         {
273                 new_is_floor = get_is_floor(x, y2 + 1);
274
275                 /* increment counter if they are different */
276                 if (new_is_floor != old_is_floor) count++;
277
278                 old_is_floor = new_is_floor;
279         }
280
281         /* Left boundary */
282         for (y = y2; y >= y1; y--)
283         {
284                 new_is_floor = get_is_floor(x1 - 1, y);
285
286                 /* increment counter if they are different */
287                 if (new_is_floor != old_is_floor) count++;
288
289                 old_is_floor = new_is_floor;
290         }
291
292         /* If all the same, or only one connection exit. */
293         if (count <= 2) return;
294
295
296         /* Tunnel around the room so to prevent problems with caves */
297         for (y = y1; y <= y2; y++)
298         {
299                 for (x = x1; x <= x2; x++)
300                 {
301                         set_floor(x, y);
302                 }
303         }
304 }
305
306
307 /*!
308  * @brief
309  * find_space()の予備処理として部屋の生成が可能かを判定する /
310  * Helper function for find_space(). Is this a good location?
311  * @param blocks_high 範囲の高さ
312  * @param blocks_wide 範囲の幅
313  * @param block_y 範囲の上端
314  * @param block_x 範囲の左端
315  * @return なし
316  */
317 static bool find_space_aux(int blocks_high, int blocks_wide, int block_y, int block_x)
318 {
319         int by1, bx1, by2, bx2, by, bx;
320
321         /* Itty-bitty rooms must shift about within their rectangle */
322         if (blocks_wide < 3)
323         {
324                 if ((blocks_wide == 2) && (block_x % 3) == 2)
325                         return FALSE;
326         }
327
328         /* Rooms with width divisible by 3 must be fitted to a rectangle. */
329         else if ((blocks_wide % 3) == 0)
330         {
331                 /* Must be aligned to the left edge of a 11x33 rectangle. */
332                 if ((block_x % 3) != 0)
333                         return FALSE;
334         }
335
336         /*
337          * Big rooms that do not have a width divisible by 3 must be
338          * aligned towards the edge of the dungeon closest to them.
339          */
340         else
341         {
342                 /* Shift towards left edge of dungeon. */
343                 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
344                 {
345                         if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
346                                 return FALSE;
347                         if ((block_x % 3) == 1)
348                                 return FALSE;
349                 }
350
351                 /* Shift toward right edge of dungeon. */
352                 else
353                 {
354                         if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
355                                 return FALSE;
356                         if ((block_x % 3) == 1)
357                                 return FALSE;
358                 }
359         }
360
361         /* Extract blocks */
362         by1 = block_y + 0;
363         bx1 = block_x + 0;
364         by2 = block_y + blocks_high;
365         bx2 = block_x + blocks_wide;
366
367         /* Never run off the screen */
368         if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
369         if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
370         
371         /* Verify available space */
372         for (by = by1; by < by2; by++)
373         {
374                 for (bx = bx1; bx < bx2; bx++)
375                 {
376                         if (dun->room_map[by][bx])
377                         {
378                                 return FALSE;
379                         }
380                 }
381         }
382
383         /* This location is okay */
384         return TRUE;
385 }
386
387
388 /*!
389  * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room.  -LM-
390  * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
391  * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
392  * @param height 確保したい領域の高さ
393  * @param width 確保したい領域の幅
394  * @return 所定の範囲が確保できた場合TRUEを返す
395  * @details
396  * Find and allocate a free space in the dungeon large enough to hold\n
397  * the room calling this function.\n
398  *\n
399  * We allocate space in 11x11 blocks, but want to make sure that rooms\n
400  * align neatly on the standard screen.  Therefore, we make them use\n
401  * blocks in few 11x33 rectangles as possible.\n
402  *\n
403  * Be careful to include the edges of the room in height and width!\n
404  *\n
405  * Return TRUE and values for the center of the room if all went well.\n
406  * Otherwise, return FALSE.\n
407  */
408 bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
409 {
410         int candidates, pick;
411         int by, bx, by1, bx1, by2, bx2;
412         int block_y = 0, block_x = 0;
413
414
415         /* Find out how many blocks we need. */
416         int blocks_high = 1 + ((height - 1) / BLOCK_HGT);
417         int blocks_wide = 1 + ((width - 1) / BLOCK_WID);
418
419         /* There are no way to allocate such huge space */
420         if (dun->row_rooms < blocks_high) return FALSE;
421         if (dun->col_rooms < blocks_wide) return FALSE;
422
423         /* Initiallize */
424         candidates = 0;
425
426         /* Count the number of valid places */
427         for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
428         {
429                 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
430                 {
431                         if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
432                         {
433                                 /* Find a valid place */
434                                 candidates++;
435                         }
436                 }
437         }
438
439         /* No place! */
440         if (!candidates)
441         {
442                 return FALSE;
443         }
444
445         /* Normal dungeon */
446         if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
447         {
448                 /* Choose a random one */
449                 pick = randint1(candidates);
450         }
451
452         /* NO_CAVE dungeon (Castle) */
453         else
454         {
455                 /* Always choose the center one */
456                 pick = candidates/2 + 1;
457         }
458
459         /* Pick up the choosen location */
460         for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
461         {
462                 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
463                 {
464                         if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
465                         {
466                                 pick--;
467
468                                 /* This one is picked? */
469                                 if (!pick) break;
470                         }
471                 }
472
473                 if (!pick) break;
474         }
475
476         /* Extract blocks */
477         by1 = block_y + 0;
478         bx1 = block_x + 0;
479         by2 = block_y + blocks_high;
480         bx2 = block_x + blocks_wide;
481
482         /*
483          * It is *extremely* important that the following calculation
484          * be *exactly* correct to prevent memory errors
485          */
486
487         /* Acquire the location of the room */
488         (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
489         (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
490
491         /* Save the room location */
492         if (dun->cent_n < CENT_MAX)
493         {
494                 dun->cent[dun->cent_n].y = (byte_hack)*y;
495                 dun->cent[dun->cent_n].x = (byte_hack)*x;
496                 dun->cent_n++;
497         }
498
499         /* Reserve some blocks. */
500         for (by = by1; by < by2; by++)
501         {
502                 for (bx = bx1; bx < bx2; bx++)
503                 {
504                         dun->room_map[by][bx] = TRUE;
505                 }
506         }
507
508
509         /*
510          * Hack- See if room will cut off a cavern.
511          *
512          * If so, fix by tunneling outside the room in such a
513          * way as to connect the caves.
514          */
515         check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
516
517
518         /* Success. */
519         return TRUE;
520 }
521
522
523
524
525
526
527
528 /*
529  * Structure to hold all "fill" data
530  */
531
532 typedef struct fill_data_type fill_data_type;
533
534 struct fill_data_type
535 {
536         /* area size */
537         int xmin;
538         int ymin;
539         int xmax;
540         int ymax;
541
542         /* cutoffs */
543         int c1;
544         int c2;
545         int c3;
546
547         /* features to fill with */
548         int feat1;
549         int feat2;
550         int feat3;
551
552         int info1;
553         int info2;
554         int info3;
555
556         /* number of filled squares */
557         int amount;
558 };
559
560 static fill_data_type fill_data;
561
562
563 /* Store routine for the fractal cave generator */
564 /* this routine probably should be an inline function or a macro. */
565 static void store_height(int x, int y, int val)
566 {
567         /* if on boundary set val > cutoff so walls are not as square */
568         if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
569              (x == fill_data.xmax) || (y == fill_data.ymax)) &&
570             (val <= fill_data.c1)) val = fill_data.c1 + 1;
571
572         /* store the value in height-map format */
573         cave[y][x].feat = (s16b)val;
574
575         return;
576 }
577
578
579 /*
580 * Explanation of the plasma fractal algorithm:
581 *
582 * A grid of points is created with the properties of a 'height-map'
583 * This is done by making the corners of the grid have a random value.
584 * The grid is then subdivided into one with twice the resolution.
585 * The new points midway between two 'known' points can be calculated
586 * by taking the average value of the 'known' ones and randomly adding
587 * or subtracting an amount proportional to the distance between those
588 * points.  The final 'middle' points of the grid are then calculated
589 * by averaging all four of the originally 'known' corner points.  An
590 * random amount is added or subtracted from this to get a value of the
591 * height at that point.  The scaling factor here is adjusted to the
592 * slightly larger distance diagonally as compared to orthogonally.
593 *
594 * This is then repeated recursively to fill an entire 'height-map'
595 * A rectangular map is done the same way, except there are different
596 * scaling factors along the x and y directions.
597 *
598 * A hack to change the amount of correlation between points is done using
599 * the grd variable.  If the current step size is greater than grd then
600 * the point will be random, otherwise it will be calculated by the
601 * above algorithm.  This makes a maximum distance at which two points on
602 * the height map can affect each other.
603 *
604 * How fractal caves are made:
605 *
606 * When the map is complete, a cut-off value is used to create a cave.
607 * Heights below this value are "floor", and heights above are "wall".
608 * This also can be used to create lakes, by adding more height levels
609 * representing shallow and deep water/ lava etc.
610 *
611 * The grd variable affects the width of passages.
612 * The roug variable affects the roughness of those passages
613 *
614 * The tricky part is making sure the created cave is connected.  This
615 * is done by 'filling' from the inside and only keeping the 'filled'
616 * floor.  Walls bounding the 'filled' floor are also kept.  Everything
617 * else is converted to the normal _extra_.
618  */
619
620
621 /*
622  *  Note that this uses the cave.feat array in a very hackish way
623  *  the values are first set to zero, and then each array location
624  *  is used as a "heightmap"
625  *  The heightmap then needs to be converted back into the "feat" format.
626  *
627  *  grd=level at which fractal turns on.  smaller gives more mazelike caves
628  *  roug=roughness level.  16=normal.  higher values make things more convoluted
629  *    small values are good for smooth walls.
630  *  size=length of the side of the square cave system.
631  */
632 static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cutoff)
633 {
634         int xhsize, yhsize, xsize, ysize, maxsize;
635
636         /*
637          * fixed point variables- these are stored as 256 x normal value
638          * this gives 8 binary places of fractional part + 8 places of normal part
639          */
640
641         u16b xstep, xhstep, ystep, yhstep;
642         u16b xstep2, xhstep2, ystep2, yhstep2;
643         u16b i, j, ii, jj, diagsize, xxsize, yysize;
644         
645         /* Cache for speed */
646         u16b xm, xp, ym, yp;
647
648         /* redefine size so can change the value if out of range */
649         xsize = xsiz;
650         ysize = ysiz;
651
652         /* Paranoia about size of the system of caves */
653         if (xsize > 254) xsize = 254;
654         if (xsize < 4) xsize = 4;
655         if (ysize > 254) ysize = 254;
656         if (ysize < 4) ysize = 4;
657
658         /* get offsets to middle of array */
659         xhsize = xsize / 2;
660         yhsize = ysize / 2;
661
662         /* fix rounding problem */
663         xsize = xhsize * 2;
664         ysize = yhsize * 2;
665
666         /* get limits of region */
667         fill_data.xmin = x0 - xhsize;
668         fill_data.ymin = y0 - yhsize;
669         fill_data.xmax = x0 + xhsize;
670         fill_data.ymax = y0 + yhsize;
671
672         /* Store cutoff in global for quick access */
673         fill_data.c1 = cutoff;
674
675         /*
676         * Scale factor for middle points:
677         * About sqrt(2) * 256 - correct for a square lattice
678         * approximately correct for everything else.
679          */
680         diagsize = 362;
681
682         /* maximum of xsize and ysize */
683         maxsize = (xsize > ysize) ? xsize : ysize;
684
685         /* Clear the section */
686         for (i = 0; i <= xsize; i++)
687         {
688                 for (j = 0; j <= ysize; j++)
689                 {
690                         /* -1 is a flag for "not done yet" */
691                         cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
692                         /* Clear icky flag because may be redoing the cave */
693                         cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
694                 }
695         }
696
697         /* Boundaries are walls */
698         cave[fill_data.ymin][fill_data.xmin].feat = (s16b)maxsize;
699         cave[fill_data.ymax][fill_data.xmin].feat = (s16b)maxsize;
700         cave[fill_data.ymin][fill_data.xmax].feat = (s16b)maxsize;
701         cave[fill_data.ymax][fill_data.xmax].feat = (s16b)maxsize;
702
703         /* Set the middle square to be an open area. */
704         cave[y0][x0].feat = 0;
705
706         /* Initialize the step sizes */
707         xstep = xhstep = xsize * 256;
708         ystep = yhstep = ysize * 256;
709         xxsize = xsize * 256;
710         yysize = ysize * 256;
711
712         /*
713          * Fill in the rectangle with fractal height data -
714          * like the 'plasma fractal' in fractint.
715          */
716         while ((xhstep > 256) || (yhstep > 256))
717         {
718                 /* Halve the step sizes */
719                 xstep = xhstep;
720                 xhstep /= 2;
721                 ystep = yhstep;
722                 yhstep /= 2;
723
724                 /* cache well used values */
725                 xstep2 = xstep / 256;
726                 ystep2 = ystep / 256;
727
728                 xhstep2 = xhstep / 256;
729                 yhstep2 = yhstep / 256;
730
731                 /* middle top to bottom. */
732                 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
733                 {
734                         for (j = 0; j <= yysize; j += ystep)
735                         {
736                                 /* cache often used values */
737                                 ii = i / 256 + fill_data.xmin;
738                                 jj = j / 256 + fill_data.ymin;
739
740                                 /* Test square */
741                                 if (cave[jj][ii].feat == -1)
742                                 {
743                                         if (xhstep2 > grd)
744                                         {
745                                                 /* If greater than 'grid' level then is random */
746                                                 store_height(ii, jj, randint1(maxsize));
747                                         }
748                                         else
749                                         {
750                                                 /* Average of left and right points +random bit */
751                                                 store_height(ii, jj,
752                                                         (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
753                                                          + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
754                                                          + (randint1(xstep2) - xhstep2) * roug / 16);
755                                         }
756                                 }
757                         }
758                 }
759
760
761                 /* middle left to right. */
762                 for (j = yhstep; j <= yysize - yhstep; j += ystep)
763                 {
764                         for (i = 0; i <= xxsize; i += xstep)
765                         {
766                                 /* cache often used values */
767                                 ii = i / 256 + fill_data.xmin;
768                                 jj = j / 256 + fill_data.ymin;
769
770                                 /* Test square */
771                                 if (cave[jj][ii].feat == -1)
772                                 {
773                                         if (xhstep2 > grd)
774                                         {
775                                                 /* If greater than 'grid' level then is random */
776                                                 store_height(ii, jj, randint1(maxsize));
777                                         }
778                                         else
779                                         {
780                                                 /* Average of up and down points +random bit */
781                                                 store_height(ii, jj,
782                                                         (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
783                                                         + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
784                                                         + (randint1(ystep2) - yhstep2) * roug / 16);
785                                         }
786                                 }
787                         }
788                 }
789
790                 /* center. */
791                 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
792                 {
793                         for (j = yhstep; j <= yysize - yhstep; j += ystep)
794                         {
795                                 /* cache often used values */
796                                 ii = i / 256 + fill_data.xmin;
797                                 jj = j / 256 + fill_data.ymin;
798
799                                 /* Test square */
800                                 if (cave[jj][ii].feat == -1)
801                                 {
802                                         if (xhstep2 > grd)
803                                         {
804                                                 /* If greater than 'grid' level then is random */
805                                                 store_height(ii, jj, randint1(maxsize));
806                                         }
807                                         else
808                                         {
809                                                 /* Cache reused values. */
810                                                 xm = fill_data.xmin + (i - xhstep) / 256;
811                                                 xp = fill_data.xmin + (i + xhstep) / 256;
812                                                 ym = fill_data.ymin + (j - yhstep) / 256;
813                                                 yp = fill_data.ymin + (j + yhstep) / 256;
814
815                                                 /* 
816                                                  * Average over all four corners + scale by diagsize to
817                                                  * reduce the effect of the square grid on the shape of the fractal
818                                                  */
819                                                 store_height(ii, jj,
820                                                         (cave[ym][xm].feat + cave[yp][xm].feat
821                                                         + cave[ym][xp].feat + cave[yp][xp].feat) / 4
822                                                         + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
823                                         }
824                                 }
825                         }
826                 }
827         }
828 }
829
830
831 static bool hack_isnt_wall(int y, int x, int c1, int c2, int c3, int feat1, int feat2, int feat3, int info1, int info2, int info3)
832 {
833         /*
834          * function used to convert from height-map back to the
835          *  normal angband cave format
836          */
837         if (cave[y][x].info & CAVE_ICKY)
838         {
839                 /* already done */
840                 return FALSE;
841         }
842         else
843         {
844                 /* Show that have looked at this square */
845                 cave[y][x].info|= (CAVE_ICKY);
846
847                 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
848                 if (cave[y][x].feat <= c1)
849                 {
850                         /* 25% of the time use the other tile : it looks better this way */
851                         if (randint1(100) < 75)
852                         {
853                                 cave[y][x].feat = (s16b)feat1;
854                                 cave[y][x].info &= ~(CAVE_MASK);
855                                 cave[y][x].info |= info1;
856                                 return TRUE;
857                         }
858                         else
859                         {
860                                 cave[y][x].feat = (s16b)feat2;
861                                 cave[y][x].info &= ~(CAVE_MASK);
862                                 cave[y][x].info |= info2;
863                                 return TRUE;
864                         }
865                 }
866                 else if (cave[y][x].feat <= c2)
867                 {
868                         /* 25% of the time use the other tile : it looks better this way */
869                         if (randint1(100) < 75)
870                         {
871                                 cave[y][x].feat = (s16b)feat2;
872                                 cave[y][x].info &= ~(CAVE_MASK);
873                                 cave[y][x].info |= info2;
874                                 return TRUE;
875                         }
876                         else
877                         {
878                                 cave[y][x].feat = (s16b)feat1;
879                                 cave[y][x].info &= ~(CAVE_MASK);
880                                 cave[y][x].info |= info1;
881                                 return TRUE;
882                         }
883                 }
884                 else if (cave[y][x].feat <= c3)
885                 {
886                         cave[y][x].feat = (s16b)feat3;
887                         cave[y][x].info &= ~(CAVE_MASK);
888                         cave[y][x].info |= info3;
889                         return TRUE;
890                 }
891                 /* if greater than cutoff then is a wall */
892                 else
893                 {
894                         place_outer_bold(y, x);
895                         return FALSE;
896                 }
897         }
898 }
899
900
901
902
903 /*
904  * Quick and nasty fill routine used to find the connected region
905  * of floor in the middle of the cave
906  */
907 static void cave_fill(POSITION y, POSITION x)
908 {
909         int i, j, d;
910         int ty, tx;
911
912         int flow_tail = 1;
913         int flow_head = 0;
914
915
916         /*** Start Grid ***/
917
918         /* Enqueue that entry */
919         temp_y[0] = y;
920         temp_x[0] = x;
921
922
923         /* Now process the queue */
924         while (flow_head != flow_tail)
925         {
926                 /* Extract the next entry */
927                 ty = temp_y[flow_head];
928                 tx = temp_x[flow_head];
929
930                 /* Forget that entry */
931                 if (++flow_head == TEMP_MAX) flow_head = 0;
932
933                 /* Add the "children" */
934                 for (d = 0; d < 8; d++)
935                 {
936                         int old_head = flow_tail;
937
938                         /* Child location */
939                         j = ty + ddy_ddd[d];
940                         i = tx + ddx_ddd[d];
941
942                         /* Paranoia Don't leave the cave */
943                         if (!in_bounds(j, i))
944                         {
945                                 /* affect boundary */
946                                 cave[j][i].info |= CAVE_ICKY;
947 /*                              return; */
948                         }
949
950                         /* If within bounds */
951                         else if ((i > fill_data.xmin) && (i < fill_data.xmax)
952                                 && (j > fill_data.ymin) && (j < fill_data.ymax))
953                         {
954                                 /* If not a wall or floor done before */
955                                 if (hack_isnt_wall(j, i,
956                                         fill_data.c1, fill_data.c2, fill_data.c3,
957                                         fill_data.feat1, fill_data.feat2, fill_data.feat3,
958                                         fill_data.info1, fill_data.info2, fill_data.info3))
959                                 {
960                                         /* Enqueue that entry */
961                                         temp_y[flow_tail] = (byte_hack)j;
962                                         temp_x[flow_tail] = (byte_hack)i;
963
964                                         /* Advance the queue */
965                                         if (++flow_tail == TEMP_MAX) flow_tail = 0;
966
967                                         /* Hack -- Overflow by forgetting new entry */
968                                         if (flow_tail == flow_head)
969                                         {
970                                                 flow_tail = old_head;
971                                         }
972                                         else
973                                         {
974                                                 /* keep tally of size of cave system */
975                                                 (fill_data.amount)++;
976                                         }
977                                 }
978                         }
979                         else
980                         {
981                                 /* affect boundary */
982                                 cave[j][i].info |= CAVE_ICKY;
983                         }
984                 }
985         }
986 }
987
988
989 static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
990 {
991         int x, y, i, xhsize, yhsize;
992
993         /* offsets to middle from corner */
994         xhsize = xsize / 2;
995         yhsize = ysize / 2;
996
997
998         /*
999          * select region connected to center of cave system
1000          * this gets rid of alot of isolated one-sqaures that
1001          * can make teleport traps instadeaths...
1002          */
1003
1004         /* cutoffs */
1005         fill_data.c1 = cutoff;
1006         fill_data.c2 = 0;
1007         fill_data.c3 = 0;
1008
1009         /* features to fill with */
1010         fill_data.feat1 = floor_type[randint0(100)];
1011         fill_data.feat2 = floor_type[randint0(100)];
1012         fill_data.feat3 = floor_type[randint0(100)];
1013
1014         fill_data.info1 = CAVE_FLOOR;
1015         fill_data.info2 = CAVE_FLOOR;
1016         fill_data.info3 = CAVE_FLOOR;
1017
1018         /* number of filled squares */
1019         fill_data.amount = 0;
1020
1021         cave_fill((byte)y0, (byte)x0);
1022
1023         /* if tally too small, try again */
1024         if (fill_data.amount < 10)
1025         {
1026                 /* too small - clear area and try again later */
1027                 for (x = 0; x <= xsize; ++x)
1028                 {
1029                         for (y = 0; y <= ysize; ++y)
1030                         {
1031                                 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1032                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1033                         }
1034                 }
1035                 return FALSE;
1036         }
1037
1038         /*
1039          * Do boundarys-check to see if they are next to a filled region
1040          * If not then they are set to normal granite
1041          * If so then they are marked as room walls.
1042          */
1043         for (i = 0; i <= xsize; ++i)
1044         {
1045                 /* top boundary */
1046                 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1047                 {
1048                         /* Next to a 'filled' region? - set to be room walls */
1049                         place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1050                         if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
1051                         cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
1052                         place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1053                 }
1054                 else
1055                 {
1056                         /* set to be normal granite */
1057                         place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1058                 }
1059
1060                 /* bottom boundary */
1061                 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1062                 {
1063                         /* Next to a 'filled' region? - set to be room walls */
1064                         place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1065                         if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
1066                         cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
1067                         place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1068                 }
1069                 else
1070                 {
1071                         /* set to be normal granite */
1072                         place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1073                 }
1074
1075                 /* clear the icky flag-don't need it any more */
1076                 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1077                 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1078         }
1079
1080         /* Do the left and right boundaries minus the corners (done above) */
1081         for (i = 1; i < ysize; ++i)
1082         {
1083                 /* left boundary */
1084                 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
1085                 {
1086                         /* room boundary */
1087                         place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1088                         if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
1089                         cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
1090                         place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1091                 }
1092                 else
1093                 {
1094                         /* outside room */
1095                         place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1096                 }
1097                 /* right boundary */
1098                 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
1099                 {
1100                         /* room boundary */
1101                         place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1102                         if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
1103                         cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
1104                         place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1105                 }
1106                 else
1107                 {
1108                         /* outside room */
1109                         place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1110                 }
1111
1112                 /* clear icky flag -done with it */
1113                 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1114                 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1115         }
1116
1117
1118         /* Do the rest: convert back to the normal format */
1119         for (x = 1; x < xsize; ++x)
1120         {
1121                 for (y = 1; y < ysize; ++y)
1122                 {
1123                         if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
1124                             (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1125                         {
1126                                 /* Clear the icky flag in the filled region */
1127                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
1128
1129                                 /* Set appropriate flags */
1130                                 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1131                                 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1132                         }
1133                         else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
1134                                  (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1135                         {
1136                                 /* Walls */
1137                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1138                                 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1139                                 if (room)
1140                                 {
1141                                         cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1142                                 }
1143                                 else
1144                                 {
1145
1146                                         place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1147                                         cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
1148                                 }
1149                         }
1150                         else
1151                         {
1152                                 /* Clear the unconnected regions */
1153                                 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1154                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1155                         }
1156                 }
1157         }
1158
1159         /*
1160          * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
1161          * Extra doors appear inside the system.  (Its not very noticeable though.)
1162          * This can be removed by "filling" from the outside in.  This allows a separation
1163          * from _outer_ with _inner_.  (Internal walls are  _outer_ instead.)
1164          * The extra effort for what seems to be only a minor thing (even non-existant if you
1165          * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
1166          * worth it.
1167          */
1168
1169         return TRUE;
1170 }
1171
1172
1173 /*!
1174  * @brief タイプ9の部屋…フラクタルカーブによる洞窟生成 / Type 9 -- Driver routine to create fractal cave system
1175  * @return なし
1176  */
1177 static bool build_type9(void)
1178 {
1179         int grd, roug, cutoff;
1180         POSITION xsize, ysize, y0, x0;
1181
1182         bool done, light, room;
1183
1184         /* get size: note 'Evenness'*/
1185         xsize = randint1(22) * 2 + 6;
1186         ysize = randint1(15) * 2 + 6;
1187
1188         /* Find and reserve some space in the dungeon.  Get center of room. */
1189         if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
1190         {
1191                 /* Limit to the minimum room size, and retry */
1192                 xsize = 8;
1193                 ysize = 8;
1194
1195                 /* Find and reserve some space in the dungeon.  Get center of room. */
1196                 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
1197                 {
1198                         /*
1199                          * Still no space?!
1200                          * Try normal room
1201                          */
1202                         return build_type1();
1203                 }
1204         }
1205
1206         light = done = FALSE;
1207         room = TRUE;
1208
1209         if ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
1210
1211         while (!done)
1212         {
1213                 /* Note: size must be even or there are rounding problems
1214                 * This causes the tunnels not to connect properly to the room */
1215
1216                 /* testing values for these parameters feel free to adjust */
1217                 grd = 1 << (randint0(4));
1218
1219                 /* want average of about 16 */
1220                 roug = randint1(8) * randint1(4);
1221
1222                 /* about size/2 */
1223                 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
1224                          randint1(xsize / 4) + randint1(ysize / 4);
1225
1226                 /* make it */
1227                 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
1228
1229                 /* Convert to normal format + clean up */
1230                 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
1231         }
1232
1233         return TRUE;
1234 }
1235
1236 #ifdef ALLOW_CAVERNS_AND_LAKES
1237 /*
1238  * Builds a cave system in the center of the dungeon.
1239  */
1240 void build_cavern(void)
1241 {
1242         int grd, roug, cutoff, xsize, ysize, x0, y0;
1243         bool done, light;
1244
1245         light = done = FALSE;
1246         if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
1247
1248         /* Make a cave the size of the dungeon */
1249         xsize = cur_wid - 1;
1250         ysize = cur_hgt - 1;
1251         x0 = xsize / 2;
1252         y0 = ysize / 2;
1253
1254         /* Paranoia: make size even */
1255         xsize = x0 * 2;
1256         ysize = y0 * 2;
1257
1258         while (!done)
1259         {
1260                 /* testing values for these parameters: feel free to adjust */
1261                 grd = randint1(4) + 4;
1262
1263                 /* want average of about 16 */
1264                 roug = randint1(8) * randint1(4);
1265
1266                 /* about size/2 */
1267                 cutoff = xsize / 2;
1268
1269                  /* make it */
1270                 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
1271
1272                 /* Convert to normal format+ clean up */
1273                 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
1274         }
1275 }
1276
1277 static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
1278 {
1279         int x, y, i, xhsize, yhsize;
1280         int feat1, feat2, feat3;
1281
1282         /* offsets to middle from corner */
1283         xhsize = xsize / 2;
1284         yhsize = ysize / 2;
1285
1286         /* Get features based on type */
1287         switch (type)
1288         {
1289         case LAKE_T_LAVA: /* Lava */
1290                 feat1 = feat_deep_lava;
1291                 feat2 = feat_shallow_lava;
1292                 feat3 = floor_type[randint0(100)];
1293                 break;
1294         case LAKE_T_WATER: /* Water */
1295                 feat1 = feat_deep_water;
1296                 feat2 = feat_shallow_water;
1297                 feat3 = floor_type[randint0(100)];
1298                 break;
1299         case LAKE_T_CAVE: /* Collapsed cave */
1300                 feat1 = floor_type[randint0(100)];
1301                 feat2 = floor_type[randint0(100)];
1302                 feat3 = feat_rubble;
1303                 break;
1304         case LAKE_T_EARTH_VAULT: /* Earth vault */
1305                 feat1 = feat_rubble;
1306                 feat2 = floor_type[randint0(100)];
1307                 feat3 = feat_rubble;
1308                 break;
1309         case LAKE_T_AIR_VAULT: /* Air vault */
1310                 feat1 = feat_grass;
1311                 feat2 = feat_tree;
1312                 feat3 = feat_grass;
1313                 break;
1314         case LAKE_T_WATER_VAULT: /* Water vault */
1315                 feat1 = feat_shallow_water;
1316                 feat2 = feat_deep_water;
1317                 feat3 = feat_shallow_water;
1318                 break;
1319         case LAKE_T_FIRE_VAULT: /* Fire Vault */
1320                 feat1 = feat_shallow_lava;
1321                 feat2 = feat_deep_lava;
1322                 feat3 = feat_shallow_lava;
1323                 break;
1324
1325         /* Paranoia */
1326         default: return FALSE;
1327         }
1328
1329         /*
1330          * select region connected to center of cave system
1331          * this gets rid of alot of isolated one-sqaures that
1332          * can make teleport traps instadeaths...
1333          */
1334
1335         /* cutoffs */
1336         fill_data.c1 = c1;
1337         fill_data.c2 = c2;
1338         fill_data.c3 = c3;
1339
1340         /* features to fill with */
1341         fill_data.feat1 = feat1;
1342         fill_data.feat2 = feat2;
1343         fill_data.feat3 = feat3;
1344
1345         fill_data.info1 = 0;
1346         fill_data.info2 = 0;
1347         fill_data.info3 = 0;
1348
1349         /* number of filled squares */
1350         fill_data.amount = 0;
1351
1352         /* select region connected to center of cave system
1353         * this gets rid of alot of isolated one-sqaures that
1354         * can make teleport traps instadeaths... */
1355         cave_fill((byte)y0, (byte)x0);
1356
1357         /* if tally too small, try again */
1358         if (fill_data.amount < 10)
1359         {
1360                 /* too small -clear area and try again later */
1361                 for (x = 0; x <= xsize; ++x)
1362                 {
1363                         for (y = 0; y <= ysize; ++y)
1364                         {
1365                                 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
1366                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1367                         }
1368                 }
1369                 return FALSE;
1370         }
1371
1372         /* Do boundarys- set to normal granite */
1373         for (i = 0; i <= xsize; ++i)
1374         {
1375                 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1376                 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1377
1378                 /* clear the icky flag-don't need it any more */
1379                 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1380                 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1381         }
1382
1383         /* Do the left and right boundaries minus the corners (done above) */
1384
1385         for (i = 1; i < ysize; ++i)
1386         {
1387                 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1388                 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1389
1390                 /* clear icky flag -done with it */
1391                 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1392                 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1393         }
1394
1395
1396         /* Do the rest: convert back to the normal format */
1397         for (x = 1; x < xsize; ++x)
1398         {
1399                 for (y = 1; y < ysize; ++y)
1400                 {
1401                         /* Fill unconnected regions with granite */
1402                         if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
1403                                 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
1404                                 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1405
1406                         /* turn off icky flag (no longer needed.) */
1407                         cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1408
1409                         /* Light lava */
1410                         if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
1411                         {
1412                                 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
1413                         }
1414                 }
1415         }
1416
1417         return TRUE;
1418 }
1419
1420
1421 /*
1422  * makes a lake/collapsed cave system in the center of the dungeon
1423  */
1424 void build_lake(int type)
1425 {
1426         int grd, roug, xsize, ysize, x0, y0;
1427         bool done = FALSE;
1428         int c1, c2, c3;
1429
1430         /* paranoia - exit if lake type out of range. */
1431         if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
1432         {
1433                 msg_format("Invalid lake type (%d)", type);
1434                 return;
1435         }
1436
1437         /* Make the size of the dungeon */
1438         xsize = cur_wid - 1;
1439         ysize = cur_hgt - 1;
1440         x0 = xsize / 2;
1441         y0 = ysize / 2;
1442
1443         /* Paranoia: make size even */
1444         xsize = x0 * 2;
1445         ysize = y0 * 2;
1446
1447         while (!done)
1448         {
1449                 /* testing values for these parameters: feel free to adjust */
1450                 grd = randint1(3) + 4;
1451
1452                 /* want average of about 16 */
1453                 roug = randint1(8) * randint1(4);
1454
1455                 /* Make up size of various componants */
1456                 /* Floor */
1457                 c3 = 3 * xsize / 4;
1458
1459                 /* Deep water/lava */
1460                 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
1461
1462                 /* Shallow boundary */
1463                 c2 = (c1 + c3) / 2;
1464
1465                 /* make it */
1466                 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
1467
1468                 /* Convert to normal format+ clean up */
1469                 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
1470         }
1471 }
1472 #endif /* ALLOW_CAVERNS_AND_LAKES */
1473
1474
1475 /*
1476  * Routine used by the random vault creators to add a door to a location
1477  * Note that range checking has to be done in the calling routine.
1478  *
1479  * The doors must be INSIDE the allocated region.
1480  */
1481 static void add_door(int x, int y)
1482 {
1483         /* Need to have a wall in the center square */
1484         if (!is_outer_bold(y, x)) return;
1485
1486         /* look at:
1487          *  x#x
1488          *  .#.
1489          *  x#x
1490          *
1491          *  where x=don't care
1492          *  .=floor, #=wall
1493          */
1494
1495         if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
1496             (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
1497         {
1498                 /* secret door */
1499                 place_secret_door(y, x, DOOR_DEFAULT);
1500
1501                 /* set boundarys so don't get wide doors */
1502                 place_solid_bold(y, x - 1);
1503                 place_solid_bold(y, x + 1);
1504         }
1505
1506
1507         /* look at:
1508          *  x#x
1509          *  .#.
1510          *  x#x
1511          *
1512          *  where x = don't care
1513          *  .=floor, #=wall
1514          */
1515         if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
1516             is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
1517         {
1518                 /* secret door */
1519                 place_secret_door(y, x, DOOR_DEFAULT);
1520
1521                 /* set boundarys so don't get wide doors */
1522                 place_solid_bold(y - 1, x);
1523                 place_solid_bold(y + 1, x);
1524         }
1525 }
1526
1527
1528 /*
1529  * Routine that fills the empty areas of a room with treasure and monsters.
1530  */
1531 static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
1532 {
1533         int x, y, cx, cy, size;
1534         s32b value;
1535
1536         /* center of room:*/
1537         cx = (x1 + x2) / 2;
1538         cy = (y1 + y2) / 2;
1539
1540         /* Rough measure of size of vault= sum of lengths of sides */
1541         size = abs(x2 - x1) + abs(y2 - y1);
1542
1543         for (x = x1; x <= x2; x++)
1544         {
1545                 for (y = y1; y <= y2; y++)
1546                 {
1547                         /* Thing added based on distance to center of vault
1548                          * Difficulty is 1-easy to 10-hard */
1549                         value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
1550
1551                         /* hack- empty square part of the time */
1552                         if ((randint1(100) - difficulty * 3) > 50) value = 20;
1553
1554                          /* if floor, shallow water and lava */
1555                         if (is_floor_bold(y, x) ||
1556                             (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
1557                         {
1558                                 /* The smaller 'value' is, the better the stuff */
1559                                 if (value < 0)
1560                                 {
1561                                         /* Meanest monster + treasure */
1562                                         monster_level = base_level + 40;
1563                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1564                                         monster_level = base_level;
1565                                         object_level = base_level + 20;
1566                                         place_object(y, x, AM_GOOD);
1567                                         object_level = base_level;
1568                                 }
1569                                 else if (value < 5)
1570                                 {
1571                                         /* Mean monster +treasure */
1572                                         monster_level = base_level + 20;
1573                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1574                                         monster_level = base_level;
1575                                         object_level = base_level + 10;
1576                                         place_object(y, x, AM_GOOD);
1577                                         object_level = base_level;
1578                                 }
1579                                 else if (value < 10)
1580                                 {
1581                                         /* Monster */
1582                                         monster_level = base_level + 9;
1583                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1584                                         monster_level = base_level;
1585                                 }
1586                                 else if (value < 17)
1587                                 {
1588                                         /* Intentional Blank space */
1589
1590                                         /*
1591                                          * (Want some of the vault to be empty
1592                                          * so have room for group monsters.
1593                                          * This is used in the hack above to lower
1594                                          * the density of stuff in the vault.)
1595                                          */
1596                                 }
1597                                 else if (value < 23)
1598                                 {
1599                                         /* Object or trap */
1600                                         if (randint0(100) < 25)
1601                                         {
1602                                                 place_object(y, x, 0L);
1603                                         }
1604                                         else
1605                                         {
1606                                                 place_trap(y, x);
1607                                         }
1608                                 }
1609                                 else if (value < 30)
1610                                 {
1611                                         /* Monster and trap */
1612                                         monster_level = base_level + 5;
1613                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1614                                         monster_level = base_level;
1615                                         place_trap(y, x);
1616                                 }
1617                                 else if (value < 40)
1618                                 {
1619                                         /* Monster or object */
1620                                         if (randint0(100) < 50)
1621                                         {
1622                                                 monster_level = base_level + 3;
1623                                                 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1624                                                 monster_level = base_level;
1625                                         }
1626                                         if (randint0(100) < 50)
1627                                         {
1628                                                 object_level = base_level + 7;
1629                                                 place_object(y, x, 0L);
1630                                                 object_level = base_level;
1631                                         }
1632                                 }
1633                                 else if (value < 50)
1634                                 {
1635                                         /* Trap */
1636                                         place_trap(y, x);
1637                                 }
1638                                 else
1639                                 {
1640                                         /* Various Stuff */
1641
1642                                         /* 20% monster, 40% trap, 20% object, 20% blank space */
1643                                         if (randint0(100) < 20)
1644                                         {
1645                                                 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1646                                         }
1647                                         else if (randint0(100) < 50)
1648                                         {
1649                                                 place_trap(y, x);
1650                                         }
1651                                         else if (randint0(100) < 50)
1652                                         {
1653                                                 place_object(y, x, 0L);
1654                                         }
1655                                 }
1656
1657                         }
1658                 }
1659         }
1660 }
1661
1662
1663 /*
1664  * This function creates a random vault that looks like a collection of bubbles.
1665  * It works by getting a set of coordinates that represent the center of each
1666  * bubble.  The entire room is made by seeing which bubble center is closest. If
1667  * two centers are equidistant then the square is a wall, otherwise it is a floor.
1668  * The only exception is for squares really near a center, these are always floor.
1669  * (It looks better than without this check.)
1670  *
1671  * Note: If two centers are on the same point then this algorithm will create a
1672  *       blank bubble filled with walls. - This is prevented from happening.
1673  */
1674 static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
1675 {
1676         #define BUBBLENUM 10            /* number of bubbles */
1677
1678         /* array of center points of bubbles */
1679         coord center[BUBBLENUM];
1680
1681         int i, j, x, y;
1682         u16b min1, min2, temp;
1683         bool done;
1684
1685         /* Offset from center to top left hand corner */
1686         int xhsize = xsize / 2;
1687         int yhsize = ysize / 2;
1688
1689         msg_print_wizard(CHEAT_DUNGEON, _("泡型ランダムVaultを生成しました。", "Room Vault."));
1690
1691         /* Allocate center of bubbles */
1692         center[0].x = (byte)randint1(xsize - 3) + 1;
1693         center[0].y = (byte)randint1(ysize - 3) + 1;
1694
1695         for (i = 1; i < BUBBLENUM; i++)
1696         {
1697                 done = FALSE;
1698
1699                 /* get center and check to see if it is unique */
1700                 while (!done)
1701                 {
1702                         done = TRUE;
1703
1704                         x = randint1(xsize - 3) + 1;
1705                         y = randint1(ysize - 3) + 1;
1706
1707                         for (j = 0; j < i; j++)
1708                         {
1709                                 /* rough test to see if there is an overlap */
1710                                 if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
1711                         }
1712                 }
1713
1714                 center[i].x = (byte_hack)x;
1715                 center[i].y = (byte_hack)y;
1716         }
1717
1718
1719         /* Top and bottom boundaries */
1720         for (i = 0; i < xsize; i++)
1721         {
1722                 int side_x = x0 - xhsize + i;
1723
1724                 place_outer_noperm_bold(y0 - yhsize + 0, side_x);
1725                 cave[y0 - yhsize + 0][side_x].info |= (CAVE_ROOM | CAVE_ICKY);
1726                 place_outer_noperm_bold(y0 - yhsize + ysize - 1, side_x);
1727                 cave[y0 - yhsize + ysize - 1][side_x].info |= (CAVE_ROOM | CAVE_ICKY);
1728         }
1729
1730         /* Left and right boundaries */
1731         for (i = 1; i < ysize - 1; i++)
1732         {
1733                 int side_y = y0 - yhsize + i;
1734
1735                 place_outer_noperm_bold(side_y, x0 - xhsize + 0);
1736                 cave[side_y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
1737                 place_outer_noperm_bold(side_y, x0 - xhsize + xsize - 1);
1738                 cave[side_y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
1739         }
1740
1741         /* Fill in middle with bubbles */
1742         for (x = 1; x < xsize - 1; x++)
1743         {
1744                 for (y = 1; y < ysize - 1; y++)
1745                 {
1746                         /* Get distances to two closest centers */
1747
1748                         /* initialize */
1749                         min1 = (u16b)distance(x, y, center[0].x, center[0].y);
1750                         min2 = (u16b)distance(x, y, center[1].x, center[1].y);
1751
1752                         if (min1 > min2)
1753                         {
1754                                 /* swap if in wrong order */
1755                                 temp = min1;
1756                                 min1 = min2;
1757                                 min2 = temp;
1758                         }
1759
1760                         /* Scan the rest */
1761                         for (i = 2; i < BUBBLENUM; i++)
1762                         {
1763                                 temp = (u16b)distance(x, y, center[i].x, center[i].y);
1764
1765                                 if (temp < min1)
1766                                 {
1767                                         /* smallest */
1768                                         min2 = min1;
1769                                         min1 = temp;
1770                                 }
1771                                 else if (temp < min2)
1772                                 {
1773                                         /* second smallest */
1774                                         min2 = temp;
1775                                 }
1776                         }
1777                         if (((min2 - min1) <= 2) && (!(min1 < 3)))
1778                         {
1779                                 /* Boundary at midpoint+ not at inner region of bubble */
1780                                 place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
1781                         }
1782                         else
1783                         {
1784                                 /* middle of a bubble */
1785                                 place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
1786                         }
1787
1788                         /* clean up rest of flags */
1789                         cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
1790                 }
1791         }
1792
1793         /* Try to add some random doors */
1794         for (i = 0; i < 500; i++)
1795         {
1796                 x = randint1(xsize - 3) - xhsize + x0 + 1;
1797                 y = randint1(ysize - 3) - yhsize + y0 + 1;
1798                 add_door(x, y);
1799         }
1800
1801         /* Fill with monsters and treasure, low difficulty */
1802         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
1803 }
1804
1805
1806 /*
1807  * Overlay a rectangular room given its bounds
1808  * This routine is used by build_room_vault
1809  * The area inside the walls is not touched:
1810  * only granite is removed- normal walls stay
1811  */
1812 static void build_room(int x1, int x2, int y1, int y2)
1813 {
1814         int x, y, i, xsize, ysize, temp;
1815
1816         /* Check if rectangle has no width */
1817         if ((x1 == x2) || (y1 == y2)) return;
1818
1819         /* initialize */
1820         if (x1 > x2)
1821         {
1822                 /* Swap boundaries if in wrong order */
1823                 temp = x1;
1824                 x1 = x2;
1825                 x2 = temp;
1826         }
1827
1828         if (y1 > y2)
1829         {
1830                 /* Swap boundaries if in wrong order */
1831                 temp = y1;
1832                 y1 = y2;
1833                 y2 = temp;
1834         }
1835
1836         /* get total widths */
1837         xsize = x2 - x1;
1838         ysize = y2 - y1;
1839
1840
1841         /* Top and bottom boundaries */
1842         for (i = 0; i <= xsize; i++)
1843         {
1844                 place_outer_noperm_bold(y1, x1 + i);
1845                 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1846                 place_outer_noperm_bold(y2, x1 + i);
1847                 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1848         }
1849
1850         /* Left and right boundaries */
1851         for (i = 1; i < ysize; i++)
1852         {
1853                 place_outer_noperm_bold(y1 + i, x1);
1854                 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
1855                 place_outer_noperm_bold(y1 + i, x2);
1856                 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
1857         }
1858
1859         /* Middle */
1860         for (x = 1; x < xsize; x++)
1861         {
1862                 for (y = 1; y < ysize; y++)
1863                 {
1864                         if (is_extra_bold(y1+y, x1+x))
1865                         {
1866                                 /* clear the untouched region */
1867                                 place_floor_bold(y1 + y, x1 + x);
1868                                 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1869                         }
1870                         else
1871                         {
1872                                 /* make it a room- but don't touch */
1873                                 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1874                         }
1875                 }
1876         }
1877 }
1878
1879
1880 /* Create a random vault that looks like a collection of overlapping rooms */
1881
1882 static void build_room_vault(int x0, int y0, int xsize, int ysize)
1883 {
1884         int i, x1, x2, y1, y2, xhsize, yhsize;
1885
1886         /* get offset from center */
1887         xhsize = xsize / 2;
1888         yhsize = ysize / 2;
1889
1890         msg_print_wizard(CHEAT_DUNGEON, _("部屋型ランダムVaultを生成しました。", "Room Vault."));
1891
1892         /* fill area so don't get problems with arena levels */
1893         for (x1 = 0; x1 < xsize; x1++)
1894         {
1895                 int x = x0 - xhsize + x1;
1896
1897                 for (y1 = 0; y1 < ysize; y1++)
1898                 {
1899                         int y = y0 - yhsize + y1;
1900
1901                         place_extra_bold(y, x);
1902                         cave[y][x].info &= (~CAVE_ICKY);
1903                 }
1904         }
1905
1906         /* add ten random rooms */
1907         for (i = 0; i < 10; i++)
1908         {
1909                 x1 = randint1(xhsize) * 2 + x0 - xhsize;
1910                 x2 = randint1(xhsize) * 2 + x0 - xhsize;
1911                 y1 = randint1(yhsize) * 2 + y0 - yhsize;
1912                 y2 = randint1(yhsize) * 2 + y0 - yhsize;
1913                 build_room(x1, x2, y1, y2);
1914         }
1915
1916         /* Add some random doors */
1917         for (i = 0; i < 500; i++)
1918         {
1919                 x1 = randint1(xsize - 3) - xhsize + x0 + 1;
1920                 y1 = randint1(ysize - 3) - yhsize + y0 + 1;
1921                 add_door(x1, y1);
1922         }
1923
1924         /* Fill with monsters and treasure, high difficulty */
1925         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
1926 }
1927
1928
1929 /* Create a random vault out of a fractal cave */
1930 static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
1931 {
1932         int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y;
1933         bool done, light, room;
1934
1935         /* round to make sizes even */
1936         xhsize = xsiz / 2;
1937         yhsize = ysiz / 2;
1938         xsize = xhsize * 2;
1939         ysize = yhsize * 2;
1940
1941         msg_print_wizard(CHEAT_DUNGEON, _("洞穴ランダムVaultを生成しました。", "Cave Vault."));
1942
1943         light = done = FALSE;
1944         room = TRUE;
1945
1946         while (!done)
1947         {
1948                 /* testing values for these parameters feel free to adjust */
1949                 grd = 1 << randint0(4);
1950
1951                 /* want average of about 16 */
1952                 roug = randint1(8) * randint1(4);
1953
1954                 /* about size/2 */
1955                 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
1956                          randint1(xsize / 4) + randint1(ysize / 4);
1957
1958                 /* make it */
1959                 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
1960
1961                 /* Convert to normal format+ clean up */
1962                 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
1963         }
1964
1965         /* Set icky flag because is a vault */
1966         for (x = 0; x <= xsize; x++)
1967         {
1968                 for (y = 0; y <= ysize; y++)
1969                 {
1970                         cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
1971                 }
1972         }
1973
1974         /* Fill with monsters and treasure, low difficulty */
1975         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
1976 }
1977
1978 /*
1979  * maze vault -- rectangular labyrinthine rooms
1980  *
1981  * maze vault uses two routines:
1982  *    r_visit - a recursive routine that builds the labyrinth
1983  *    build_maze_vault - a driver routine that calls r_visit and adds
1984  *                   monsters, traps and treasure
1985  *
1986  * The labyrinth is built by creating a spanning tree of a graph.
1987  * The graph vertices are at
1988  *    (x, y) = (2j + x1, 2k + y1)   j = 0,...,m-1    k = 0,...,n-1
1989  * and the edges are the vertical and horizontal nearest neighbors.
1990  *
1991  * The spanning tree is created by performing a suitably randomized
1992  * depth-first traversal of the graph. The only adjustable parameter
1993  * is the randint0(3) below; it governs the relative density of
1994  * twists and turns in the labyrinth: smaller number, more twists.
1995  */
1996 static void r_visit(int y1, int x1, int y2, int x2,
1997                     int node, int dir, int *visited)
1998 {
1999         int i, j, m, n, temp, x, y, adj[4];
2000
2001         /* dimensions of vertex array */
2002         m = (x2 - x1) / 2 + 1;
2003         n = (y2 - y1) / 2 + 1;
2004
2005         /* mark node visited and set it to a floor */
2006         visited[node] = 1;
2007         x = 2 * (node % m) + x1;
2008         y = 2 * (node / m) + y1;
2009         place_floor_bold(y, x);
2010
2011         /* setup order of adjacent node visits */
2012         if (one_in_(3))
2013         {
2014                 /* pick a random ordering */
2015                 for (i = 0; i < 4; i++)
2016                         adj[i] = i;
2017                 for (i = 0; i < 4; i++)
2018                 {
2019                         j = randint0(4);
2020                         temp = adj[i];
2021                         adj[i] = adj[j];
2022                         adj[j] = temp;
2023                 }
2024                 dir = adj[0];
2025         }
2026         else
2027         {
2028                 /* pick a random ordering with dir first */
2029                 adj[0] = dir;
2030                 for (i = 1; i < 4; i++)
2031                         adj[i] = i;
2032                 for (i = 1; i < 4; i++)
2033                 {
2034                         j = 1 + randint0(3);
2035                         temp = adj[i];
2036                         adj[i] = adj[j];
2037                         adj[j] = temp;
2038                 }
2039         }
2040
2041         for (i = 0; i < 4; i++)
2042         {
2043                 switch (adj[i])
2044                 {
2045                         case 0:
2046                                 /* (0,+) - check for bottom boundary */
2047                                 if ((node / m < n - 1) && (visited[node + m] == 0))
2048                                 {
2049                                         place_floor_bold(y + 1, x);
2050                                         r_visit(y1, x1, y2, x2, node + m, dir, visited);
2051                                 }
2052                                 break;
2053                         case 1:
2054                                 /* (0,-) - check for top boundary */
2055                                 if ((node / m > 0) && (visited[node - m] == 0))
2056                                 {
2057                                         place_floor_bold(y - 1, x);
2058                                         r_visit(y1, x1, y2, x2, node - m, dir, visited);
2059                                 }
2060                                 break;
2061                         case 2:
2062                                 /* (+,0) - check for right boundary */
2063                                 if ((node % m < m - 1) && (visited[node + 1] == 0))
2064                                 {
2065                                         place_floor_bold(y, x + 1);
2066                                         r_visit(y1, x1, y2, x2, node + 1, dir, visited);
2067                                 }
2068                                 break;
2069                         case 3:
2070                                 /* (-,0) - check for left boundary */
2071                                 if ((node % m > 0) && (visited[node - 1] == 0))
2072                                 {
2073                                         place_floor_bold(y, x - 1);
2074                                         r_visit(y1, x1, y2, x2, node - 1, dir, visited);
2075                                 }
2076                 } /* end switch */
2077         }
2078 }
2079
2080
2081 void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
2082 {
2083         int y, x, dy, dx;
2084         int y1, x1, y2, x2;
2085         int m, n, num_vertices, *visited;
2086         bool light;
2087         cave_type *c_ptr;
2088
2089         msg_print_wizard(CHEAT_DUNGEON, _("迷路ランダムVaultを生成しました。", "Maze Vault."));
2090
2091         /* Choose lite or dark */
2092         light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
2093
2094         /* Pick a random room size - randomized by calling routine */
2095         dy = ysize / 2 - 1;
2096         dx = xsize / 2 - 1;
2097
2098         y1 = y0 - dy;
2099         x1 = x0 - dx;
2100         y2 = y0 + dy;
2101         x2 = x0 + dx;
2102
2103         /* generate the room */
2104         for (y = y1 - 1; y <= y2 + 1; y++)
2105         {
2106                 for (x = x1 - 1; x <= x2 + 1; x++)
2107                 {
2108                         c_ptr = &cave[y][x];
2109                         c_ptr->info |= CAVE_ROOM;
2110                         if (is_vault) c_ptr->info |= CAVE_ICKY;
2111                         if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
2112                         {
2113                                 place_outer_grid(c_ptr);
2114                         }
2115                         else if (!is_vault)
2116                         {
2117                                 place_extra_grid(c_ptr);
2118                         }
2119                         else
2120                         {
2121                                 place_inner_grid(c_ptr);
2122                         }
2123                         if (light) c_ptr->info |= (CAVE_GLOW);
2124                 }
2125         }
2126
2127         /* dimensions of vertex array */
2128         m = dx + 1;
2129         n = dy + 1;
2130         num_vertices = m * n;
2131
2132         /* initialize array of visited vertices */
2133         C_MAKE(visited, num_vertices, int);
2134
2135         /* traverse the graph to create a spaning tree, pick a random root */
2136         r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
2137
2138         /* Fill with monsters and treasure, low difficulty */
2139         if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
2140
2141         C_KILL(visited, num_vertices, int);
2142 }
2143
2144
2145 /* Build a "mini" checkerboard vault
2146  *
2147  * This is done by making a permanent wall maze and setting
2148  * the diagonal sqaures of the checker board to be granite.
2149  * The vault has two entrances on opposite sides to guarantee
2150  * a way to get in even if the vault abuts a side of the dungeon.
2151  */
2152 static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
2153 {
2154         int dy, dx;
2155         int y1, x1, y2, x2, y, x, total;
2156         int m, n, num_vertices;
2157         int *visited;
2158
2159         msg_print_wizard(CHEAT_DUNGEON, _("小型チェッカーランダムVaultを生成しました。", "Mini Checker Board Vault."));
2160
2161         /* Pick a random room size */
2162         dy = ysize / 2 - 1;
2163         dx = xsize / 2 - 1;
2164
2165         y1 = y0 - dy;
2166         x1 = x0 - dx;
2167         y2 = y0 + dy;
2168         x2 = x0 + dx;
2169
2170
2171         /* generate the room */
2172         for (x = x1 - 2; x <= x2 + 2; x++)
2173         {
2174                 if (!in_bounds(y1-2,x)) break;
2175
2176                 cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY);
2177
2178                 place_outer_noperm_bold(y1-2, x);
2179         }
2180
2181         for (x = x1 - 2; x <= x2 + 2; x++)
2182         {
2183                 if (!in_bounds(y2+2,x)) break;
2184
2185                 cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY);
2186
2187                 place_outer_noperm_bold(y2+2, x);
2188         }
2189
2190         for (y = y1 - 2; y <= y2 + 2; y++)
2191         {
2192                 if (!in_bounds(y,x1-2)) break;
2193
2194                 cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY);
2195
2196                 place_outer_noperm_bold(y, x1-2);
2197         }
2198
2199         for (y = y1 - 2; y <= y2 + 2; y++)
2200         {
2201                 if (!in_bounds(y,x2+2)) break;
2202
2203                 cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY);
2204
2205                 place_outer_noperm_bold(y, x2+2);
2206         }
2207
2208         for (y = y1 - 1; y <= y2 + 1; y++)
2209         {
2210                 for (x = x1 - 1; x <= x2 + 1; x++)
2211                 {
2212                         cave_type *c_ptr = &cave[y][x];
2213
2214                         c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
2215
2216                         /* Permanent walls */
2217                         place_inner_perm_grid(c_ptr);
2218                 }
2219         }
2220
2221
2222         /* dimensions of vertex array */
2223         m = dx + 1;
2224         n = dy + 1;
2225         num_vertices = m * n;
2226
2227         /* initialize array of visited vertices */
2228         C_MAKE(visited, num_vertices, int);
2229
2230         /* traverse the graph to create a spannng tree, pick a random root */
2231         r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
2232
2233         /* Make it look like a checker board vault */
2234         for (x = x1; x <= x2; x++)
2235         {
2236                 for (y = y1; y <= y2; y++)
2237                 {
2238                         total = x - x1 + y - y1;
2239                         /* If total is odd- and is a floor then make a wall */
2240                         if ((total % 2 == 1) && is_floor_bold(y, x))
2241                         {
2242                                 place_inner_bold(y, x);
2243                         }
2244                 }
2245         }
2246
2247         /* Make a couple of entrances */
2248         if (one_in_(2))
2249         {
2250                 /* left and right */
2251                 y = randint1(dy) + dy / 2;
2252                 place_inner_bold(y1 + y, x1 - 1);
2253                 place_inner_bold(y1 + y, x2 + 1);
2254         }
2255         else
2256         {
2257                 /* top and bottom */
2258                 x = randint1(dx) + dx / 2;
2259                 place_inner_bold(y1 - 1, x1 + x);
2260                 place_inner_bold(y2 + 1, x1 + x);
2261         }
2262
2263         /* Fill with monsters and treasure, highest difficulty */
2264         fill_treasure(x1, x2, y1, y2, 10);
2265
2266         C_KILL(visited, num_vertices, int);
2267 }
2268
2269
2270 /* Build a town/ castle by using a recursive algorithm.
2271  * Basically divide each region in a probalistic way to create
2272  * smaller regions.  When the regions get too small stop.
2273  *
2274  * The power variable is a measure of how well defended a region is.
2275  * This alters the possible choices.
2276  */
2277 static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
2278 {
2279         int xsize, ysize;
2280         int x, y;
2281         int choice;
2282
2283         /* Temp variables */
2284         int t1, t2, t3, t4;
2285
2286         xsize = x2 - x1;
2287         ysize = y2 - y1;
2288
2289         if ((power < 3) && (xsize > 12) && (ysize > 12))
2290         {
2291                 /* Need outside wall +keep */
2292                 choice = 1;
2293         }
2294         else
2295         {
2296                 if (power < 10)
2297                 {
2298                         /* Make rooms + subdivide */
2299                         if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
2300                         {
2301                                 choice = 4;
2302                         }
2303                         else
2304                         {
2305                                 choice = randint1(2) + 1;
2306                         }
2307                 }
2308                 else
2309                 {
2310                         /* Mostly subdivide */
2311                         choice = randint1(3) + 1;
2312                 }
2313         }
2314
2315         /* Based on the choice made above, do something */
2316
2317         switch (choice)
2318         {
2319                 case 1:
2320                 {
2321                         /* Outer walls */
2322
2323                         /* top and bottom */
2324                         for (x = x1; x <= x2; x++)
2325                         {
2326                                 place_outer_bold(y1, x);
2327                                 place_outer_bold(y2, x);
2328                         }
2329
2330                         /* left and right */
2331                         for (y = y1 + 1; y < y2; y++)
2332                         {
2333                                 place_outer_bold(y, x1);
2334                                 place_outer_bold(y, x2);
2335                         }
2336
2337                         /* Make a couple of entrances */
2338                         if (one_in_(2))
2339                         {
2340                                 /* left and right */
2341                                 y = randint1(ysize) + y1;
2342                                 place_floor_bold(y, x1);
2343                                 place_floor_bold(y, x2);
2344                         }
2345                         else
2346                         {
2347                                 /* top and bottom */
2348                                 x = randint1(xsize) + x1;
2349                                 place_floor_bold(y1, x);
2350                                 place_floor_bold(y2, x);
2351                         }
2352
2353                         /* Select size of keep */
2354                         t1 = randint1(ysize / 3) + y1;
2355                         t2 = y2 - randint1(ysize / 3);
2356                         t3 = randint1(xsize / 3) + x1;
2357                         t4 = x2 - randint1(xsize / 3);
2358
2359                         /* Do outside areas */
2360
2361                         /* Above and below keep */
2362                         build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
2363                         build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
2364
2365                         /* Left and right of keep */
2366                         build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
2367                         build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
2368
2369                         /* Make the keep itself: */
2370                         x1 = t3;
2371                         x2 = t4;
2372                         y1 = t1;
2373                         y2 = t2;
2374                         xsize = x2 - x1;
2375                         ysize = y2 - y1;
2376                         power += 2;
2377
2378                         /* Fall through */
2379                 }
2380                 case 4:
2381                 {
2382                         /* Try to build a room */
2383                         if ((xsize < 3) || (ysize < 3))
2384                         {
2385                                 for (y = y1; y < y2; y++)
2386                                 {
2387                                         for (x = x1; x < x2; x++)
2388                                         {
2389                                                 place_inner_bold(y, x);
2390                                         }
2391                                 }
2392
2393                                 /* Too small */
2394                                 return;
2395                         }
2396
2397                         /* Make outside walls */
2398                         /* top and bottom */
2399                         for (x = x1 + 1; x <= x2 - 1; x++)
2400                         {
2401                                 place_inner_bold(y1 + 1, x);
2402                                 place_inner_bold(y2 - 1, x);
2403                         }
2404
2405                         /* left and right */
2406                         for (y = y1 + 1; y <= y2 - 1; y++)
2407                         {
2408                                 place_inner_bold(y, x1 + 1);
2409                                 place_inner_bold(y, x2 - 1);
2410                         }
2411
2412                         /* Make a door */
2413                         y = randint1(ysize - 3) + y1 + 1;
2414
2415                         if (one_in_(2))
2416                         {
2417                                 /* left */
2418                                 place_floor_bold(y, x1 + 1);
2419                         }
2420                         else
2421                         {
2422                                 /* right */
2423                                 place_floor_bold(y, x2 - 1);
2424                         }
2425
2426                         /* Build the room */
2427                         build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
2428                         break;
2429                 }
2430                 case 2:
2431                 {
2432                         /* Try and divide vertically */
2433                         if (xsize < 3)
2434                         {
2435                                 /* Too small */
2436                                 for (y = y1; y < y2; y++)
2437                                 {
2438                                         for (x = x1; x < x2; x++)
2439                                         {
2440                                                 place_inner_bold(y, x);
2441                                         }
2442                                 }
2443                                 return;
2444                         }
2445
2446                         t1 = randint1(xsize - 2) + x1 + 1;
2447                         build_recursive_room(x1, y1, t1, y2, power - 2);
2448                         build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
2449                         break;
2450                 }
2451                 case 3:
2452                 {
2453                         /* Try and divide horizontally */
2454                         if (ysize < 3)
2455                         {
2456                                 /* Too small */
2457                                 for (y = y1; y < y2; y++)
2458                                 {
2459                                         for (x = x1; x < x2; x++)
2460                                         {
2461                                                 place_inner_bold(y, x);
2462                                         }
2463                                 }
2464                                 return;
2465                         }
2466
2467                         t1 = randint1(ysize - 2) + y1 + 1;
2468                         build_recursive_room(x1, y1, x2, t1, power - 2);
2469                         build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
2470                         break;
2471                 }
2472         }
2473 }
2474
2475
2476 /* Build a castle */
2477
2478 /* Driver routine: clear the region and call the recursive
2479 * room routine.
2480 *
2481 *This makes a vault that looks like a castle/ city in the dungeon.
2482 */
2483 static void build_castle_vault(int x0, int y0, int xsize, int ysize)
2484 {
2485         int dy, dx;
2486         int y1, x1, y2, x2;
2487         int y, x;
2488
2489         /* Pick a random room size */
2490         dy = ysize / 2 - 1;
2491         dx = xsize / 2 - 1;
2492
2493         y1 = y0 - dy;
2494         x1 = x0 - dx;
2495         y2 = y0 + dy;
2496         x2 = x0 + dx;
2497
2498         msg_print_wizard(CHEAT_DUNGEON, _("城型ランダムVaultを生成しました。", "Castle Vault"));
2499
2500         /* generate the room */
2501         for (y = y1 - 1; y <= y2 + 1; y++)
2502         {
2503                 for (x = x1 - 1; x <= x2 + 1; x++)
2504                 {
2505                         cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
2506                         /* Make everything a floor */
2507                         place_floor_bold(y, x);
2508                 }
2509         }
2510
2511         /* Make the castle */
2512         build_recursive_room(x1, y1, x2, y2, randint1(5));
2513
2514         /* Fill with monsters and treasure, low difficulty */
2515         fill_treasure(x1, x2, y1, y2, randint1(3));
2516 }
2517
2518
2519 /*
2520  * Add outer wall to a floored region
2521  * Note: no range checking is done so must be inside dungeon
2522  * This routine also stomps on doors
2523  */
2524 void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
2525 {
2526         cave_type *c_ptr;
2527         feature_type *f_ptr;
2528         int i, j;
2529
2530         if (!in_bounds(y, x)) return;
2531
2532         c_ptr = &cave[y][x];
2533
2534         /* hack- check to see if square has been visited before
2535         * if so, then exit (use room flag to do this) */
2536         if (c_ptr->info & CAVE_ROOM) return;
2537
2538         /* set room flag */
2539         c_ptr->info |= CAVE_ROOM;
2540
2541         f_ptr = &f_info[c_ptr->feat];
2542
2543         if (is_floor_bold(y, x))
2544         {
2545                 for (i = -1; i <= 1; i++)
2546                 {
2547                         for (j = -1; j <= 1; j++)
2548                         {
2549                                 if ((x + i >= x1) && (x + i <= x2) &&
2550                                          (y + j >= y1) && (y + j <= y2))
2551                                 {
2552                                         add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
2553                                         if (light) c_ptr->info |= CAVE_GLOW;
2554                                 }
2555                         }
2556                 }
2557         }
2558         else if (is_extra_bold(y, x))
2559         {
2560                 /* Set bounding walls */
2561                 place_outer_bold(y, x);
2562                 if (light) c_ptr->info |= CAVE_GLOW;
2563         }
2564         else if (permanent_wall(f_ptr))
2565         {
2566                 /* Set bounding walls */
2567                 if (light) c_ptr->info |= CAVE_GLOW;
2568         }
2569 }
2570
2571
2572 /*
2573  * Hacked distance formula - gives the 'wrong' answer.
2574  * Used to build crypts
2575  */
2576 int dist2(int x1, int y1, int x2, int y2, int h1, int h2, int h3, int h4)
2577 {
2578         int dx, dy;
2579         dx = abs(x2 - x1);
2580         dy = abs(y2 - y1);
2581
2582         /* Basically this works by taking the normal pythagorean formula
2583          * and using an expansion to express this in a way without the
2584          * square root.  This approximate formula is then perturbed to give
2585          * the distorted results.  (I found this by making a mistake when I was
2586          * trying to fix the circular rooms.)
2587          */
2588
2589         /* h1-h4 are constants that describe the metric */
2590         if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
2591         if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
2592         return (((dx + dy) * 128) / 181 +
2593                 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
2594         /* 128/181 is approx. 1/sqrt(2) */
2595 }
2596
2597
2598 /*
2599  * Build target vault.
2600  * This is made by two concentric "crypts" with perpendicular
2601  * walls creating the cross-hairs.
2602  */
2603 static void build_target_vault(int x0, int y0, int xsize, int ysize)
2604 {
2605         int rad, x, y;
2606
2607         /* Make a random metric */
2608         int h1, h2, h3, h4;
2609         h1 = randint1(32) - 16;
2610         h2 = randint1(16);
2611         h3 = randint1(32);
2612         h4 = randint1(32) - 16;
2613
2614         msg_print_wizard(CHEAT_DUNGEON, _("対称形ランダムVaultを生成しました。", "Elemental Vault"));
2615
2616         /* work out outer radius */
2617         if (xsize > ysize)
2618         {
2619                 rad = ysize / 2;
2620         }
2621         else
2622         {
2623                 rad = xsize / 2;
2624         }
2625
2626         /* Make floor */
2627         for (x = x0 - rad; x <= x0 + rad; x++)
2628         {
2629                 for (y = y0 - rad; y <= y0 + rad; y++)
2630                 {
2631                         /* clear room flag */
2632                         cave[y][x].info &= ~(CAVE_ROOM);
2633
2634                         /* Vault - so is "icky" */
2635                         cave[y][x].info |= CAVE_ICKY;
2636
2637                         if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
2638                         {
2639                                 /* inside- so is floor */
2640                                 place_floor_bold(y, x);
2641                         }
2642                         else
2643                         {
2644                                 /* make granite outside so arena works */
2645                                 place_extra_bold(y, x);
2646                         }
2647
2648                         /* proper boundary for arena */
2649                         if (((y + rad) == y0) || ((y - rad) == y0) ||
2650                             ((x + rad) == x0) || ((x - rad) == x0))
2651                         {
2652                                 place_extra_bold(y, x);
2653                         }
2654                 }
2655         }
2656
2657         /* Find visible outer walls and set to be FEAT_OUTER */
2658         add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
2659                        x0 + rad + 1, y0 + rad + 1);
2660
2661         /* Add inner wall */
2662         for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
2663         {
2664                 for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
2665                 {
2666                         if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
2667                         {
2668                                 /* Make an internal wall */
2669                                 place_inner_bold(y, x);
2670                         }
2671                 }
2672         }
2673
2674         /* Add perpendicular walls */
2675         for (x = x0 - rad; x <= x0 + rad; x++)
2676         {
2677                 place_inner_bold(y0, x);
2678         }
2679
2680         for (y = y0 - rad; y <= y0 + rad; y++)
2681         {
2682                 place_inner_bold(y, x0);
2683         }
2684
2685         /* Make inner vault */
2686         for (y = y0 - 1; y <= y0 + 1; y++)
2687         {
2688                 place_inner_bold(y, x0 - 1);
2689                 place_inner_bold(y, x0 + 1);
2690         }
2691         for (x = x0 - 1; x <= x0 + 1; x++)
2692         {
2693                 place_inner_bold(y0 - 1, x);
2694                 place_inner_bold(y0 + 1, x);
2695         }
2696
2697         place_floor_bold(y0, x0);
2698
2699
2700         /* Add doors to vault */
2701         /* get two distances so can place doors relative to centre */
2702         x = (rad - 2) / 4 + 1;
2703         y = rad / 2 + x;
2704
2705         add_door(x0 + x, y0);
2706         add_door(x0 + y, y0);
2707         add_door(x0 - x, y0);
2708         add_door(x0 - y, y0);
2709         add_door(x0, y0 + x);
2710         add_door(x0, y0 + y);
2711         add_door(x0, y0 - x);
2712         add_door(x0, y0 - y);
2713
2714         /* Fill with stuff - medium difficulty */
2715         fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
2716 }
2717
2718
2719 #ifdef ALLOW_CAVERNS_AND_LAKES
2720 /*
2721  * This routine uses a modified version of the lake code to make a
2722  * distribution of some terrain type over the vault.  This type
2723  * depends on the dungeon depth.
2724  *
2725  * Miniture rooms are then scattered across the vault.
2726  */
2727 static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
2728 {
2729         int grd, roug;
2730         int c1, c2, c3;
2731         bool done = FALSE;
2732         int xsize, ysize, xhsize, yhsize, x, y, i;
2733         int type;
2734
2735         msg_print_wizard(CHEAT_DUNGEON, _("精霊界ランダムVaultを生成しました。", "Elemental Vault"));
2736
2737         /* round to make sizes even */
2738         xhsize = xsiz / 2;
2739         yhsize = ysiz / 2;
2740         xsize = xhsize * 2;
2741         ysize = yhsize * 2;
2742
2743         if (dun_level < 25)
2744         {
2745                 /* Earth vault  (Rubble) */
2746                 type = LAKE_T_EARTH_VAULT;
2747         }
2748         else if (dun_level < 50)
2749         {
2750                 /* Air vault (Trees) */
2751                 type = LAKE_T_AIR_VAULT;
2752         }
2753         else if (dun_level < 75)
2754         {
2755                 /* Water vault (shallow water) */
2756                 type = LAKE_T_WATER_VAULT;
2757         }
2758         else
2759         {
2760                 /* Fire vault (shallow lava) */
2761                 type = LAKE_T_FIRE_VAULT;
2762         }
2763
2764         while (!done)
2765         {
2766                 /* testing values for these parameters: feel free to adjust */
2767                 grd = 1 << (randint0(3));
2768
2769                 /* want average of about 16 */
2770                 roug = randint1(8) * randint1(4);
2771
2772                 /* Make up size of various componants */
2773                 /* Floor */
2774                 c3 = 2 * xsize / 3;
2775
2776                 /* Deep water/lava */
2777                 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
2778
2779                 /* Shallow boundary */
2780                 c2 = (c1 + c3) / 2;
2781
2782                 /* make it */
2783                 generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
2784
2785                 /* Convert to normal format+ clean up */
2786                 done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
2787         }
2788
2789         /* Set icky flag because is a vault */
2790         for (x = 0; x <= xsize; x++)
2791         {
2792                 for (y = 0; y <= ysize; y++)
2793                 {
2794                         cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
2795                 }
2796         }
2797
2798         /* make a few rooms in the vault */
2799         for (i = 1; i <= (xsize * ysize) / 50; i++)
2800         {
2801                 build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
2802                                  y0 + randint0(ysize - 4) - ysize / 2 + 2);
2803         }
2804
2805         /* Fill with monsters and treasure, low difficulty */
2806         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
2807                       y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
2808 }
2809 #endif /* ALLOW_CAVERNS_AND_LAKES */
2810
2811
2812 /*!
2813  * @brief タイプ10の部屋…ランダム生成vault / Type 10 -- Random vaults
2814  * @return なし
2815  */
2816 static bool build_type10(void)
2817 {
2818         POSITION y0, x0, xsize, ysize, vtype;
2819
2820         /* Get size */
2821         /* big enough to look good, small enough to be fairly common. */
2822         xsize = randint1(22) + 22;
2823         ysize = randint1(11) + 11;
2824
2825         /* Find and reserve some space in the dungeon.  Get center of room. */
2826         if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
2827
2828         /* Select type of vault */
2829 #ifdef ALLOW_CAVERNS_AND_LAKES
2830         do
2831         {
2832                 vtype = randint1(15);
2833         }
2834         while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
2835                 ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11)));
2836 #else /* ALLOW_CAVERNS_AND_LAKES */
2837         do
2838         {
2839                 vtype = randint1(7);
2840         }
2841         while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
2842                 ((vtype == 1) || (vtype == 3)));
2843 #endif /* ALLOW_CAVERNS_AND_LAKES */
2844
2845         switch (vtype)
2846         {
2847                 /* Build an appropriate room */
2848                 case 1: case  9: build_bubble_vault(x0, y0, xsize, ysize); break;
2849                 case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
2850                 case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
2851                 case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
2852                 case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
2853                 case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
2854                 case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
2855 #ifdef ALLOW_CAVERNS_AND_LAKES
2856                 case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
2857 #endif /* ALLOW_CAVERNS_AND_LAKES */
2858                 /* I know how to add a few more... give me some time. */
2859
2860                 /* Paranoia */
2861                 default: return FALSE;
2862         }
2863
2864         return TRUE;
2865 }
2866
2867
2868
2869 /*!
2870  * @brief タイプ14の部屋…特殊トラップ部屋の生成 / Type 14 -- trapped rooms
2871  * @return なし
2872  * @details
2873  * A special trap is placed at center of the room
2874  */
2875 static bool build_type14(void)
2876 {
2877         POSITION y, x, y2, x2, yval, xval;
2878         POSITION y1, x1, xsize, ysize;
2879
2880         bool light;
2881
2882         cave_type *c_ptr;
2883         s16b trap;
2884
2885         /* Pick a room size */
2886         y1 = randint1(4);
2887         x1 = randint1(11);
2888         y2 = randint1(3);
2889         x2 = randint1(11);
2890
2891         xsize = x1 + x2 + 1;
2892         ysize = y1 + y2 + 1;
2893
2894         /* Find and reserve some space in the dungeon.  Get center of room. */
2895         if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
2896
2897         /* Choose lite or dark */
2898         light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
2899
2900
2901         /* Get corner values */
2902         y1 = yval - ysize / 2;
2903         x1 = xval - xsize / 2;
2904         y2 = yval + (ysize - 1) / 2;
2905         x2 = xval + (xsize - 1) / 2;
2906
2907
2908         /* Place a full floor under the room */
2909         for (y = y1 - 1; y <= y2 + 1; y++)
2910         {
2911                 for (x = x1 - 1; x <= x2 + 1; x++)
2912                 {
2913                         c_ptr = &cave[y][x];
2914                         place_floor_grid(c_ptr);
2915                         c_ptr->info |= (CAVE_ROOM);
2916                         if (light) c_ptr->info |= (CAVE_GLOW);
2917                 }
2918         }
2919
2920         /* Walls around the room */
2921         for (y = y1 - 1; y <= y2 + 1; y++)
2922         {
2923                 c_ptr = &cave[y][x1 - 1];
2924                 place_outer_grid(c_ptr);
2925                 c_ptr = &cave[y][x2 + 1];
2926                 place_outer_grid(c_ptr);
2927         }
2928         for (x = x1 - 1; x <= x2 + 1; x++)
2929         {
2930                 c_ptr = &cave[y1 - 1][x];
2931                 place_outer_grid(c_ptr);
2932                 c_ptr = &cave[y2 + 1][x];
2933                 place_outer_grid(c_ptr);
2934         }
2935
2936         if (dun_level < 30 + randint1(30))
2937                 trap = feat_trap_piranha;
2938         else
2939                 trap = feat_trap_armageddon;
2940
2941         /* Place a special trap */
2942         c_ptr = &cave[rand_spread(yval, ysize/4)][rand_spread(xval, xsize/4)];
2943         c_ptr->mimic = c_ptr->feat;
2944         c_ptr->feat = trap;
2945
2946         msg_format_wizard(CHEAT_DUNGEON, _("%sの部屋が生成されました。", "Room of %s was generated."), f_name + f_info[trap].name);
2947
2948         return TRUE;
2949 }
2950
2951
2952 /*
2953  * Helper function for "glass room"
2954  */
2955 static bool vault_aux_lite(MONRACE_IDX r_idx)
2956 {
2957         monster_race *r_ptr = &r_info[r_idx];
2958
2959         /* Validate the monster */
2960         if (!vault_monster_okay(r_idx)) return FALSE;
2961
2962         /* Require lite attack */
2963         if (!(r_ptr->flags4 & RF4_BR_LITE) && !(r_ptr->a_ability_flags1 & RF5_BA_LITE)) return FALSE;
2964
2965         /* No wall passing monsters */
2966         if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return FALSE;
2967
2968         /* No disintegrating monsters */
2969         if (r_ptr->flags4 & RF4_BR_DISI) return FALSE;
2970
2971         return TRUE;
2972 }
2973
2974 /*
2975  * Helper function for "glass room"
2976  */
2977 static bool vault_aux_shards(MONRACE_IDX r_idx)
2978 {
2979         monster_race *r_ptr = &r_info[r_idx];
2980
2981         /* Validate the monster */
2982         if (!vault_monster_okay(r_idx)) return FALSE;
2983
2984         /* Require shards breath attack */
2985         if (!(r_ptr->flags4 & RF4_BR_SHAR)) return FALSE;
2986
2987         return TRUE;
2988 }
2989
2990 /*
2991  * Hack -- determine if a template is potion
2992  */
2993 static bool kind_is_potion(KIND_OBJECT_IDX k_idx)
2994 {
2995         return k_info[k_idx].tval == TV_POTION;
2996 }
2997
2998 /*!
2999  * @brief タイプ15の部屋…ガラス部屋の生成 / Type 15 -- glass rooms
3000  * @return なし
3001  */
3002 static bool build_type15(void)
3003 {
3004         POSITION y, x, y2, x2, yval, xval;
3005         POSITION y1, x1, xsize, ysize;
3006         bool light;
3007
3008         cave_type *c_ptr;
3009
3010         /* Pick a room size */
3011         xsize = rand_range(9, 13);
3012         ysize = rand_range(9, 13);
3013
3014         /* Find and reserve some space in the dungeon.  Get center of room. */
3015         if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
3016
3017         /* Choose lite or dark */
3018         light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
3019
3020         /* Get corner values */
3021         y1 = yval - ysize / 2;
3022         x1 = xval - xsize / 2;
3023         y2 = yval + (ysize - 1) / 2;
3024         x2 = xval + (xsize - 1) / 2;
3025
3026         /* Place a full floor under the room */
3027         for (y = y1 - 1; y <= y2 + 1; y++)
3028         {
3029                 for (x = x1 - 1; x <= x2 + 1; x++)
3030                 {
3031                         c_ptr = &cave[y][x];
3032                         place_floor_grid(c_ptr);
3033                         c_ptr->feat = feat_glass_floor;
3034                         c_ptr->info |= (CAVE_ROOM);
3035                         if (light) c_ptr->info |= (CAVE_GLOW);
3036                 }
3037         }
3038
3039         /* Walls around the room */
3040         for (y = y1 - 1; y <= y2 + 1; y++)
3041         {
3042                 c_ptr = &cave[y][x1 - 1];
3043                 place_outer_grid(c_ptr);
3044                 c_ptr->feat = feat_glass_wall;
3045                 c_ptr = &cave[y][x2 + 1];
3046                 place_outer_grid(c_ptr);
3047                 c_ptr->feat = feat_glass_wall;
3048         }
3049         for (x = x1 - 1; x <= x2 + 1; x++)
3050         {
3051                 c_ptr = &cave[y1 - 1][x];
3052                 place_outer_grid(c_ptr);
3053                 c_ptr->feat = feat_glass_wall;
3054                 c_ptr = &cave[y2 + 1][x];
3055                 place_outer_grid(c_ptr);
3056                 c_ptr->feat = feat_glass_wall;
3057         }
3058
3059         switch (randint1(3))
3060         {
3061         case 1: /* 4 lite breathers + potion */
3062                 {
3063                         int dir1, dir2;
3064
3065                         /* Prepare allocation table */
3066                         get_mon_num_prep(vault_aux_lite, NULL);
3067
3068                         /* Place fixed lite berathers */
3069                         for (dir1 = 4; dir1 < 8; dir1++)
3070                         {
3071                                 MONRACE_IDX r_idx = get_mon_num(dun_level);
3072
3073                                 y = yval + 2 * ddy_ddd[dir1];
3074                                 x = xval + 2 * ddx_ddd[dir1];
3075                                 if (r_idx) place_monster_aux(0, y, x, r_idx, PM_ALLOW_SLEEP);
3076
3077                                 /* Walls around the breather */
3078                                 for (dir2 = 0; dir2 < 8; dir2++)
3079                                 {
3080                                         c_ptr = &cave[y + ddy_ddd[dir2]][x + ddx_ddd[dir2]];
3081                                         place_inner_grid(c_ptr);
3082                                         c_ptr->feat = feat_glass_wall;
3083                                 }
3084                         }
3085
3086                         /* Walls around the potion */
3087                         for (dir1 = 0; dir1 < 4; dir1++)
3088                         {
3089                                 y = yval + 2 * ddy_ddd[dir1];
3090                                 x = xval + 2 * ddx_ddd[dir1];
3091                                 c_ptr = &cave[y][x];
3092                                 place_inner_perm_grid(c_ptr);
3093                                 c_ptr->feat = feat_permanent_glass_wall;
3094                                 cave[yval + ddy_ddd[dir1]][xval + ddx_ddd[dir1]].info |= (CAVE_ICKY);
3095                         }
3096
3097                         /* Glass door */
3098                         dir1 = randint0(4);
3099                         y = yval + 2 * ddy_ddd[dir1];
3100                         x = xval + 2 * ddx_ddd[dir1];
3101                         place_secret_door(y, x, DOOR_GLASS_DOOR);
3102                         c_ptr = &cave[y][x];
3103                         if (is_closed_door(c_ptr->feat)) c_ptr->mimic = feat_glass_wall;
3104
3105                         /* Place a potion */
3106                         get_obj_num_hook = kind_is_potion;
3107                         place_object(yval, xval, AM_NO_FIXED_ART);
3108                         cave[yval][xval].info |= (CAVE_ICKY);
3109                 }
3110                 break;
3111
3112         case 2: /* 1 lite breather + random object */
3113                 {
3114                         MONRACE_IDX r_idx;
3115                         DIRECTION dir1;
3116
3117                         /* Pillars */
3118                         c_ptr = &cave[y1 + 1][x1 + 1];
3119                         place_inner_grid(c_ptr);
3120                         c_ptr->feat = feat_glass_wall;
3121
3122                         c_ptr = &cave[y1 + 1][x2 - 1];
3123                         place_inner_grid(c_ptr);
3124                         c_ptr->feat = feat_glass_wall;
3125
3126                         c_ptr = &cave[y2 - 1][x1 + 1];
3127                         place_inner_grid(c_ptr);
3128                         c_ptr->feat = feat_glass_wall;
3129
3130                         c_ptr = &cave[y2 - 1][x2 - 1];
3131                         place_inner_grid(c_ptr);
3132                         c_ptr->feat = feat_glass_wall;
3133
3134                         /* Prepare allocation table */
3135                         get_mon_num_prep(vault_aux_lite, NULL);
3136
3137                         r_idx = get_mon_num(dun_level);
3138                         if (r_idx) place_monster_aux(0, yval, xval, r_idx, 0L);
3139
3140                         /* Walls around the breather */
3141                         for (dir1 = 0; dir1 < 8; dir1++)
3142                         {
3143                                 c_ptr = &cave[yval + ddy_ddd[dir1]][xval + ddx_ddd[dir1]];
3144                                 place_inner_grid(c_ptr);
3145                                 c_ptr->feat = feat_glass_wall;
3146                         }
3147
3148                         /* Curtains around the breather */
3149                         for (y = yval - 1; y <= yval + 1; y++)
3150                         {
3151                                 place_closed_door(y, xval - 2, DOOR_CURTAIN);
3152                                 place_closed_door(y, xval + 2, DOOR_CURTAIN);
3153                         }
3154                         for (x = xval - 1; x <= xval + 1; x++)
3155                         {
3156                                 place_closed_door(yval - 2, x, DOOR_CURTAIN);
3157                                 place_closed_door(yval + 2, x, DOOR_CURTAIN);
3158                         }
3159
3160                         /* Place an object */
3161                         place_object(yval, xval, AM_NO_FIXED_ART);
3162                         cave[yval][xval].info |= (CAVE_ICKY);
3163                 }
3164                 break;
3165
3166         case 3: /* 4 shards breathers + 2 potions */
3167                 {
3168                         int dir1;
3169
3170                         /* Walls around the potion */
3171                         for (y = yval - 2; y <= yval + 2; y++)
3172                         {
3173                                 c_ptr = &cave[y][xval - 3];
3174                                 place_inner_grid(c_ptr);
3175                                 c_ptr->feat = feat_glass_wall;
3176                                 c_ptr = &cave[y][xval + 3];
3177                                 place_inner_grid(c_ptr);
3178                                 c_ptr->feat = feat_glass_wall;
3179                         }
3180                         for (x = xval - 2; x <= xval + 2; x++)
3181                         {
3182                                 c_ptr = &cave[yval - 3][x];
3183                                 place_inner_grid(c_ptr);
3184                                 c_ptr->feat = feat_glass_wall;
3185                                 c_ptr = &cave[yval + 3][x];
3186                                 place_inner_grid(c_ptr);
3187                                 c_ptr->feat = feat_glass_wall;
3188                         }
3189                         for (dir1 = 4; dir1 < 8; dir1++)
3190                         {
3191                                 c_ptr = &cave[yval + 2 * ddy_ddd[dir1]][xval + 2 * ddx_ddd[dir1]];
3192                                 place_inner_grid(c_ptr);
3193                                 c_ptr->feat = feat_glass_wall;
3194                         }
3195
3196                         /* Prepare allocation table */
3197                         get_mon_num_prep(vault_aux_shards, NULL);
3198
3199                         /* Place shard berathers */
3200                         for (dir1 = 4; dir1 < 8; dir1++)
3201                         {
3202                                 MONRACE_IDX r_idx = get_mon_num(dun_level);
3203
3204                                 y = yval + ddy_ddd[dir1];
3205                                 x = xval + ddx_ddd[dir1];
3206                                 if (r_idx) place_monster_aux(0, y, x, r_idx, 0L);
3207                         }
3208
3209                         /* Place two potions */
3210                         if (one_in_(2))
3211                         {
3212                                 get_obj_num_hook = kind_is_potion;
3213                                 place_object(yval, xval - 1, AM_NO_FIXED_ART);
3214                                 get_obj_num_hook = kind_is_potion;
3215                                 place_object(yval, xval + 1, AM_NO_FIXED_ART);
3216                         }
3217                         else
3218                         {
3219                                 get_obj_num_hook = kind_is_potion;
3220                                 place_object(yval - 1, xval, AM_NO_FIXED_ART);
3221                                 get_obj_num_hook = kind_is_potion;
3222                                 place_object(yval + 1, xval, AM_NO_FIXED_ART);
3223                         }
3224
3225                         for (y = yval - 2; y <= yval + 2; y++)
3226                                 for (x = xval - 2; x <= xval + 2; x++)
3227                                         cave[y][x].info |= (CAVE_ICKY);
3228
3229                 }
3230                 break;
3231         }
3232
3233         msg_print_wizard(CHEAT_DUNGEON, _("ガラスの部屋が生成されました。", "Glass room was generated."));
3234
3235         return TRUE;
3236 }
3237
3238
3239 /* Create a new floor room with optional light */
3240 void generate_room_floor(int y1, int x1, int y2, int x2, int light)
3241 {
3242         int y, x;
3243         
3244         cave_type *c_ptr;
3245
3246         for (y = y1; y <= y2; y++)
3247         {
3248                 for (x = x1; x <= x2; x++)
3249                 {
3250                         /* Point to grid */
3251                         c_ptr = &cave[y][x];
3252                         place_floor_grid(c_ptr);
3253                         c_ptr->info |= (CAVE_ROOM);
3254                         if (light) c_ptr->info |= (CAVE_GLOW);
3255                 }
3256         }
3257 }
3258
3259 void generate_fill_perm_bold(int y1, int x1, int y2, int x2)
3260 {
3261         int y, x;
3262
3263         for (y = y1; y <= y2; y++)
3264         {
3265                 for (x = x1; x <= x2; x++)
3266                 {
3267                         /* Point to grid */
3268                         place_inner_perm_bold(y, x);
3269                 }
3270         }
3271 }
3272
3273
3274 /*!
3275  * @brief 与えられた部屋型IDに応じて部屋の生成処理分岐を行い結果を返す / Attempt to build a room of the given type at the given block
3276  * @param type 部屋型ID
3277  * @note that we restrict the number of "crowded" rooms to reduce the chance of overflowing the monster list during level creation.
3278  * @return 部屋の精製に成功した場合 TRUE を返す。
3279  */
3280 static bool room_build(int typ)
3281 {
3282         /* Build a room */
3283         switch (typ)
3284         {
3285         /* Build an appropriate room */
3286         case ROOM_T_NORMAL:        return build_type1();
3287         case ROOM_T_OVERLAP:       return build_type2();
3288         case ROOM_T_CROSS:         return build_type3();
3289         case ROOM_T_INNER_FEAT:    return build_type4();
3290         case ROOM_T_NEST:          return build_type5();
3291         case ROOM_T_PIT:           return build_type6();
3292         case ROOM_T_LESSER_VAULT:  return build_type7();
3293         case ROOM_T_GREATER_VAULT: return build_type8();
3294         case ROOM_T_FRACAVE:       return build_type9();
3295         case ROOM_T_RANDOM_VAULT:  return build_type10();
3296         case ROOM_T_OVAL:          return build_type11();
3297         case ROOM_T_CRYPT:         return build_type12();
3298         case ROOM_T_TRAP_PIT:      return build_type13();
3299         case ROOM_T_TRAP:          return build_type14();
3300         case ROOM_T_GLASS:         return build_type15();
3301         case ROOM_T_ARCADE:        return build_type16();
3302         }
3303
3304         /* Paranoia */
3305         return FALSE;
3306 }
3307
3308 /*!
3309  * @brief 指定した部屋の生成確率を別の部屋に加算し、指定した部屋の生成率を0にする
3310  * @param dst 確率を移す先の部屋種ID
3311  * @param src 確率を与える元の部屋種ID
3312  */
3313 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0) 
3314
3315 /*!
3316  * @brief 部屋生成処理のメインルーチン(Sangbandを経由してOangbandからの実装を引用) / Generate rooms in dungeon.  Build bigger rooms at first. [from SAngband (originally from OAngband)]
3317  * @return 部屋生成に成功した場合 TRUE を返す。
3318  */
3319 bool generate_rooms(void)
3320 {
3321         int i;
3322         bool remain;
3323         int crowded = 0;
3324         int total_prob;
3325         int prob_list[ROOM_T_MAX];
3326         int rooms_built = 0;
3327         int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
3328         int level_index = MIN(10, div_round(dun_level, 10));
3329
3330         /* Number of each type of room on this level */
3331         s16b room_num[ROOM_T_MAX];
3332
3333         /* Limit number of rooms */
3334         int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
3335
3336         /* Assume normal cave */
3337         room_info_type *room_info_ptr = room_info_normal;
3338
3339         /*
3340          * Initialize probability list.
3341          */
3342         for (i = 0; i < ROOM_T_MAX; i++)
3343         {
3344                 /* No rooms allowed above their minimum depth. */
3345                 if (dun_level < room_info_ptr[i].min_level)
3346                 {
3347                         prob_list[i] = 0;
3348                 }
3349                 else
3350                 {
3351                         prob_list[i] = room_info_ptr[i].prob[level_index];
3352                 }
3353         }
3354
3355         /*
3356          * XXX -- Various dungeon types and options.
3357          */
3358
3359         /*! @details ダンジョンにBEGINNER、CHAMELEON、SMALLESTいずれのフラグもなく、かつ「常に通常でない部屋を生成する」フラグがONならば、GRATER_VAULTのみを生成対象とする。 / Ironman sees only Greater Vaults */
3360         if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
3361         {
3362                 for (i = 0; i < ROOM_T_MAX; i++)
3363                 {
3364                         if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
3365                         else prob_list[i] = 0;
3366                 }
3367         }
3368
3369         /*! @details ダンジョンにNO_VAULTフラグがあるならば、LESSER_VAULT / GREATER_VAULT/ RANDOM_VAULTを除外 / Forbidden vaults */
3370         else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
3371         {
3372                 prob_list[ROOM_T_LESSER_VAULT] = 0;
3373                 prob_list[ROOM_T_GREATER_VAULT] = 0;
3374                 prob_list[ROOM_T_RANDOM_VAULT] = 0;
3375         }
3376
3377         /*! @details ダンジョンにNO_CAVEフラグがある場合、FRACAVEの生成枠がNORMALに与えられる。CRIPT、OVALの生成枠がINNER_Fに与えられる。/ NO_CAVE dungeon (Castle)*/
3378         if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
3379         {
3380                 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
3381                 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
3382                 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
3383         }
3384
3385         /*! @details ダンジョンにCAVEフラグがある場合、NORMALの生成枠がFRACAVEに与えられる。/ CAVE dungeon (Orc cave etc.) */
3386         else if (d_info[dungeon_type].flags1 & DF1_CAVE)
3387         {
3388                 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
3389         }
3390
3391         /*! @details ダンジョンの基本地形が最初から渓谷かアリーナ型の場合 FRACAVE は生成から除外。 /  No caves when a (random) cavern exists: they look bad */
3392         else if (dun->cavern || dun->empty_level)
3393         {
3394                 prob_list[ROOM_T_FRACAVE] = 0;
3395         }
3396
3397         /*! @details ダンジョンに最初からGLASS_ROOMフラグがある場合、GLASS を生成から除外。/ Forbidden glass rooms */
3398         if (!(d_info[dungeon_type].flags1 & DF1_GLASS_ROOM))
3399         {
3400                 prob_list[ROOM_T_GLASS] = 0;
3401         }
3402
3403         /*! @details ARCADEは同フラグがダンジョンにないと生成されない。 / Forbidden glass rooms */
3404         if (!(d_info[dungeon_type].flags1 & DF1_ARCADE))
3405         {
3406                 prob_list[ROOM_T_ARCADE] = 0;
3407         }
3408
3409         /*
3410          * Initialize number of rooms,
3411          * And calcurate total probability.
3412          */
3413         for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
3414         {
3415                 room_num[i] = 0;
3416                 total_prob += prob_list[i];
3417         }
3418
3419         /*
3420          * Prepare the number of rooms, of all types, we should build
3421          * on this level.
3422          */
3423         for (i = dun_rooms; i > 0; i--)
3424         {
3425                 int room_type;
3426                 int rand = randint0(total_prob);
3427
3428                 /* Get room_type randomly */
3429                 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
3430                 {
3431                         if (rand < prob_list[room_type]) break;
3432                         else rand -= prob_list[room_type];
3433                 }
3434
3435                 /* Paranoia */
3436                 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
3437
3438                 /* Increase the number of rooms of that type we should build. */
3439                 room_num[room_type]++;
3440
3441                 switch (room_type)
3442                 {
3443                 case ROOM_T_NEST:
3444                 case ROOM_T_PIT:
3445                 case ROOM_T_LESSER_VAULT:
3446                 case ROOM_T_TRAP_PIT:
3447                 case ROOM_T_GLASS:
3448                 case ROOM_T_ARCADE:
3449
3450                         /* Large room */
3451                         i -= 2;
3452                         break;
3453
3454                 case ROOM_T_GREATER_VAULT:
3455                 case ROOM_T_RANDOM_VAULT:
3456
3457                         /* Largest room */
3458                         i -= 3;
3459                         break;
3460                 }
3461         }
3462
3463         /*
3464          * Build each type of room one by one until we cannot build any more.
3465          * [from SAngband (originally from OAngband)]
3466          */
3467         while (TRUE)
3468         {
3469                 /* Assume no remaining rooms */
3470                 remain = FALSE;
3471
3472                 for (i = 0; i < ROOM_T_MAX; i++)
3473                 {
3474                         /* What type of room are we building now? */
3475                         int room_type = room_build_order[i];
3476
3477                         /* Go next if none available */
3478                         if (!room_num[room_type]) continue;
3479
3480                         /* Use up one unit */
3481                         room_num[room_type]--;
3482
3483                         /* Build the room. */
3484                         if (room_build(room_type))
3485                         {
3486                                 /* Increase the room built count. */
3487                                 rooms_built++;
3488
3489                                 /* Mark as there was some remaining rooms */
3490                                 remain = TRUE;
3491
3492                                 switch (room_type)
3493                                 {
3494                                 case ROOM_T_PIT:
3495                                 case ROOM_T_NEST:
3496                                 case ROOM_T_TRAP_PIT:
3497
3498                                         /* Avoid too many monsters */
3499                                         if (++crowded >= 2)
3500                                         {
3501                                                 room_num[ROOM_T_PIT] = 0;
3502                                                 room_num[ROOM_T_NEST] = 0;
3503                                                 room_num[ROOM_T_TRAP_PIT] = 0;
3504                                         }
3505                                         break;
3506
3507                                 case ROOM_T_ARCADE:
3508
3509                                         /* Avoid double-town */
3510                                         room_num[ROOM_T_ARCADE] = 0;
3511                                         break;
3512                                 }
3513                         }
3514                 }
3515
3516                 /* End loop if no room remain */
3517                 if (!remain) break;
3518         }
3519
3520         /*! @details 部屋生成数が2未満の場合生成失敗を返す */
3521         if (rooms_built < 2)
3522         {
3523                 msg_format_wizard(CHEAT_DUNGEON, _("部屋数が2未満でした。生成を再試行します。", "Number of rooms was under 2. Retry."), rooms_built);
3524                 return FALSE;
3525         }
3526
3527         msg_format_wizard(CHEAT_DUNGEON, _("このダンジョンの部屋数は %d です。", "Number of Rooms: %d"), rooms_built);
3528
3529         return TRUE;
3530 }