OSDN Git Service

d847f35bb6a99593c803c376c3a5135deb1e1c41
[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
45 /*!
46  * 各部屋タイプの生成比定義
47  *[from SAngband (originally from OAngband)]\n
48  *\n
49  * Table of values that control how many times each type of room will\n
50  * appear.  Each type of room has its own row, and each column\n
51  * corresponds to dungeon levels 0, 10, 20, and so on.  The final\n
52  * value is the minimum depth the room can appear at.  -LM-\n
53  *\n
54  * Level 101 and below use the values for level 100.\n
55  *\n
56  * Rooms with lots of monsters or loot may not be generated if the\n
57  * object or monster lists are already nearly full.  Rooms will not\n
58  * appear above their minimum depth.  Tiny levels will not have space\n
59  * for all the rooms you ask for.\n
60  */
61 static room_info_type room_info_normal[ROOM_T_MAX] =
62 {
63         /* Depth */
64         /*  0  10  20  30  40  50  60  70  80  90 100  min limit */
65
66         {{999,900,800,700,600,500,400,300,200,100,  0},  0}, /*NORMAL   */
67         {{  1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100},  1}, /*OVERLAP  */
68         {{  1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100},  3}, /*CROSS    */
69         {{  1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100},  3}, /*INNER_F  */
70         {{  0,  1,  1,  1,  2,  3,  5,  6,  8, 10, 13}, 10}, /*NEST     */
71         {{  0,  1,  1,  2,  3,  4,  6,  8, 10, 13, 16}, 10}, /*PIT      */
72         {{  0,  1,  1,  1,  2,  2,  3,  5,  6,  8, 10}, 10}, /*LESSER_V */
73         {{  0,  0,  1,  1,  1,  2,  2,  2,  3,  3,  4}, 20}, /*GREATER_V*/
74         {{  0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE  */
75         {{  0,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2}, 10}, /*RANDOM_V */
76         {{  0,  4,  8, 12, 16, 20, 24, 28, 32, 36, 40},  3}, /*OVAL     */
77         {{  1,  6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT    */
78         {{  0,  0,  1,  1,  1,  2,  3,  4,  5,  6,  8}, 20}, /*TRAP_PIT */
79         {{  0,  0,  1,  1,  1,  2,  3,  4,  5,  6,  8}, 20}, /*TRAP     */
80         {{  0,  0,  0,  0,  1,  1,  1,  2,  2,  2,  2}, 40}, /*GLASS    */
81         {{  1,  1,  1,  1,  1,  1,  1,  2,  2,  3,  3},  1}, /*ARCADE   */
82 };
83
84
85 /*! 部屋の生成処理順 / Build rooms in descending order of difficulty. */
86 static byte room_build_order[ROOM_T_MAX] = {
87         ROOM_T_GREATER_VAULT,
88         ROOM_T_ARCADE,
89         ROOM_T_RANDOM_VAULT,
90         ROOM_T_LESSER_VAULT,
91         ROOM_T_TRAP_PIT,
92         ROOM_T_PIT,
93         ROOM_T_NEST,
94         ROOM_T_TRAP,
95         ROOM_T_GLASS,
96         ROOM_T_INNER_FEAT,
97         ROOM_T_OVAL,
98         ROOM_T_CRYPT,
99         ROOM_T_OVERLAP,
100         ROOM_T_CROSS,
101         ROOM_T_FRACAVE,
102         ROOM_T_NORMAL,
103 };
104
105 /*!
106  * @brief 鍵のかかったドアを配置する
107  * @param y 配置したいフロアのY座標
108  * @param x 配置したいフロアのX座標
109  * @return なし
110  */
111 static void place_locked_door(int y, int x)
112 {
113         if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
114         {
115                 place_floor_bold(y, x);
116         }
117         else
118         {
119                 set_cave_feat(y, x, feat_locked_door_random((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
120                 cave[y][x].info &= ~(CAVE_FLOOR);
121                 delete_monster(y, x);
122         }
123 }
124
125 /*!
126  * @brief 隠しドアを配置する
127  * @param y 配置したいフロアのY座標
128  * @param x 配置したいフロアのX座標
129  * @param type #DOOR_DEFAULT / #DOOR_DOOR / #DOOR_GLASS_DOOR / #DOOR_CURTAIN のいずれか
130  * @return なし
131  */
132 static void place_secret_door(int y, int x, int type)
133 {
134         if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
135         {
136                 place_floor_bold(y, x);
137         }
138         else
139         {
140                 cave_type *c_ptr = &cave[y][x];
141
142                 if (type == DOOR_DEFAULT)
143                 {
144                         type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
145                                 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
146                                 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
147                 }
148
149                 /* Create secret door */
150                 place_closed_door(y, x, type);
151
152                 if (type != DOOR_CURTAIN)
153                 {
154                         /* Hide by inner wall because this is used in rooms only */
155                         c_ptr->mimic = feat_wall_inner;
156
157                         /* Floor type terrain cannot hide a door */
158                         if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
159                         {
160                                 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
161                                 {
162                                         c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
163                                 }
164                                 c_ptr->mimic = 0;
165                         }
166                 }
167
168                 c_ptr->info &= ~(CAVE_FLOOR);
169                 delete_monster(y, x);
170         }
171 }
172
173 /*!
174  * @brief 1マスだけの部屋を作成し、上下左右いずれか一つに隠しドアを配置する。
175  * @param y0 配置したい中心のY座標
176  * @param x0 配置したい中心のX座標
177  * @details
178  * This funtion makes a very small room centred at (x0, y0)
179  * This is used in crypts, and random elemental vaults.
180  *
181  * Note - this should be used only on allocated regions
182  * within another room.
183  */
184 static void build_small_room(int x0, int y0)
185 {
186         int x, y;
187
188         for (y = y0 - 1; y <= y0 + 1; y++)
189         {
190                 place_inner_bold(y, x0 - 1);
191                 place_inner_bold(y, x0 + 1);
192         }
193
194         for (x = x0 - 1; x <= x0 + 1; x++)
195         {
196                 place_inner_bold(y0 - 1, x);
197                 place_inner_bold(y0 + 1, x);
198         }
199
200         /* Place a secret door on one side */
201         switch (randint0(4))
202         {
203                 case 0: place_secret_door(y0, x0 - 1, DOOR_DEFAULT); break;
204                 case 1: place_secret_door(y0, x0 + 1, DOOR_DEFAULT); break;
205                 case 2: place_secret_door(y0 - 1, x0, DOOR_DEFAULT); break;
206                 case 3: place_secret_door(y0 + 1, x0, DOOR_DEFAULT); break;
207         }
208
209         /* Clear mimic type */
210         cave[y0][x0].mimic = 0;
211
212         /* Add inner open space */
213         place_floor_bold(y0, x0);
214 }
215
216 /*!
217  * @brief
218  * 指定範囲に通路が通っていることを確認した上で床で埋める
219  * This function tunnels around a room if it will cut off part of a cave system.
220  * @param x1 範囲の左端
221  * @param y1 範囲の上端
222  * @param x2 範囲の右端
223  * @param y2 範囲の下端
224  * @return なし
225  */
226 static void check_room_boundary(int x1, int y1, int x2, int y2)
227 {
228         int count, x, y;
229         bool old_is_floor, new_is_floor;
230
231
232         /* Initialize */
233         count = 0;
234
235         old_is_floor = get_is_floor(x1 - 1, y1);
236
237         /*
238          * Count the number of floor-wall boundaries around the room
239          * Note: diagonal squares are ignored since the player can move diagonally
240          * to bypass these if needed.
241          */
242
243         /* Above the top boundary */
244         for (x = x1; x <= x2; x++)
245         {
246                 new_is_floor = get_is_floor(x, y1 - 1);
247
248                 /* Increment counter if they are different */
249                 if (new_is_floor != old_is_floor) count++;
250
251                 old_is_floor = new_is_floor;
252         }
253
254         /* Right boundary */
255         for (y = y1; y <= y2; y++)
256         {
257                 new_is_floor = get_is_floor(x2 + 1, y);
258
259                 /* increment counter if they are different */
260                 if (new_is_floor != old_is_floor) count++;
261
262                 old_is_floor = new_is_floor;
263         }
264
265         /* Bottom boundary */
266         for (x = x2; x >= x1; x--)
267         {
268                 new_is_floor = get_is_floor(x, y2 + 1);
269
270                 /* increment counter if they are different */
271                 if (new_is_floor != old_is_floor) count++;
272
273                 old_is_floor = new_is_floor;
274         }
275
276         /* Left boundary */
277         for (y = y2; y >= y1; y--)
278         {
279                 new_is_floor = get_is_floor(x1 - 1, y);
280
281                 /* increment counter if they are different */
282                 if (new_is_floor != old_is_floor) count++;
283
284                 old_is_floor = new_is_floor;
285         }
286
287         /* If all the same, or only one connection exit. */
288         if (count <= 2) return;
289
290
291         /* Tunnel around the room so to prevent problems with caves */
292         for (y = y1; y <= y2; y++)
293         {
294                 for (x = x1; x <= x2; x++)
295                 {
296                         set_floor(x, y);
297                 }
298         }
299 }
300
301
302 /*!
303  * @brief
304  * find_space()の予備処理として部屋の生成が可能かを判定する /
305  * Helper function for find_space(). Is this a good location?
306  * @param blocks_high 範囲の高さ
307  * @param blocks_wide 範囲の幅
308  * @param block_y 範囲の上端
309  * @param block_x 範囲の左端
310  * @return なし
311  */
312 static bool find_space_aux(int blocks_high, int blocks_wide, int block_y, int block_x)
313 {
314         int by1, bx1, by2, bx2, by, bx;
315
316         /* Itty-bitty rooms must shift about within their rectangle */
317         if (blocks_wide < 3)
318         {
319                 if ((blocks_wide == 2) && (block_x % 3) == 2)
320                         return FALSE;
321         }
322
323         /* Rooms with width divisible by 3 must be fitted to a rectangle. */
324         else if ((blocks_wide % 3) == 0)
325         {
326                 /* Must be aligned to the left edge of a 11x33 rectangle. */
327                 if ((block_x % 3) != 0)
328                         return FALSE;
329         }
330
331         /*
332          * Big rooms that do not have a width divisible by 3 must be
333          * aligned towards the edge of the dungeon closest to them.
334          */
335         else
336         {
337                 /* Shift towards left edge of dungeon. */
338                 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
339                 {
340                         if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
341                                 return FALSE;
342                         if ((block_x % 3) == 1)
343                                 return FALSE;
344                 }
345
346                 /* Shift toward right edge of dungeon. */
347                 else
348                 {
349                         if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
350                                 return FALSE;
351                         if ((block_x % 3) == 1)
352                                 return FALSE;
353                 }
354         }
355
356         /* Extract blocks */
357         by1 = block_y + 0;
358         bx1 = block_x + 0;
359         by2 = block_y + blocks_high;
360         bx2 = block_x + blocks_wide;
361
362         /* Never run off the screen */
363         if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
364         if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
365         
366         /* Verify available space */
367         for (by = by1; by < by2; by++)
368         {
369                 for (bx = bx1; bx < bx2; bx++)
370                 {
371                         if (dun->room_map[by][bx])
372                         {
373                                 return FALSE;
374                         }
375                 }
376         }
377
378         /* This location is okay */
379         return TRUE;
380 }
381
382
383 /*!
384  * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room.  -LM-
385  * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
386  * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
387  * @param height 確保したい領域の高さ
388  * @param width 確保したい領域の幅
389  * @return 所定の範囲が確保できた場合TRUEを返す
390  * @details
391  * Find and allocate a free space in the dungeon large enough to hold\n
392  * the room calling this function.\n
393  *\n
394  * We allocate space in 11x11 blocks, but want to make sure that rooms\n
395  * align neatly on the standard screen.  Therefore, we make them use\n
396  * blocks in few 11x33 rectangles as possible.\n
397  *\n
398  * Be careful to include the edges of the room in height and width!\n
399  *\n
400  * Return TRUE and values for the center of the room if all went well.\n
401  * Otherwise, return FALSE.\n
402  */
403 static bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
404 {
405         int candidates, pick;
406         int by, bx, by1, bx1, by2, bx2;
407         int block_y = 0, block_x = 0;
408
409
410         /* Find out how many blocks we need. */
411         int blocks_high = 1 + ((height - 1) / BLOCK_HGT);
412         int blocks_wide = 1 + ((width - 1) / BLOCK_WID);
413
414         /* There are no way to allocate such huge space */
415         if (dun->row_rooms < blocks_high) return FALSE;
416         if (dun->col_rooms < blocks_wide) return FALSE;
417
418         /* Initiallize */
419         candidates = 0;
420
421         /* Count the number of valid places */
422         for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
423         {
424                 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
425                 {
426                         if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
427                         {
428                                 /* Find a valid place */
429                                 candidates++;
430                         }
431                 }
432         }
433
434         /* No place! */
435         if (!candidates)
436         {
437                 return FALSE;
438         }
439
440         /* Normal dungeon */
441         if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
442         {
443                 /* Choose a random one */
444                 pick = randint1(candidates);
445         }
446
447         /* NO_CAVE dungeon (Castle) */
448         else
449         {
450                 /* Always choose the center one */
451                 pick = candidates/2 + 1;
452         }
453
454         /* Pick up the choosen location */
455         for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
456         {
457                 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
458                 {
459                         if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
460                         {
461                                 pick--;
462
463                                 /* This one is picked? */
464                                 if (!pick) break;
465                         }
466                 }
467
468                 if (!pick) break;
469         }
470
471         /* Extract blocks */
472         by1 = block_y + 0;
473         bx1 = block_x + 0;
474         by2 = block_y + blocks_high;
475         bx2 = block_x + blocks_wide;
476
477         /*
478          * It is *extremely* important that the following calculation
479          * be *exactly* correct to prevent memory errors
480          */
481
482         /* Acquire the location of the room */
483         (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
484         (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
485
486         /* Save the room location */
487         if (dun->cent_n < CENT_MAX)
488         {
489                 dun->cent[dun->cent_n].y = (byte_hack)*y;
490                 dun->cent[dun->cent_n].x = (byte_hack)*x;
491                 dun->cent_n++;
492         }
493
494         /* Reserve some blocks. */
495         for (by = by1; by < by2; by++)
496         {
497                 for (bx = bx1; bx < bx2; bx++)
498                 {
499                         dun->room_map[by][bx] = TRUE;
500                 }
501         }
502
503
504         /*
505          * Hack- See if room will cut off a cavern.
506          *
507          * If so, fix by tunneling outside the room in such a
508          * way as to connect the caves.
509          */
510         check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
511
512
513         /* Success. */
514         return TRUE;
515 }
516
517
518 /*!
519  * @brief タイプ1の部屋…通常可変長方形の部屋を生成する / Type 1 -- normal rectangular rooms
520  * @return なし
521  */
522 static bool build_type1(void)
523 {
524         POSITION y, x, y2, x2, yval, xval;
525         POSITION y1, x1, xsize, ysize;
526
527         bool light;
528
529         cave_type *c_ptr;
530
531         bool curtain = (d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
532                 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 48 : 512);
533
534         /* Pick a room size */
535         y1 = randint1(4);
536         x1 = randint1(11);
537         y2 = randint1(3);
538         x2 = randint1(11);
539
540         xsize = x1 + x2 + 1;
541         ysize = y1 + y2 + 1;
542
543         /* Find and reserve some space in the dungeon.  Get center of room. */
544         if (!find_space(&yval, &xval, ysize + 2, xsize + 2))
545         {
546                 /* Limit to the minimum room size, and retry */
547                 y1 = 1;
548                 x1 = 1;
549                 y2 = 1;
550                 x2 = 1;
551
552                 xsize = x1 + x2 + 1;
553                 ysize = y1 + y2 + 1;
554
555                 /* Find and reserve some space in the dungeon.  Get center of room. */
556                 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
557         }
558
559         /* Choose lite or dark */
560         light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
561
562
563         /* Get corner values */
564         y1 = yval - ysize / 2;
565         x1 = xval - xsize / 2;
566         y2 = yval + (ysize - 1) / 2;
567         x2 = xval + (xsize - 1) / 2;
568
569
570         /* Place a full floor under the room */
571         for (y = y1 - 1; y <= y2 + 1; y++)
572         {
573                 for (x = x1 - 1; x <= x2 + 1; x++)
574                 {
575                         c_ptr = &cave[y][x];
576                         place_floor_grid(c_ptr);
577                         c_ptr->info |= (CAVE_ROOM);
578                         if (light) c_ptr->info |= (CAVE_GLOW);
579                 }
580         }
581
582         /* Walls around the room */
583         for (y = y1 - 1; y <= y2 + 1; y++)
584         {
585                 c_ptr = &cave[y][x1 - 1];
586                 place_outer_grid(c_ptr);
587                 c_ptr = &cave[y][x2 + 1];
588                 place_outer_grid(c_ptr);
589         }
590         for (x = x1 - 1; x <= x2 + 1; x++)
591         {
592                 c_ptr = &cave[y1 - 1][x];
593                 place_outer_grid(c_ptr);
594                 c_ptr = &cave[y2 + 1][x];
595                 place_outer_grid(c_ptr);
596         }
597
598
599         /* Hack -- Occasional curtained room */
600         if (curtain && (y2 - y1 > 2) && (x2 - x1 > 2))
601         {
602                 for (y = y1; y <= y2; y++)
603                 {
604                         c_ptr = &cave[y][x1];
605                         c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
606                         c_ptr->info &= ~(CAVE_MASK);
607                         c_ptr = &cave[y][x2];
608                         c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
609                         c_ptr->info &= ~(CAVE_MASK);
610                 }
611                 for (x = x1; x <= x2; x++)
612                 {
613                         c_ptr = &cave[y1][x];
614                         c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
615                         c_ptr->info &= ~(CAVE_MASK);
616                         c_ptr = &cave[y2][x];
617                         c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
618                         c_ptr->info &= ~(CAVE_MASK);
619                 }
620         }
621
622
623         /* Hack -- Occasional pillar room */
624         if (one_in_(20))
625         {
626                 for (y = y1; y <= y2; y += 2)
627                 {
628                         for (x = x1; x <= x2; x += 2)
629                         {
630                                 c_ptr = &cave[y][x];
631                                 place_inner_grid(c_ptr);
632                         }
633                 }
634         }
635
636         /* Hack -- Occasional room with four pillars */
637         else if (one_in_(20))
638         {
639                 if ((y1 + 4 < y2) && (x1 + 4 < x2))
640                 {
641                         c_ptr = &cave[y1 + 1][x1 + 1];
642                         place_inner_grid(c_ptr);
643
644                         c_ptr = &cave[y1 + 1][x2 - 1];
645                         place_inner_grid(c_ptr);
646
647                         c_ptr = &cave[y2 - 1][x1 + 1];
648                         place_inner_grid(c_ptr);
649
650                         c_ptr = &cave[y2 - 1][x2 - 1];
651                         place_inner_grid(c_ptr);
652                 }
653         }
654
655         /* Hack -- Occasional ragged-edge room */
656         else if (one_in_(50))
657         {
658                 for (y = y1 + 2; y <= y2 - 2; y += 2)
659                 {
660                         c_ptr = &cave[y][x1];
661                         place_inner_grid(c_ptr);
662                         c_ptr = &cave[y][x2];
663                         place_inner_grid(c_ptr);
664                 }
665                 for (x = x1 + 2; x <= x2 - 2; x += 2)
666                 {
667                         c_ptr = &cave[y1][x];
668                         place_inner_grid(c_ptr);
669                         c_ptr = &cave[y2][x];
670                         place_inner_grid(c_ptr);
671                 }
672         }
673         /* Hack -- Occasional divided room */
674         else if (one_in_(50))
675         {
676                 bool curtain2 = (d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
677                         one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 2 : 128);
678
679                 if (randint1(100) < 50)
680                 {
681                         /* Horizontal wall */
682                         for (x = x1; x <= x2; x++)
683                         {
684                                 place_inner_bold(yval, x);
685                                 if (curtain2) cave[yval][x].feat = feat_door[DOOR_CURTAIN].closed;
686                         }
687
688                         /* Prevent edge of wall from being tunneled */
689                         place_solid_bold(yval, x1 - 1);
690                         place_solid_bold(yval, x2 + 1);
691                 }
692                 else
693                 {
694                         /* Vertical wall */
695                         for (y = y1; y <= y2; y++)
696                         {
697                                 place_inner_bold(y, xval);
698                                 if (curtain2) cave[y][xval].feat = feat_door[DOOR_CURTAIN].closed;
699                         }
700
701                         /* Prevent edge of wall from being tunneled */
702                         place_solid_bold(y1 - 1, xval);
703                         place_solid_bold(y2 + 1, xval);
704                 }
705
706                 place_random_door(yval, xval, TRUE);
707                 if (curtain2) cave[yval][xval].feat = feat_door[DOOR_CURTAIN].closed;
708         }
709
710         return TRUE;
711 }
712
713 /*!
714  * @brief タイプ2の部屋…二重長方形の部屋を生成する / Type 2 -- Overlapping rectangular rooms
715  * @return なし
716  */
717 static bool build_type2(void)
718 {
719         POSITION        y, x, xval, yval;
720         POSITION        y1a, x1a, y2a, x2a;
721         POSITION        y1b, x1b, y2b, x2b;
722         bool            light;
723         cave_type   *c_ptr;
724
725         /* Find and reserve some space in the dungeon.  Get center of room. */
726         if (!find_space(&yval, &xval, 11, 25)) return FALSE;
727
728         /* Choose lite or dark */
729         light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
730
731         /* Determine extents of the first room */
732         y1a = yval - randint1(4);
733         y2a = yval + randint1(3);
734         x1a = xval - randint1(11);
735         x2a = xval + randint1(10);
736
737         /* Determine extents of the second room */
738         y1b = yval - randint1(3);
739         y2b = yval + randint1(4);
740         x1b = xval - randint1(10);
741         x2b = xval + randint1(11);
742
743
744         /* Place a full floor for room "a" */
745         for (y = y1a - 1; y <= y2a + 1; y++)
746         {
747                 for (x = x1a - 1; x <= x2a + 1; x++)
748                 {
749                         c_ptr = &cave[y][x];
750                         place_floor_grid(c_ptr);
751                         c_ptr->info |= (CAVE_ROOM);
752                         if (light) c_ptr->info |= (CAVE_GLOW);
753                 }
754         }
755
756         /* Place a full floor for room "b" */
757         for (y = y1b - 1; y <= y2b + 1; y++)
758         {
759                 for (x = x1b - 1; x <= x2b + 1; x++)
760                 {
761                         c_ptr = &cave[y][x];
762                         place_floor_grid(c_ptr);
763                         c_ptr->info |= (CAVE_ROOM);
764                         if (light) c_ptr->info |= (CAVE_GLOW);
765                 }
766         }
767
768
769         /* Place the walls around room "a" */
770         for (y = y1a - 1; y <= y2a + 1; y++)
771         {
772                 c_ptr = &cave[y][x1a - 1];
773                 place_outer_grid(c_ptr);
774                 c_ptr = &cave[y][x2a + 1];
775                 place_outer_grid(c_ptr);
776         }
777         for (x = x1a - 1; x <= x2a + 1; x++)
778         {
779                 c_ptr = &cave[y1a - 1][x];
780                 place_outer_grid(c_ptr);
781                 c_ptr = &cave[y2a + 1][x];
782                 place_outer_grid(c_ptr);
783         }
784
785         /* Place the walls around room "b" */
786         for (y = y1b - 1; y <= y2b + 1; y++)
787         {
788                 c_ptr = &cave[y][x1b - 1];
789                 place_outer_grid(c_ptr);
790                 c_ptr = &cave[y][x2b + 1];
791                 place_outer_grid(c_ptr);
792         }
793         for (x = x1b - 1; x <= x2b + 1; x++)
794         {
795                 c_ptr = &cave[y1b - 1][x];
796                 place_outer_grid(c_ptr);
797                 c_ptr = &cave[y2b + 1][x];
798                 place_outer_grid(c_ptr);
799         }
800
801
802
803         /* Replace the floor for room "a" */
804         for (y = y1a; y <= y2a; y++)
805         {
806                 for (x = x1a; x <= x2a; x++)
807                 {
808                         c_ptr = &cave[y][x];
809                         place_floor_grid(c_ptr);
810                 }
811         }
812
813         /* Replace the floor for room "b" */
814         for (y = y1b; y <= y2b; y++)
815         {
816                 for (x = x1b; x <= x2b; x++)
817                 {
818                         c_ptr = &cave[y][x];
819                         place_floor_grid(c_ptr);
820                 }
821         }
822
823         return TRUE;
824 }
825
826
827
828 /*!
829  * @brief タイプ2の部屋…十字型の部屋を生成する / Type 3 -- Cross shaped rooms
830  * @return なし
831  * @details
832  * Builds a room at a row, column coordinate\n
833  *\n
834  * Room "a" runs north/south, and Room "b" runs east/east\n
835  * So the "central pillar" runs from x1a, y1b to x2a, y2b.\n
836  *\n
837  * Note that currently, the "center" is always 3x3, but I think that\n
838  * the code below will work (with "bounds checking") for 5x5, or even\n
839  * for unsymetric values like 4x3 or 5x3 or 3x4 or 3x5, or even larger.\n
840  */
841 static bool build_type3(void)
842 {
843         POSITION y, x, dy, dx, wy, wx;
844         POSITION y1a, x1a, y2a, x2a;
845         POSITION y1b, x1b, y2b, x2b;
846         POSITION yval, xval;
847         bool            light;
848         cave_type   *c_ptr;
849
850
851         /* Find and reserve some space in the dungeon.  Get center of room. */
852         if (!find_space(&yval, &xval, 11, 25)) return FALSE;
853
854
855         /* Choose lite or dark */
856         light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
857
858         /* For now, always 3x3 */
859         wx = wy = 1;
860
861         /* Pick max vertical size (at most 4) */
862         dy = rand_range(3, 4);
863
864         /* Pick max horizontal size (at most 15) */
865         dx = rand_range(3, 11);
866
867
868         /* Determine extents of the north/south room */
869         y1a = yval - dy;
870         y2a = yval + dy;
871         x1a = xval - wx;
872         x2a = xval + wx;
873
874         /* Determine extents of the east/west room */
875         y1b = yval - wy;
876         y2b = yval + wy;
877         x1b = xval - dx;
878         x2b = xval + dx;
879
880
881         /* Place a full floor for room "a" */
882         for (y = y1a - 1; y <= y2a + 1; y++)
883         {
884                 for (x = x1a - 1; x <= x2a + 1; x++)
885                 {
886                         c_ptr = &cave[y][x];
887                         place_floor_grid(c_ptr);
888                         c_ptr->info |= (CAVE_ROOM);
889                         if (light) c_ptr->info |= (CAVE_GLOW);
890                 }
891         }
892
893         /* Place a full floor for room "b" */
894         for (y = y1b - 1; y <= y2b + 1; y++)
895         {
896                 for (x = x1b - 1; x <= x2b + 1; x++)
897                 {
898                         c_ptr = &cave[y][x];
899                         place_floor_grid(c_ptr);
900                         c_ptr->info |= (CAVE_ROOM);
901                         if (light) c_ptr->info |= (CAVE_GLOW);
902                 }
903         }
904
905
906         /* Place the walls around room "a" */
907         for (y = y1a - 1; y <= y2a + 1; y++)
908         {
909                 c_ptr = &cave[y][x1a - 1];
910                 place_outer_grid(c_ptr);
911                 c_ptr = &cave[y][x2a + 1];
912                 place_outer_grid(c_ptr);
913         }
914         for (x = x1a - 1; x <= x2a + 1; x++)
915         {
916                 c_ptr = &cave[y1a - 1][x];
917                 place_outer_grid(c_ptr);
918                 c_ptr = &cave[y2a + 1][x];
919                 place_outer_grid(c_ptr);
920         }
921
922         /* Place the walls around room "b" */
923         for (y = y1b - 1; y <= y2b + 1; y++)
924         {
925                 c_ptr = &cave[y][x1b - 1];
926                 place_outer_grid(c_ptr);
927                 c_ptr = &cave[y][x2b + 1];
928                 place_outer_grid(c_ptr);
929         }
930         for (x = x1b - 1; x <= x2b + 1; x++)
931         {
932                 c_ptr = &cave[y1b - 1][x];
933                 place_outer_grid(c_ptr);
934                 c_ptr = &cave[y2b + 1][x];
935                 place_outer_grid(c_ptr);
936         }
937
938
939         /* Replace the floor for room "a" */
940         for (y = y1a; y <= y2a; y++)
941         {
942                 for (x = x1a; x <= x2a; x++)
943                 {
944                         c_ptr = &cave[y][x];
945                         place_floor_grid(c_ptr);
946                 }
947         }
948
949         /* Replace the floor for room "b" */
950         for (y = y1b; y <= y2b; y++)
951         {
952                 for (x = x1b; x <= x2b; x++)
953                 {
954                         c_ptr = &cave[y][x];
955                         place_floor_grid(c_ptr);
956                 }
957         }
958
959
960
961         /* Special features (3/4) */
962         switch (randint0(4))
963         {
964                 /* Large solid middle pillar */
965                 case 1:
966                 {
967                         for (y = y1b; y <= y2b; y++)
968                         {
969                                 for (x = x1a; x <= x2a; x++)
970                                 {
971                                         c_ptr = &cave[y][x];
972                                         place_inner_grid(c_ptr);
973                                 }
974                         }
975                         break;
976                 }
977
978                 /* Inner treasure vault */
979                 case 2:
980                 {
981                         /* Build the vault */
982                         for (y = y1b; y <= y2b; y++)
983                         {
984                                 c_ptr = &cave[y][x1a];
985                                 place_inner_grid(c_ptr);
986                                 c_ptr = &cave[y][x2a];
987                                 place_inner_grid(c_ptr);
988                         }
989                         for (x = x1a; x <= x2a; x++)
990                         {
991                                 c_ptr = &cave[y1b][x];
992                                 place_inner_grid(c_ptr);
993                                 c_ptr = &cave[y2b][x];
994                                 place_inner_grid(c_ptr);
995                         }
996
997                         /* Place a secret door on the inner room */
998                         switch (randint0(4))
999                         {
1000                                 case 0: place_secret_door(y1b, xval, DOOR_DEFAULT); break;
1001                                 case 1: place_secret_door(y2b, xval, DOOR_DEFAULT); break;
1002                                 case 2: place_secret_door(yval, x1a, DOOR_DEFAULT); break;
1003                                 case 3: place_secret_door(yval, x2a, DOOR_DEFAULT); break;
1004                         }
1005
1006                         /* Place a treasure in the vault */
1007                         place_object(yval, xval, 0L);
1008
1009                         /* Let's guard the treasure well */
1010                         vault_monsters(yval, xval, randint0(2) + 3);
1011
1012                         /* Traps naturally */
1013                         vault_traps(yval, xval, 4, 4, randint0(3) + 2);
1014
1015                         break;
1016                 }
1017
1018                 /* Something else */
1019                 case 3:
1020                 {
1021                         /* Occasionally pinch the center shut */
1022                         if (one_in_(3))
1023                         {
1024                                 /* Pinch the east/west sides */
1025                                 for (y = y1b; y <= y2b; y++)
1026                                 {
1027                                         if (y == yval) continue;
1028                                         c_ptr = &cave[y][x1a - 1];
1029                                         place_inner_grid(c_ptr);
1030                                         c_ptr = &cave[y][x2a + 1];
1031                                         place_inner_grid(c_ptr);
1032                                 }
1033
1034                                 /* Pinch the north/south sides */
1035                                 for (x = x1a; x <= x2a; x++)
1036                                 {
1037                                         if (x == xval) continue;
1038                                         c_ptr = &cave[y1b - 1][x];
1039                                         place_inner_grid(c_ptr);
1040                                         c_ptr = &cave[y2b + 1][x];
1041                                         place_inner_grid(c_ptr);
1042                                 }
1043
1044                                 /* Sometimes shut using secret doors */
1045                                 if (one_in_(3))
1046                                 {
1047                                         int door_type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
1048                                                 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
1049                                                 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
1050
1051                                         place_secret_door(yval, x1a - 1, door_type);
1052                                         place_secret_door(yval, x2a + 1, door_type);
1053                                         place_secret_door(y1b - 1, xval, door_type);
1054                                         place_secret_door(y2b + 1, xval, door_type);
1055                                 }
1056                         }
1057
1058                         /* Occasionally put a "plus" in the center */
1059                         else if (one_in_(3))
1060                         {
1061                                 c_ptr = &cave[yval][xval];
1062                                 place_inner_grid(c_ptr);
1063                                 c_ptr = &cave[y1b][xval];
1064                                 place_inner_grid(c_ptr);
1065                                 c_ptr = &cave[y2b][xval];
1066                                 place_inner_grid(c_ptr);
1067                                 c_ptr = &cave[yval][x1a];
1068                                 place_inner_grid(c_ptr);
1069                                 c_ptr = &cave[yval][x2a];
1070                                 place_inner_grid(c_ptr);
1071                         }
1072
1073                         /* Occasionally put a pillar in the center */
1074                         else if (one_in_(3))
1075                         {
1076                                 c_ptr = &cave[yval][xval];
1077                                 place_inner_grid(c_ptr);
1078                         }
1079
1080                         break;
1081                 }
1082         }
1083
1084         return TRUE;
1085 }
1086
1087
1088 /*!
1089  * @brief タイプ4の部屋…固定サイズの二重構造部屋を生成する / Type 4 -- Large room with inner features
1090  * @return なし
1091  * @details
1092  * Possible sub-types:\n
1093  *      1 - Just an inner room with one door\n
1094  *      2 - An inner room within an inner room\n
1095  *      3 - An inner room with pillar(s)\n
1096  *      4 - Inner room has a maze\n
1097  *      5 - A set of four inner rooms\n
1098  */
1099 static bool build_type4(void)
1100 {
1101         POSITION y, x, y1, x1;
1102         POSITION y2, x2, tmp, yval, xval;
1103         bool        light;
1104         cave_type   *c_ptr;
1105
1106
1107         /* Find and reserve some space in the dungeon.  Get center of room. */
1108         if (!find_space(&yval, &xval, 11, 25)) return FALSE;
1109
1110         /* Choose lite or dark */
1111         light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
1112
1113         /* Large room */
1114         y1 = yval - 4;
1115         y2 = yval + 4;
1116         x1 = xval - 11;
1117         x2 = xval + 11;
1118
1119         /* Place a full floor under the room */
1120         for (y = y1 - 1; y <= y2 + 1; y++)
1121         {
1122                 for (x = x1 - 1; x <= x2 + 1; x++)
1123                 {
1124                         c_ptr = &cave[y][x];
1125                         place_floor_grid(c_ptr);
1126                         c_ptr->info |= (CAVE_ROOM);
1127                         if (light) c_ptr->info |= (CAVE_GLOW);
1128                 }
1129         }
1130
1131         /* Outer Walls */
1132         for (y = y1 - 1; y <= y2 + 1; y++)
1133         {
1134                 c_ptr = &cave[y][x1 - 1];
1135                 place_outer_grid(c_ptr);
1136                 c_ptr = &cave[y][x2 + 1];
1137                 place_outer_grid(c_ptr);
1138         }
1139         for (x = x1 - 1; x <= x2 + 1; x++)
1140         {
1141                 c_ptr = &cave[y1 - 1][x];
1142                 place_outer_grid(c_ptr);
1143                 c_ptr = &cave[y2 + 1][x];
1144                 place_outer_grid(c_ptr);
1145         }
1146
1147
1148         /* The inner room */
1149         y1 = y1 + 2;
1150         y2 = y2 - 2;
1151         x1 = x1 + 2;
1152         x2 = x2 - 2;
1153
1154         /* The inner walls */
1155         for (y = y1 - 1; y <= y2 + 1; y++)
1156         {
1157                 c_ptr = &cave[y][x1 - 1];
1158                 place_inner_grid(c_ptr);
1159                 c_ptr = &cave[y][x2 + 1];
1160                 place_inner_grid(c_ptr);
1161         }
1162         for (x = x1 - 1; x <= x2 + 1; x++)
1163         {
1164                 c_ptr = &cave[y1 - 1][x];
1165                 place_inner_grid(c_ptr);
1166                 c_ptr = &cave[y2 + 1][x];
1167                 place_inner_grid(c_ptr);
1168         }
1169
1170
1171         /* Inner room variations */
1172         switch (randint1(5))
1173         {
1174                 /* Just an inner room with a monster */
1175                 case 1:
1176                 {
1177                         /* Place a secret door */
1178                         switch (randint1(4))
1179                         {
1180                                 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
1181                                 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
1182                                 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
1183                                 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
1184                         }
1185
1186                         /* Place a monster in the room */
1187                         vault_monsters(yval, xval, 1);
1188
1189                         break;
1190                 }
1191
1192                 /* Treasure Vault (with a door) */
1193                 case 2:
1194                 {
1195                         /* Place a secret door */
1196                         switch (randint1(4))
1197                         {
1198                                 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
1199                                 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
1200                                 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
1201                                 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
1202                         }
1203
1204                         /* Place another inner room */
1205                         for (y = yval - 1; y <= yval + 1; y++)
1206                         {
1207                                 for (x = xval -  1; x <= xval + 1; x++)
1208                                 {
1209                                         if ((x == xval) && (y == yval)) continue;
1210                                         c_ptr = &cave[y][x];
1211                                         place_inner_grid(c_ptr);
1212                                 }
1213                         }
1214
1215                         /* Place a locked door on the inner room */
1216                         switch (randint1(4))
1217                         {
1218                                 case 1: place_locked_door(yval - 1, xval); break;
1219                                 case 2: place_locked_door(yval + 1, xval); break;
1220                                 case 3: place_locked_door(yval, xval - 1); break;
1221                                 case 4: place_locked_door(yval, xval + 1); break;
1222                         }
1223
1224                         /* Monsters to guard the "treasure" */
1225                         vault_monsters(yval, xval, randint1(3) + 2);
1226
1227                         /* Object (80%) */
1228                         if (randint0(100) < 80)
1229                         {
1230                                 place_object(yval, xval, 0L);
1231                         }
1232
1233                         /* Stairs (20%) */
1234                         else
1235                         {
1236                                 place_random_stairs(yval, xval);
1237                         }
1238
1239                         /* Traps to protect the treasure */
1240                         vault_traps(yval, xval, 4, 10, 2 + randint1(3));
1241
1242                         break;
1243                 }
1244
1245                 /* Inner pillar(s). */
1246                 case 3:
1247                 {
1248                         /* Place a secret door */
1249                         switch (randint1(4))
1250                         {
1251                                 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
1252                                 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
1253                                 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
1254                                 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
1255                         }
1256
1257                         /* Large Inner Pillar */
1258                         for (y = yval - 1; y <= yval + 1; y++)
1259                         {
1260                                 for (x = xval - 1; x <= xval + 1; x++)
1261                                 {
1262                                 c_ptr = &cave[y][x];
1263                                 place_inner_grid(c_ptr);
1264                                 }
1265                         }
1266
1267                         /* Occasionally, two more Large Inner Pillars */
1268                         if (one_in_(2))
1269                         {
1270                                 tmp = randint1(2);
1271                                 for (y = yval - 1; y <= yval + 1; y++)
1272                                 {
1273                                         for (x = xval - 5 - tmp; x <= xval - 3 - tmp; x++)
1274                                         {
1275                                         c_ptr = &cave[y][x];
1276                                         place_inner_grid(c_ptr);
1277                                         }
1278                                         for (x = xval + 3 + tmp; x <= xval + 5 + tmp; x++)
1279                                         {
1280                                         c_ptr = &cave[y][x];
1281                                         place_inner_grid(c_ptr);
1282                                         }
1283                                 }
1284                         }
1285
1286                         /* Occasionally, some Inner rooms */
1287                         if (one_in_(3))
1288                         {
1289                                 int door_type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
1290                                         one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
1291                                         ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
1292
1293                                 /* Long horizontal walls */
1294                                 for (x = xval - 5; x <= xval + 5; x++)
1295                                 {
1296                                 c_ptr = &cave[yval - 1][x];
1297                                 place_inner_grid(c_ptr);
1298                                 c_ptr = &cave[yval + 1][x];
1299                                 place_inner_grid(c_ptr);
1300                                 }
1301
1302                                 /* Close off the left/right edges */
1303                                 c_ptr = &cave[yval][xval - 5];
1304                                 place_inner_grid(c_ptr);
1305                                 c_ptr = &cave[yval][xval + 5];
1306                                 place_inner_grid(c_ptr);
1307
1308                                 /* Secret doors (random top/bottom) */
1309                                 place_secret_door(yval - 3 + (randint1(2) * 2), xval - 3, door_type);
1310                                 place_secret_door(yval - 3 + (randint1(2) * 2), xval + 3, door_type);
1311
1312                                 /* Monsters */
1313                                 vault_monsters(yval, xval - 2, randint1(2));
1314                                 vault_monsters(yval, xval + 2, randint1(2));
1315
1316                                 /* Objects */
1317                                 if (one_in_(3)) place_object(yval, xval - 2, 0L);
1318                                 if (one_in_(3)) place_object(yval, xval + 2, 0L);
1319                         }
1320
1321                         break;
1322                 }
1323
1324                 /* Maze inside. */
1325                 case 4:
1326                 {
1327                         /* Place a secret door */
1328                         switch (randint1(4))
1329                         {
1330                                 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
1331                                 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
1332                                 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
1333                                 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
1334                         }
1335
1336                         /* Maze (really a checkerboard) */
1337                         for (y = y1; y <= y2; y++)
1338                         {
1339                                 for (x = x1; x <= x2; x++)
1340                                 {
1341                                         if (0x1 & (x + y))
1342                                         {
1343                                                 c_ptr = &cave[y][x];
1344                                                 place_inner_grid(c_ptr);
1345                                         }
1346                                 }
1347                         }
1348
1349                         /* Monsters just love mazes. */
1350                         vault_monsters(yval, xval - 5, randint1(3));
1351                         vault_monsters(yval, xval + 5, randint1(3));
1352
1353                         /* Traps make them entertaining. */
1354                         vault_traps(yval, xval - 3, 2, 8, randint1(3));
1355                         vault_traps(yval, xval + 3, 2, 8, randint1(3));
1356
1357                         /* Mazes should have some treasure too. */
1358                         vault_objects(yval, xval, 3);
1359
1360                         break;
1361                 }
1362
1363                 /* Four small rooms. */
1364                 case 5:
1365                 {
1366                         int door_type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
1367                                 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
1368                                 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
1369
1370                         /* Inner "cross" */
1371                         for (y = y1; y <= y2; y++)
1372                         {
1373                                 c_ptr = &cave[y][xval];
1374                                 place_inner_grid(c_ptr);
1375                         }
1376                         for (x = x1; x <= x2; x++)
1377                         {
1378                                 c_ptr = &cave[yval][x];
1379                                 place_inner_grid(c_ptr);
1380                         }
1381
1382                         /* Doors into the rooms */
1383                         if (randint0(100) < 50)
1384                         {
1385                                 int i = randint1(10);
1386                                 place_secret_door(y1 - 1, xval - i, door_type);
1387                                 place_secret_door(y1 - 1, xval + i, door_type);
1388                                 place_secret_door(y2 + 1, xval - i, door_type);
1389                                 place_secret_door(y2 + 1, xval + i, door_type);
1390                         }
1391                         else
1392                         {
1393                                 int i = randint1(3);
1394                                 place_secret_door(yval + i, x1 - 1, door_type);
1395                                 place_secret_door(yval - i, x1 - 1, door_type);
1396                                 place_secret_door(yval + i, x2 + 1, door_type);
1397                                 place_secret_door(yval - i, x2 + 1, door_type);
1398                         }
1399
1400                         /* Treasure, centered at the center of the cross */
1401                         vault_objects(yval, xval, 2 + randint1(2));
1402
1403                         /* Gotta have some monsters. */
1404                         vault_monsters(yval + 1, xval - 4, randint1(4));
1405                         vault_monsters(yval + 1, xval + 4, randint1(4));
1406                         vault_monsters(yval - 1, xval - 4, randint1(4));
1407                         vault_monsters(yval - 1, xval + 4, randint1(4));
1408
1409                         break;
1410                 }
1411         }
1412
1413         return TRUE;
1414 }
1415
1416
1417
1418 /*!
1419  * vaultに配置可能なモンスターの条件を指定するマクロ / Monster validation macro
1420  *
1421  * Line 1 -- forbid town monsters
1422  * Line 2 -- forbid uniques
1423  * Line 3 -- forbid aquatic monsters
1424  */
1425 #define vault_monster_okay(I) \
1426         (mon_hook_dungeon(I) && \
1427          !(r_info[I].flags1 & RF1_UNIQUE) && \
1428          !(r_info[I].flags7 & RF7_UNIQUE2) && \
1429          !(r_info[I].flagsr & RFR_RES_ALL) && \
1430          !(r_info[I].flags7 & RF7_AQUATIC))
1431
1432
1433 /*! 通常pit生成時のモンスターの構成条件ID / Race index for "monster pit (clone)" */
1434 static int vault_aux_race;
1435
1436 /*! 単一シンボルpit生成時の指定シンボル / Race index for "monster pit (symbol clone)" */
1437 static char vault_aux_char;
1438
1439 /*! ブレス属性に基づくドラゴンpit生成時条件マスク / Breath mask for "monster pit (dragon)" */
1440 static u32b vault_aux_dragon_mask4;
1441
1442
1443 /*!
1444  * @brief モンスターがVault生成の最低必要条件を満たしているかを返す /
1445  * Helper monster selection function
1446  * @param r_idx 確認したいモンスター種族ID
1447  * @return Vault生成の最低必要条件を満たしているならTRUEを返す。
1448  */
1449 static bool vault_aux_simple(MONRACE_IDX r_idx)
1450 {
1451         /* Okay */
1452         return (vault_monster_okay(r_idx));
1453 }
1454
1455
1456 /*!
1457  * @brief モンスターがゼリーnestの生成必要条件を満たしているかを返す /
1458  * Helper function for "monster nest (jelly)"
1459  * @param r_idx 確認したいモンスター種族ID
1460  * @return 生成必要条件を満たしているならTRUEを返す。
1461  */
1462 static bool vault_aux_jelly(MONRACE_IDX r_idx)
1463 {
1464         monster_race *r_ptr = &r_info[r_idx];
1465
1466         /* Validate the monster */
1467         if (!vault_monster_okay(r_idx)) return (FALSE);
1468
1469         if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1470
1471         /* Also decline evil jellies (like death molds and shoggoths) */
1472         if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1473
1474         /* Require icky thing, jelly, mold, or mushroom */
1475         if (!my_strchr("ijm,", r_ptr->d_char)) return (FALSE);
1476
1477         /* Okay */
1478         return (TRUE);
1479 }
1480
1481 /*!
1482  * @brief モンスターが動物nestの生成必要条件を満たしているかを返す /
1483  * Helper function for "monster nest (animal)"
1484  * @param r_idx 確認したいモンスター種族ID
1485  * @return 生成必要条件を満たしているならTRUEを返す。
1486  */
1487 static bool vault_aux_animal(MONRACE_IDX r_idx)
1488 {
1489         monster_race *r_ptr = &r_info[r_idx];
1490
1491         /* Validate the monster */
1492         if (!vault_monster_okay(r_idx)) return (FALSE);
1493
1494         /* Require "animal" flag */
1495         if (!(r_ptr->flags3 & (RF3_ANIMAL))) return (FALSE);
1496
1497         /* Okay */
1498         return (TRUE);
1499 }
1500
1501
1502 /*!
1503  * @brief モンスターがアンデッドnestの生成必要条件を満たしているかを返す /
1504  * Helper function for "monster nest (undead)"
1505  * @param r_idx 確認したいモンスター種族ID
1506  * @return 生成必要条件を満たしているならTRUEを返す。
1507  */
1508 static bool vault_aux_undead(MONRACE_IDX r_idx)
1509 {
1510         monster_race *r_ptr = &r_info[r_idx];
1511
1512         /* Validate the monster */
1513         if (!vault_monster_okay(r_idx)) return (FALSE);
1514
1515         /* Require Undead */
1516         if (!(r_ptr->flags3 & (RF3_UNDEAD))) return (FALSE);
1517
1518         /* Okay */
1519         return (TRUE);
1520 }
1521
1522 /*!
1523  * @brief モンスターが聖堂nestの生成必要条件を満たしているかを返す /
1524  * Helper function for "monster nest (chapel)"
1525  * @param r_idx 確認したいモンスター種族ID
1526  * @return 生成必要条件を満たしているならTRUEを返す。
1527  */
1528 static bool vault_aux_chapel_g(MONRACE_IDX r_idx)
1529 {
1530         static int chapel_list[] = {
1531                 MON_NOV_PRIEST, MON_NOV_PALADIN, MON_NOV_PRIEST_G, MON_NOV_PALADIN_G, 
1532                 MON_PRIEST, MON_JADE_MONK, MON_IVORY_MONK, MON_ULTRA_PALADIN, 
1533                 MON_EBONY_MONK, MON_W_KNIGHT, MON_KNI_TEMPLAR, MON_PALADIN,
1534                 MON_TOPAZ_MONK, 0};
1535
1536         int i;
1537
1538         monster_race *r_ptr = &r_info[r_idx];
1539
1540         /* Validate the monster */
1541         if (!vault_monster_okay(r_idx)) return (FALSE);
1542
1543         if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1544         if ((r_idx == MON_A_GOLD) || (r_idx == MON_A_SILVER)) return (FALSE);
1545
1546         /* Require "priest" or Angel */
1547
1548         if (r_ptr->d_char == 'A') return TRUE;
1549
1550         for (i = 0; chapel_list[i]; i++)
1551                 if (r_idx == chapel_list[i]) return TRUE;
1552
1553         return FALSE;
1554 }
1555
1556 /*!
1557  * @brief モンスターが犬小屋nestの生成必要条件を満たしているかを返す /
1558  * Helper function for "monster nest (kennel)"
1559  * @param r_idx 確認したいモンスター種族ID
1560  * @return 生成必要条件を満たしているならTRUEを返す。
1561  */
1562 static bool vault_aux_kennel(MONRACE_IDX r_idx)
1563 {
1564         monster_race *r_ptr = &r_info[r_idx];
1565
1566         /* Validate the monster */
1567         if (!vault_monster_okay(r_idx)) return (FALSE);
1568
1569         /* Require a Zephyr Hound or a dog */
1570         if (!my_strchr("CZ", r_ptr->d_char)) return (FALSE);
1571   
1572         /* Okay */
1573         return (TRUE);
1574 }
1575
1576 /*!
1577  * @brief モンスターがミミックnestの生成必要条件を満たしているかを返す /
1578  * Helper function for "monster nest (mimic)"
1579  * @param r_idx 確認したいモンスター種族ID
1580  * @return 生成必要条件を満たしているならTRUEを返す。
1581  */
1582 static bool vault_aux_mimic(MONRACE_IDX r_idx)
1583 {
1584         monster_race *r_ptr = &r_info[r_idx];
1585
1586         /* Validate the monster */
1587         if (!vault_monster_okay(r_idx)) return (FALSE);
1588
1589         /* Require mimic */
1590         if (!my_strchr("!$&(/=?[\\|", r_ptr->d_char)) return (FALSE);
1591
1592         /* Okay */
1593         return (TRUE);
1594 }
1595
1596 /*!
1597  * @brief モンスターが単一クローンnestの生成必要条件を満たしているかを返す /
1598  * Helper function for "monster nest (clone)"
1599  * @param r_idx 確認したいモンスター種族ID
1600  * @return 生成必要条件を満たしているならTRUEを返す。
1601  */
1602 static bool vault_aux_clone(MONRACE_IDX r_idx)
1603 {
1604         /* Validate the monster */
1605         if (!vault_monster_okay(r_idx)) return (FALSE);
1606
1607         return (r_idx == vault_aux_race);
1608 }
1609
1610
1611 /*!
1612  * @brief モンスターが邪悪属性シンボルクローンnestの生成必要条件を満たしているかを返す /
1613  * Helper function for "monster nest (symbol clone)"
1614  * @param r_idx 確認したいモンスター種族ID
1615  * @return 生成必要条件を満たしているならTRUEを返す。
1616  */
1617 static bool vault_aux_symbol_e(MONRACE_IDX r_idx)
1618 {
1619         monster_race *r_ptr = &r_info[r_idx];
1620
1621         /* Validate the monster */
1622         if (!vault_monster_okay(r_idx)) return (FALSE);
1623
1624         if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1625
1626         if (r_ptr->flags3 & (RF3_GOOD)) return (FALSE);
1627
1628         /* Decline incorrect symbol */
1629         if (r_ptr->d_char != vault_aux_char) return (FALSE);
1630
1631         /* Okay */
1632         return (TRUE);
1633 }
1634
1635
1636 /*!
1637  * @brief モンスターが善良属性シンボルクローンnestの生成必要条件を満たしているかを返す /
1638  * Helper function for "monster nest (symbol clone)"
1639  * @param r_idx 確認したいモンスター種族ID
1640  * @return 生成必要条件を満たしているならTRUEを返す。
1641  */
1642 static bool vault_aux_symbol_g(MONRACE_IDX r_idx)
1643 {
1644         monster_race *r_ptr = &r_info[r_idx];
1645
1646         /* Validate the monster */
1647         if (!vault_monster_okay(r_idx)) return (FALSE);
1648
1649         if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1650
1651         if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1652
1653         /* Decline incorrect symbol */
1654         if (r_ptr->d_char != vault_aux_char) return (FALSE);
1655
1656         /* Okay */
1657         return (TRUE);
1658 }
1659
1660
1661 /*!
1662  * @brief モンスターがオークpitの生成必要条件を満たしているかを返す /
1663  * Helper function for "monster pit (orc)"
1664  * @param r_idx 確認したいモンスター種族ID
1665  * @return 生成必要条件を満たしているならTRUEを返す。
1666  */
1667 static bool vault_aux_orc(MONRACE_IDX r_idx)
1668 {
1669         monster_race *r_ptr = &r_info[r_idx];
1670
1671         /* Validate the monster */
1672         if (!vault_monster_okay(r_idx)) return (FALSE);
1673
1674         /* Require orc */
1675         if (!(r_ptr->flags3 & RF3_ORC)) return (FALSE);
1676
1677         /* Decline undead */
1678         if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1679
1680         /* Okay */
1681         return (TRUE);
1682 }
1683
1684
1685 /*!
1686  * @brief モンスターがトロルpitの生成必要条件を満たしているかを返す /
1687  * Helper function for "monster pit (troll)"
1688  * @param r_idx 確認したいモンスター種族ID
1689  * @return 生成必要条件を満たしているならTRUEを返す。
1690  */
1691 static bool vault_aux_troll(MONRACE_IDX r_idx)
1692 {
1693         monster_race *r_ptr = &r_info[r_idx];
1694
1695         /* Validate the monster */
1696         if (!vault_monster_okay(r_idx)) return (FALSE);
1697
1698         /* Require troll */
1699         if (!(r_ptr->flags3 & RF3_TROLL)) return (FALSE);
1700
1701         /* Decline undead */
1702         if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1703
1704         /* Okay */
1705         return (TRUE);
1706 }
1707
1708
1709 /*!
1710  * @brief モンスターが巨人pitの生成必要条件を満たしているかを返す /
1711  * Helper function for "monster pit (giant)"
1712  * @param r_idx 確認したいモンスター種族ID
1713  * @return 生成必要条件を満たしているならTRUEを返す。
1714  */
1715 static bool vault_aux_giant(MONRACE_IDX r_idx)
1716 {
1717         monster_race *r_ptr = &r_info[r_idx];
1718
1719         /* Validate the monster */
1720         if (!vault_monster_okay(r_idx)) return (FALSE);
1721
1722         /* Require giant */
1723         if (!(r_ptr->flags3 & RF3_GIANT)) return (FALSE);
1724
1725         if (r_ptr->flags3 & RF3_GOOD) return (FALSE);
1726
1727         /* Decline undead */
1728         if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1729
1730         /* Okay */
1731         return (TRUE);
1732 }
1733
1734
1735 /*!
1736  * @brief モンスターがドラゴンpitの生成必要条件を満たしているかを返す /
1737  * Helper function for "monster pit (dragon)"
1738  * @param r_idx 確認したいモンスター種族ID
1739  * @return 生成必要条件を満たしているならTRUEを返す。
1740  */
1741 static bool vault_aux_dragon(MONRACE_IDX r_idx)
1742 {
1743         monster_race *r_ptr = &r_info[r_idx];
1744
1745         /* Validate the monster */
1746         if (!vault_monster_okay(r_idx)) return (FALSE);
1747
1748         /* Require dragon */
1749         if (!(r_ptr->flags3 & RF3_DRAGON)) return (FALSE);
1750
1751         /* Hack -- Require correct "breath attack" */
1752         if (r_ptr->flags4 != vault_aux_dragon_mask4) return (FALSE);
1753
1754         /* Decline undead */
1755         if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1756
1757         /* Okay */
1758         return (TRUE);
1759 }
1760
1761
1762 /*!
1763  * @brief モンスターが悪魔pitの生成必要条件を満たしているかを返す /
1764  * Helper function for "monster pit (demon)"
1765  * @param r_idx 確認したいモンスター種族ID
1766  * @return 生成必要条件を満たしているならTRUEを返す。
1767  */
1768 static bool vault_aux_demon(MONRACE_IDX r_idx)
1769 {
1770         monster_race *r_ptr = &r_info[r_idx];
1771
1772         /* Validate the monster */
1773         if (!vault_monster_okay(r_idx)) return (FALSE);
1774
1775         if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1776
1777         /* Require demon */
1778         if (!(r_ptr->flags3 & RF3_DEMON)) return (FALSE);
1779
1780         /* Okay */
1781         return (TRUE);
1782 }
1783
1784
1785 /*!
1786  * @brief モンスターが狂気pitの生成必要条件を満たしているかを返す /
1787  * Helper function for "monster pit (lovecraftian)"
1788  * @param r_idx 確認したいモンスター種族ID
1789  * @return 生成必要条件を満たしているならTRUEを返す。
1790  */
1791 static bool vault_aux_cthulhu(MONRACE_IDX r_idx)
1792 {
1793         monster_race *r_ptr = &r_info[r_idx];
1794
1795         /* Validate the monster */
1796         if (!vault_monster_okay(r_idx)) return (FALSE);
1797
1798         if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1799
1800         /* Require eldritch horror */
1801         if (!(r_ptr->flags2 & (RF2_ELDRITCH_HORROR))) return (FALSE);
1802
1803         /* Okay */
1804         return (TRUE);
1805 }
1806
1807
1808 /*!
1809  * @brief pit/nestの基準となる単種モンスターを決める /
1810  * @return なし
1811  */
1812 static void vault_prep_clone(void)
1813 {
1814         /* Apply the monster restriction */
1815         get_mon_num_prep(vault_aux_simple, NULL);
1816
1817         /* Pick a race to clone */
1818         vault_aux_race = get_mon_num(dun_level + 10);
1819
1820         /* Remove the monster restriction */
1821         get_mon_num_prep(NULL, NULL);
1822 }
1823
1824
1825 /*!
1826  * @brief pit/nestの基準となるモンスターシンボルを決める /
1827  * @return なし
1828  */
1829 static void vault_prep_symbol(void)
1830 {
1831         MONRACE_IDX r_idx;
1832
1833         /* Apply the monster restriction */
1834         get_mon_num_prep(vault_aux_simple, NULL);
1835
1836         /* Pick a race to clone */
1837         r_idx = get_mon_num(dun_level + 10);
1838
1839         /* Remove the monster restriction */
1840         get_mon_num_prep(NULL, NULL);
1841
1842         /* Extract the symbol */
1843         vault_aux_char = r_info[r_idx].d_char;
1844 }
1845
1846 /*!
1847  * @brief pit/nestの基準となるドラゴンの種類を決める /
1848  * @return なし
1849  */
1850 static void vault_prep_dragon(void)
1851 {
1852         /* Pick dragon type */
1853         switch (randint0(6))
1854         {
1855                 /* Black */
1856                 case 0:
1857                 {
1858                         /* Restrict dragon breath type */
1859                         vault_aux_dragon_mask4 = RF4_BR_ACID;
1860
1861                         /* Done */
1862                         break;
1863                 }
1864
1865                 /* Blue */
1866                 case 1:
1867                 {
1868                         /* Restrict dragon breath type */
1869                         vault_aux_dragon_mask4 = RF4_BR_ELEC;
1870
1871                         /* Done */
1872                         break;
1873                 }
1874
1875                 /* Red */
1876                 case 2:
1877                 {
1878                         /* Restrict dragon breath type */
1879                         vault_aux_dragon_mask4 = RF4_BR_FIRE;
1880
1881                         /* Done */
1882                         break;
1883                 }
1884
1885                 /* White */
1886                 case 3:
1887                 {
1888                         /* Restrict dragon breath type */
1889                         vault_aux_dragon_mask4 = RF4_BR_COLD;
1890
1891                         /* Done */
1892                         break;
1893                 }
1894
1895                 /* Green */
1896                 case 4:
1897                 {
1898                         /* Restrict dragon breath type */
1899                         vault_aux_dragon_mask4 = RF4_BR_POIS;
1900
1901                         /* Done */
1902                         break;
1903                 }
1904
1905                 /* Multi-hued */
1906                 default:
1907                 {
1908                         /* Restrict dragon breath type */
1909                         vault_aux_dragon_mask4 = (RF4_BR_ACID | RF4_BR_ELEC |
1910                                                                                           RF4_BR_FIRE | RF4_BR_COLD |
1911                                                                                           RF4_BR_POIS);
1912
1913                         /* Done */
1914                         break;
1915                 }
1916         }
1917 }
1918
1919
1920 /*!
1921  * @brief モンスターがダークエルフpitの生成必要条件を満たしているかを返す /
1922  * Helper function for "monster pit (dark elf)"
1923  * @param r_idx 確認したいモンスター種族ID
1924  * @return 生成必要条件を満たしているならTRUEを返す。
1925  */
1926 static bool vault_aux_dark_elf(MONRACE_IDX r_idx)
1927 {
1928         int i;
1929         static int dark_elf_list[] =
1930         {
1931                 MON_D_ELF, MON_D_ELF_MAGE, MON_D_ELF_WARRIOR, MON_D_ELF_PRIEST,
1932                 MON_D_ELF_LORD, MON_D_ELF_WARLOCK, MON_D_ELF_DRUID, MON_NIGHTBLADE,
1933                 MON_D_ELF_SORC, MON_D_ELF_SHADE, 0,
1934         };
1935
1936         /* Validate the monster */
1937         if (!vault_monster_okay(r_idx)) return FALSE;
1938
1939         /* Require dark elves */
1940         for (i = 0; dark_elf_list[i]; i++)
1941                 if (r_idx == dark_elf_list[i]) return TRUE;
1942
1943         /* Assume not */
1944         return FALSE;
1945 }
1946
1947 /*! pit/nest型情報のtypedef */
1948 typedef struct vault_aux_type vault_aux_type;
1949
1950 /*! pit/nest型情報の構造体定義 */
1951 struct vault_aux_type
1952 {
1953         cptr name;
1954         bool (*hook_func)(MONRACE_IDX r_idx);
1955         void (*prep_func)(void);
1956         int level;
1957         int chance;
1958 };
1959
1960 /*!
1961  * @brief ダンジョン毎に指定されたピット配列を基準にランダムなpit/nestタイプを決める
1962  * @param l_ptr 選択されたpit/nest情報を返す参照ポインタ
1963  * @param allow_flag_mask 生成が許されるpit/nestのビット配列
1964  * @return 選択されたpit/nestのID、選択失敗した場合-1を返す。
1965  */
1966 static int pick_vault_type(vault_aux_type *l_ptr, s16b allow_flag_mask)
1967 {
1968         int tmp, total, count;
1969
1970         vault_aux_type *n_ptr;
1971
1972         /* Calculate the total possibilities */
1973         for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1974         {
1975                 /* Note end */
1976                 if (!n_ptr->name) break;
1977
1978                 /* Ignore excessive depth */
1979                 if (n_ptr->level > dun_level) continue;
1980
1981                 /* Not matched with pit/nest flag */
1982                 if (!(allow_flag_mask & (1L << count))) continue;
1983
1984                 /* Count this possibility */
1985                 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1986         }
1987
1988         /* Pick a random type */
1989         tmp = randint0(total);
1990
1991         /* Find this type */
1992         for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1993         {
1994                 /* Note end */
1995                 if (!n_ptr->name) break;
1996
1997                 /* Ignore excessive depth */
1998                 if (n_ptr->level > dun_level) continue;
1999
2000                 /* Not matched with pit/nest flag */
2001                 if (!(allow_flag_mask & (1L << count))) continue;
2002
2003                 /* Count this possibility */
2004                 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
2005
2006                 /* Found the type */
2007                 if (tmp < total) break;
2008         }
2009
2010         return n_ptr->name ? count : -1;
2011 }
2012
2013 /*!nest情報テーブル*/
2014 static vault_aux_type nest_types[] =
2015 {
2016 #ifdef JP
2017         {"クローン",     vault_aux_clone,    vault_prep_clone,   5, 3},
2018         {"ゼリー",       vault_aux_jelly,    NULL,               5, 6},
2019         {"シンボル(善)", vault_aux_symbol_g, vault_prep_symbol, 25, 2},
2020         {"シンボル(悪)", vault_aux_symbol_e, vault_prep_symbol, 25, 2},
2021         {"ミミック",     vault_aux_mimic,    NULL,              30, 4},
2022         {"狂気",         vault_aux_cthulhu,  NULL,              70, 2},
2023         {"犬小屋",       vault_aux_kennel,   NULL,              45, 4},
2024         {"動物園",       vault_aux_animal,   NULL,              35, 5},
2025         {"教会",         vault_aux_chapel_g, NULL,              75, 4},
2026         {"アンデッド",   vault_aux_undead,   NULL,              75, 5},
2027         {NULL,           NULL,               NULL,               0, 0},
2028 #else
2029         {"clone",        vault_aux_clone,    vault_prep_clone,   5, 3},
2030         {"jelly",        vault_aux_jelly,    NULL,               5, 6},
2031         {"symbol good",  vault_aux_symbol_g, vault_prep_symbol, 25, 2},
2032         {"symbol evil",  vault_aux_symbol_e, vault_prep_symbol, 25, 2},
2033         {"mimic",        vault_aux_mimic,    NULL,              30, 4},
2034         {"lovecraftian", vault_aux_cthulhu,  NULL,              70, 2},
2035         {"kennel",       vault_aux_kennel,   NULL,              45, 4},
2036         {"animal",       vault_aux_animal,   NULL,              35, 5},
2037         {"chapel",       vault_aux_chapel_g, NULL,              75, 4},
2038         {"undead",       vault_aux_undead,   NULL,              75, 5},
2039         {NULL,           NULL,               NULL,               0, 0},
2040 #endif
2041 };
2042
2043 /*!pit情報テーブル*/
2044 static vault_aux_type pit_types[] =
2045 {
2046 #ifdef JP
2047         {"オーク",       vault_aux_orc,      NULL,               5, 6},
2048         {"トロル",       vault_aux_troll,    NULL,              20, 6},
2049         {"ジャイアント", vault_aux_giant,    NULL,              50, 6},
2050         {"狂気",         vault_aux_cthulhu,  NULL,              80, 2},
2051         {"シンボル(善)", vault_aux_symbol_g, vault_prep_symbol, 70, 1},
2052         {"シンボル(悪)", vault_aux_symbol_e, vault_prep_symbol, 70, 1},
2053         {"教会",         vault_aux_chapel_g, NULL,              65, 2},
2054         {"ドラゴン",     vault_aux_dragon,   vault_prep_dragon, 70, 6},
2055         {"デーモン",     vault_aux_demon,    NULL,              80, 6},
2056         {"ダークエルフ", vault_aux_dark_elf, NULL,              45, 4},
2057         {NULL,           NULL,               NULL,               0, 0},
2058 #else
2059         {"orc",          vault_aux_orc,      NULL,               5, 6},
2060         {"troll",        vault_aux_troll,    NULL,              20, 6},
2061         {"giant",        vault_aux_giant,    NULL,              50, 6},
2062         {"lovecraftian", vault_aux_cthulhu,  NULL,              80, 2},
2063         {"symbol good",  vault_aux_symbol_g, vault_prep_symbol, 70, 1},
2064         {"symbol evil",  vault_aux_symbol_e, vault_prep_symbol, 70, 1},
2065         {"chapel",       vault_aux_chapel_g, NULL,              65, 2},
2066         {"dragon",       vault_aux_dragon,   vault_prep_dragon, 70, 6},
2067         {"demon",        vault_aux_demon,    NULL,              80, 6},
2068         {"dark elf",     vault_aux_dark_elf, NULL,              45, 4},
2069         {NULL,           NULL,               NULL,               0, 0},
2070 #endif
2071 };
2072
2073
2074 /*! nestのID定義 /  Nest types code */
2075 #define NEST_TYPE_CLONE        0
2076 #define NEST_TYPE_JELLY        1
2077 #define NEST_TYPE_SYMBOL_GOOD  2
2078 #define NEST_TYPE_SYMBOL_EVIL  3
2079 #define NEST_TYPE_MIMIC        4
2080 #define NEST_TYPE_LOVECRAFTIAN 5
2081 #define NEST_TYPE_KENNEL       6
2082 #define NEST_TYPE_ANIMAL       7
2083 #define NEST_TYPE_CHAPEL       8
2084 #define NEST_TYPE_UNDEAD       9
2085
2086 /*! pitのID定義 / Pit types code */
2087 #define PIT_TYPE_ORC           0
2088 #define PIT_TYPE_TROLL         1
2089 #define PIT_TYPE_GIANT         2
2090 #define PIT_TYPE_LOVECRAFTIAN  3
2091 #define PIT_TYPE_SYMBOL_GOOD   4
2092 #define PIT_TYPE_SYMBOL_EVIL   5
2093 #define PIT_TYPE_CHAPEL        6
2094 #define PIT_TYPE_DRAGON        7
2095 #define PIT_TYPE_DEMON         8
2096 #define PIT_TYPE_DARK_ELF      9
2097
2098
2099 /*!
2100  * @brief デバッグ時に生成されたpit/nestの型を出力する処理
2101  * @param type pit/nestの型ID
2102  * @param nest TRUEならばnest、FALSEならばpit
2103  * @return デバッグ表示文字列の参照ポインタ
2104  * @details
2105  * Hack -- Get the string describing subtype of pit/nest
2106  * Determined in prepare function (some pit/nest only)
2107  */
2108 static cptr pit_subtype_string(int type, bool nest)
2109 {
2110         static char inner_buf[256] = "";
2111
2112         inner_buf[0] = '\0'; /* Init string */
2113
2114         if (nest) /* Nests */
2115         {
2116                 switch (type)
2117                 {
2118                 case NEST_TYPE_CLONE:
2119                         sprintf(inner_buf, "(%s)", r_name + r_info[vault_aux_race].name);
2120                         break;
2121                 case NEST_TYPE_SYMBOL_GOOD:
2122                 case NEST_TYPE_SYMBOL_EVIL:
2123                         sprintf(inner_buf, "(%c)", vault_aux_char);
2124                         break;
2125                 }
2126         }
2127         else /* Pits */
2128         {
2129                 switch (type)
2130                 {
2131                 case PIT_TYPE_SYMBOL_GOOD:
2132                 case PIT_TYPE_SYMBOL_EVIL:
2133                         sprintf(inner_buf, "(%c)", vault_aux_char);
2134                         break;
2135                 case PIT_TYPE_DRAGON:
2136                         switch (vault_aux_dragon_mask4)
2137                         {
2138 #ifdef JP
2139                         case RF4_BR_ACID: strcpy(inner_buf, "(酸)");   break;
2140                         case RF4_BR_ELEC: strcpy(inner_buf, "(稲妻)"); break;
2141                         case RF4_BR_FIRE: strcpy(inner_buf, "(火炎)"); break;
2142                         case RF4_BR_COLD: strcpy(inner_buf, "(冷気)"); break;
2143                         case RF4_BR_POIS: strcpy(inner_buf, "(毒)");   break;
2144                         case (RF4_BR_ACID | RF4_BR_ELEC | RF4_BR_FIRE | RF4_BR_COLD | RF4_BR_POIS):
2145                                 strcpy(inner_buf, "(万色)"); break;
2146                         default: strcpy(inner_buf, "(未定義)"); break;
2147 #else
2148                         case RF4_BR_ACID: strcpy(inner_buf, "(acid)");      break;
2149                         case RF4_BR_ELEC: strcpy(inner_buf, "(lightning)"); break;
2150                         case RF4_BR_FIRE: strcpy(inner_buf, "(fire)");      break;
2151                         case RF4_BR_COLD: strcpy(inner_buf, "(frost)");     break;
2152                         case RF4_BR_POIS: strcpy(inner_buf, "(poison)");    break;
2153                         case (RF4_BR_ACID | RF4_BR_ELEC | RF4_BR_FIRE | RF4_BR_COLD | RF4_BR_POIS):
2154                                 strcpy(inner_buf, "(multi-hued)"); break;
2155                         default: strcpy(inner_buf, "(undefined)"); break;
2156 #endif
2157                         }
2158                         break;
2159                 }
2160         }
2161
2162         return inner_buf;
2163 }
2164
2165
2166 /*! デバッグ時にnestのモンスター情報を確認するための構造体 / A struct for nest monster information with cheat_hear */
2167 typedef struct
2168 {
2169         s16b r_idx;
2170         bool used;
2171 }
2172 nest_mon_info_type;
2173
2174
2175 /*
2176  *! @brief nestのモンスターリストをソートするための関数 /
2177  *  Comp function for sorting nest monster information
2178  *  @param u ソート処理対象配列ポインタ
2179  *  @param v 未使用
2180  *  @param a 比較対象参照ID1
2181  *  @param b 比較対象参照ID2
2182  */
2183 static bool ang_sort_comp_nest_mon_info(vptr u, vptr v, int a, int b)
2184 {
2185         nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
2186         int w1 = nest_mon_info[a].r_idx;
2187         int w2 = nest_mon_info[b].r_idx;
2188         monster_race *r1_ptr = &r_info[w1];
2189         monster_race *r2_ptr = &r_info[w2];
2190         int z1, z2;
2191
2192         /* Unused */
2193         (void)v;
2194
2195         /* Extract used info */
2196         z1 = nest_mon_info[a].used;
2197         z2 = nest_mon_info[b].used;
2198
2199         /* Compare used status */
2200         if (z1 < z2) return FALSE;
2201         if (z1 > z2) return TRUE;
2202
2203         /* Compare levels */
2204         if (r1_ptr->level < r2_ptr->level) return TRUE;
2205         if (r1_ptr->level > r2_ptr->level) return FALSE;
2206
2207         /* Compare experience */
2208         if (r1_ptr->mexp < r2_ptr->mexp) return TRUE;
2209         if (r1_ptr->mexp > r2_ptr->mexp) return FALSE;
2210
2211         /* Compare indexes */
2212         return w1 <= w2;
2213 }
2214
2215 /*!
2216  * @brief nestのモンスターリストをスワップするための関数 /
2217  * Swap function for sorting nest monster information
2218  * @param u スワップ処理対象配列ポインタ
2219  * @param v 未使用
2220  * @param a スワップ対象参照ID1
2221  * @param b スワップ対象参照ID2
2222  */
2223 static void ang_sort_swap_nest_mon_info(vptr u, vptr v, int a, int b)
2224 {
2225         nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
2226         nest_mon_info_type holder;
2227
2228         /* Unused */
2229         (void)v;
2230
2231         /* Swap */
2232         holder = nest_mon_info[a];
2233         nest_mon_info[a] = nest_mon_info[b];
2234         nest_mon_info[b] = holder;
2235 }
2236
2237
2238 #define NUM_NEST_MON_TYPE 64 /*!<nestの種別数 */
2239
2240
2241 /*!
2242  * @brief タイプ5の部屋…nestを生成する / Type 5 -- Monster nests
2243  * @return なし
2244  * @details
2245  * A monster nest is a "big" room, with an "inner" room, containing\n
2246  * a "collection" of monsters of a given type strewn about the room.\n
2247  *\n
2248  * The monsters are chosen from a set of 64 randomly selected monster\n
2249  * races, to allow the nest creation to fail instead of having "holes".\n
2250  *\n
2251  * Note the use of the "get_mon_num_prep()" function, and the special\n
2252  * "get_mon_num_hook()" restriction function, to prepare the "monster\n
2253  * allocation table" in such a way as to optimize the selection of\n
2254  * "appropriate" non-unique monsters for the nest.\n
2255  *\n
2256  * Note that the "get_mon_num()" function may (rarely) fail, in which\n
2257  * case the nest will be empty.\n
2258  *\n
2259  * Note that "monster nests" will never contain "unique" monsters.\n
2260  */
2261 static bool build_type5(void)
2262 {
2263         POSITION y, x, y1, x1, y2, x2, xval, yval;
2264         int i;
2265         nest_mon_info_type nest_mon_info[NUM_NEST_MON_TYPE];
2266
2267         monster_type align;
2268
2269         cave_type *c_ptr;
2270
2271         int cur_nest_type = pick_vault_type(nest_types, d_info[dungeon_type].nest);
2272         vault_aux_type *n_ptr;
2273
2274         /* No type available */
2275         if (cur_nest_type < 0) return FALSE;
2276
2277         n_ptr = &nest_types[cur_nest_type];
2278
2279         /* Process a preparation function if necessary */
2280         if (n_ptr->prep_func) (*(n_ptr->prep_func))();
2281
2282         /* Prepare allocation table */
2283         get_mon_num_prep(n_ptr->hook_func, NULL);
2284
2285         align.sub_align = SUB_ALIGN_NEUTRAL;
2286
2287         /* Pick some monster types */
2288         for (i = 0; i < NUM_NEST_MON_TYPE; i++)
2289         {
2290                 MONRACE_IDX r_idx = 0;
2291                 int attempts = 100;
2292                 monster_race *r_ptr = NULL;
2293
2294                 while (attempts--)
2295                 {
2296                         /* Get a (hard) monster type */
2297                         r_idx = get_mon_num(dun_level + 11);
2298                         r_ptr = &r_info[r_idx];
2299
2300                         /* Decline incorrect alignment */
2301                         if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2302
2303                         /* Accept this monster */
2304                         break;
2305                 }
2306
2307                 /* Notice failure */
2308                 if (!r_idx || !attempts) return FALSE;
2309
2310                 /* Note the alignment */
2311                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2312                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2313
2314                 nest_mon_info[i].r_idx = (s16b)r_idx;
2315                 nest_mon_info[i].used = FALSE;
2316         }
2317
2318         /* Find and reserve some space in the dungeon.  Get center of room. */
2319         if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2320
2321         /* Large room */
2322         y1 = yval - 4;
2323         y2 = yval + 4;
2324         x1 = xval - 11;
2325         x2 = xval + 11;
2326
2327         /* Place the floor area */
2328         for (y = y1 - 1; y <= y2 + 1; y++)
2329         {
2330                 for (x = x1 - 1; x <= x2 + 1; x++)
2331                 {
2332                         c_ptr = &cave[y][x];
2333                         place_floor_grid(c_ptr);
2334                         c_ptr->info |= (CAVE_ROOM);
2335                 }
2336         }
2337
2338         /* Place the outer walls */
2339         for (y = y1 - 1; y <= y2 + 1; y++)
2340         {
2341                 c_ptr = &cave[y][x1 - 1];
2342                 place_outer_grid(c_ptr);
2343                 c_ptr = &cave[y][x2 + 1];
2344                 place_outer_grid(c_ptr);
2345         }
2346         for (x = x1 - 1; x <= x2 + 1; x++)
2347         {
2348                 c_ptr = &cave[y1 - 1][x];
2349                 place_outer_grid(c_ptr);
2350                 c_ptr = &cave[y2 + 1][x];
2351                 place_outer_grid(c_ptr);
2352         }
2353
2354
2355         /* Advance to the center room */
2356         y1 = y1 + 2;
2357         y2 = y2 - 2;
2358         x1 = x1 + 2;
2359         x2 = x2 - 2;
2360
2361         /* The inner walls */
2362         for (y = y1 - 1; y <= y2 + 1; y++)
2363         {
2364                 c_ptr = &cave[y][x1 - 1];
2365                 place_inner_grid(c_ptr);
2366                 c_ptr = &cave[y][x2 + 1];
2367                 place_inner_grid(c_ptr);
2368         }
2369
2370         for (x = x1 - 1; x <= x2 + 1; x++)
2371         {
2372                 c_ptr = &cave[y1 - 1][x];
2373                 place_inner_grid(c_ptr);
2374                 c_ptr = &cave[y2 + 1][x];
2375                 place_inner_grid(c_ptr);
2376         }
2377         for (y = y1; y <= y2; y++)
2378         {
2379                 for (x = x1; x <= x2; x++)
2380                 {
2381                         add_cave_info(y, x, CAVE_ICKY);
2382                 }
2383         }
2384
2385         /* Place a secret door */
2386         switch (randint1(4))
2387         {
2388                 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
2389                 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
2390                 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
2391                 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
2392         }
2393
2394         msg_format_wizard(CHEAT_DUNGEON, _("モンスター部屋(nest)(%s%s)を生成します。", "Monster nest (%s%s)"), n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
2395
2396         /* Place some monsters */
2397         for (y = yval - 2; y <= yval + 2; y++)
2398         {
2399                 for (x = xval - 9; x <= xval + 9; x++)
2400                 {
2401                         MONRACE_IDX r_idx;
2402
2403                         i = randint0(NUM_NEST_MON_TYPE);
2404                         r_idx = nest_mon_info[i].r_idx;
2405
2406                         /* Place that "random" monster (no groups) */
2407                         (void)place_monster_aux(0, y, x, r_idx, 0L);
2408
2409                         nest_mon_info[i].used = TRUE;
2410                 }
2411         }
2412
2413         if (cheat_room)
2414         {
2415                 ang_sort_comp = ang_sort_comp_nest_mon_info;
2416                 ang_sort_swap = ang_sort_swap_nest_mon_info;
2417                 ang_sort(nest_mon_info, NULL, NUM_NEST_MON_TYPE);
2418
2419                 /* Dump the entries (prevent multi-printing) */
2420                 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
2421                 {
2422                         if (!nest_mon_info[i].used) break;
2423                         for (; i < NUM_NEST_MON_TYPE - 1; i++)
2424                         {
2425                                 if (nest_mon_info[i].r_idx != nest_mon_info[i + 1].r_idx) break;
2426                                 if (!nest_mon_info[i + 1].used) break;
2427                         }
2428                         msg_format_wizard(CHEAT_DUNGEON, "Nest構成モンスターNo.%d:%s", i, r_name + r_info[nest_mon_info[i].r_idx].name);
2429                 }
2430         }
2431
2432         return TRUE;
2433 }
2434
2435
2436 /*!
2437  * @brief タイプ6の部屋…pitを生成する / Type 6 -- Monster pits
2438  * @return なし
2439  * @details
2440  * A monster pit is a "big" room, with an "inner" room, containing\n
2441  * a "collection" of monsters of a given type organized in the room.\n
2442  *\n
2443  * The inside room in a monster pit appears as shown below, where the\n
2444  * actual monsters in each location depend on the type of the pit\n
2445  *\n
2446  *   XXXXXXXXXXXXXXXXXXXXX\n
2447  *   X0000000000000000000X\n
2448  *   X0112233455543322110X\n
2449  *   X0112233467643322110X\n
2450  *   X0112233455543322110X\n
2451  *   X0000000000000000000X\n
2452  *   XXXXXXXXXXXXXXXXXXXXX\n
2453  *\n
2454  * Note that the monsters in the pit are now chosen by using "get_mon_num()"\n
2455  * to request 16 "appropriate" monsters, sorting them by level, and using\n
2456  * the "even" entries in this sorted list for the contents of the pit.\n
2457  *\n
2458  * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",\n
2459  * which is handled by requiring a specific "breath" attack for all of the\n
2460  * dragons.  This may include "multi-hued" breath.  Note that "wyrms" may\n
2461  * be present in many of the dragon pits, if they have the proper breath.\n
2462  *\n
2463  * Note the use of the "get_mon_num_prep()" function, and the special\n
2464  * "get_mon_num_hook()" restriction function, to prepare the "monster\n
2465  * allocation table" in such a way as to optimize the selection of\n
2466  * "appropriate" non-unique monsters for the pit.\n
2467  *\n
2468  * Note that the "get_mon_num()" function may (rarely) fail, in which case\n
2469  * the pit will be empty.\n
2470  *\n
2471  * Note that "monster pits" will never contain "unique" monsters.\n
2472  */
2473 static bool build_type6(void)
2474 {
2475         POSITION y, x, y1, x1, y2, x2, xval, yval;
2476         int i, j;
2477
2478         MONRACE_IDX what[16];
2479
2480         monster_type align;
2481
2482         cave_type *c_ptr;
2483
2484         int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
2485         vault_aux_type *n_ptr;
2486
2487         /* No type available */
2488         if (cur_pit_type < 0) return FALSE;
2489
2490         n_ptr = &pit_types[cur_pit_type];
2491
2492         /* Process a preparation function if necessary */
2493         if (n_ptr->prep_func) (*(n_ptr->prep_func))();
2494
2495         /* Prepare allocation table */
2496         get_mon_num_prep(n_ptr->hook_func, NULL);
2497
2498         align.sub_align = SUB_ALIGN_NEUTRAL;
2499
2500         /* Pick some monster types */
2501         for (i = 0; i < 16; i++)
2502         {
2503                 MONRACE_IDX r_idx = 0;
2504                 int attempts = 100;
2505                 monster_race *r_ptr = NULL;
2506
2507                 while (attempts--)
2508                 {
2509                         /* Get a (hard) monster type */
2510                         r_idx = get_mon_num(dun_level + 11);
2511                         r_ptr = &r_info[r_idx];
2512
2513                         /* Decline incorrect alignment */
2514                         if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2515
2516                         /* Accept this monster */
2517                         break;
2518                 }
2519
2520                 /* Notice failure */
2521                 if (!r_idx || !attempts) return FALSE;
2522
2523                 /* Note the alignment */
2524                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2525                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2526
2527                 what[i] = r_idx;
2528         }
2529
2530         /* Find and reserve some space in the dungeon.  Get center of room. */
2531         if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2532
2533         /* Large room */
2534         y1 = yval - 4;
2535         y2 = yval + 4;
2536         x1 = xval - 11;
2537         x2 = xval + 11;
2538
2539         /* Place the floor area */
2540         for (y = y1 - 1; y <= y2 + 1; y++)
2541         {
2542                 for (x = x1 - 1; x <= x2 + 1; x++)
2543                 {
2544                         c_ptr = &cave[y][x];
2545                         place_floor_grid(c_ptr);
2546                         c_ptr->info |= (CAVE_ROOM);
2547                 }
2548         }
2549
2550         /* Place the outer walls */
2551         for (y = y1 - 1; y <= y2 + 1; y++)
2552         {
2553                 c_ptr = &cave[y][x1 - 1];
2554                 place_outer_grid(c_ptr);
2555                 c_ptr = &cave[y][x2 + 1];
2556                 place_outer_grid(c_ptr);
2557         }
2558         for (x = x1 - 1; x <= x2 + 1; x++)
2559         {
2560                 c_ptr = &cave[y1 - 1][x];
2561                 place_outer_grid(c_ptr);
2562                 c_ptr = &cave[y2 + 1][x];
2563                 place_outer_grid(c_ptr);
2564         }
2565
2566         /* Advance to the center room */
2567         y1 = y1 + 2;
2568         y2 = y2 - 2;
2569         x1 = x1 + 2;
2570         x2 = x2 - 2;
2571
2572         /* The inner walls */
2573         for (y = y1 - 1; y <= y2 + 1; y++)
2574         {
2575                 c_ptr = &cave[y][x1 - 1];
2576                 place_inner_grid(c_ptr);
2577                 c_ptr = &cave[y][x2 + 1];
2578                 place_inner_grid(c_ptr);
2579         }
2580         for (x = x1 - 1; x <= x2 + 1; x++)
2581         {
2582                 c_ptr = &cave[y1 - 1][x];
2583                 place_inner_grid(c_ptr);
2584                 c_ptr = &cave[y2 + 1][x];
2585                 place_inner_grid(c_ptr);
2586         }
2587         for (y = y1; y <= y2; y++)
2588         {
2589                 for (x = x1; x <= x2; x++)
2590                 {
2591                         add_cave_info(y, x, CAVE_ICKY);
2592                 }
2593         }
2594
2595         /* Place a secret door */
2596         switch (randint1(4))
2597         {
2598                 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
2599                 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
2600                 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
2601                 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
2602         }
2603
2604         /* Sort the entries */
2605         for (i = 0; i < 16 - 1; i++)
2606         {
2607                 /* Sort the entries */
2608                 for (j = 0; j < 16 - 1; j++)
2609                 {
2610                         int i1 = j;
2611                         int i2 = j + 1;
2612
2613                         int p1 = r_info[what[i1]].level;
2614                         int p2 = r_info[what[i2]].level;
2615
2616                         /* Bubble */
2617                         if (p1 > p2)
2618                         {
2619                                 MONRACE_IDX tmp = what[i1];
2620                                 what[i1] = what[i2];
2621                                 what[i2] = tmp;
2622                         }
2623                 }
2624         }
2625
2626         msg_format_wizard(CHEAT_DUNGEON, _("モンスター部屋(pit)(%s%s)を生成します。", "Monster pit (%s%s)"), n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
2627
2628         /* Select the entries */
2629         for (i = 0; i < 8; i++)
2630         {
2631                 /* Every other entry */
2632                 what[i] = what[i * 2];
2633                 msg_format_wizard(CHEAT_DUNGEON, _("Nest構成モンスター選択No.%d:%s", "Nest Monster Select No.%d:%s"), i, r_name + r_info[what[i]].name);
2634         }
2635
2636         /* Top and bottom rows */
2637         for (x = xval - 9; x <= xval + 9; x++)
2638         {
2639                 place_monster_aux(0, yval - 2, x, what[0], PM_NO_KAGE);
2640                 place_monster_aux(0, yval + 2, x, what[0], PM_NO_KAGE);
2641         }
2642
2643         /* Middle columns */
2644         for (y = yval - 1; y <= yval + 1; y++)
2645         {
2646                 place_monster_aux(0, y, xval - 9, what[0], PM_NO_KAGE);
2647                 place_monster_aux(0, y, xval + 9, what[0], PM_NO_KAGE);
2648
2649                 place_monster_aux(0, y, xval - 8, what[1], PM_NO_KAGE);
2650                 place_monster_aux(0, y, xval + 8, what[1], PM_NO_KAGE);
2651
2652                 place_monster_aux(0, y, xval - 7, what[1], PM_NO_KAGE);
2653                 place_monster_aux(0, y, xval + 7, what[1], PM_NO_KAGE);
2654
2655                 place_monster_aux(0, y, xval - 6, what[2], PM_NO_KAGE);
2656                 place_monster_aux(0, y, xval + 6, what[2], PM_NO_KAGE);
2657
2658                 place_monster_aux(0, y, xval - 5, what[2], PM_NO_KAGE);
2659                 place_monster_aux(0, y, xval + 5, what[2], PM_NO_KAGE);
2660
2661                 place_monster_aux(0, y, xval - 4, what[3], PM_NO_KAGE);
2662                 place_monster_aux(0, y, xval + 4, what[3], PM_NO_KAGE);
2663
2664                 place_monster_aux(0, y, xval - 3, what[3], PM_NO_KAGE);
2665                 place_monster_aux(0, y, xval + 3, what[3], PM_NO_KAGE);
2666
2667                 place_monster_aux(0, y, xval - 2, what[4], PM_NO_KAGE);
2668                 place_monster_aux(0, y, xval + 2, what[4], PM_NO_KAGE);
2669         }
2670
2671         /* Above/Below the center monster */
2672         for (x = xval - 1; x <= xval + 1; x++)
2673         {
2674                 place_monster_aux(0, yval + 1, x, what[5], PM_NO_KAGE);
2675                 place_monster_aux(0, yval - 1, x, what[5], PM_NO_KAGE);
2676         }
2677
2678         /* Next to the center monster */
2679         place_monster_aux(0, yval, xval + 1, what[6], PM_NO_KAGE);
2680         place_monster_aux(0, yval, xval - 1, what[6], PM_NO_KAGE);
2681
2682         /* Center monster */
2683         place_monster_aux(0, yval, xval, what[7], PM_NO_KAGE);
2684
2685         return TRUE;
2686 }
2687
2688
2689 /*!
2690  * @brief Vault地形を回転、上下左右反転するための座標変換を返す / coordinate translation code
2691  * @param x 変換したい点のX座標参照ポインタ
2692  * @param y 変換したい点のY座標参照ポインタ
2693  * @param xoffset Vault生成時の基準X座標
2694  * @param yoffset Vault生成時の基準Y座標
2695  * @param transno 処理ID
2696  * @return なし
2697  */
2698 static void coord_trans(POSITION *x, POSITION *y, POSITION xoffset, POSITION yoffset, int transno)
2699 {
2700         int i;
2701         int temp;
2702
2703         /*
2704          * transno specifies what transformation is required. (0-7)
2705          * The lower two bits indicate by how much the vault is rotated,
2706          * and the upper bit indicates a reflection.
2707          * This is done by using rotation matrices... however since
2708          * these are mostly zeros for rotations by 90 degrees this can
2709          * be expressed simply in terms of swapping and inverting the
2710          * x and y coordinates.
2711          */
2712         for (i = 0; i < transno % 4; i++)
2713         {
2714                 /* rotate by 90 degrees */
2715                 temp = *x;
2716                 *x = -(*y);
2717                 *y = temp;
2718         }
2719
2720         if (transno / 4)
2721         {
2722                 /* Reflect depending on status of 3rd bit. */
2723                 *x = -(*x);
2724         }
2725
2726         /* Add offsets so vault stays in the first quadrant */
2727         *x += xoffset;
2728         *y += yoffset;
2729 }
2730
2731 /*!
2732  * @brief Vaultをフロアに配置する / Hack -- fill in "vault" rooms
2733  * @param yval 生成基準Y座標
2734  * @param xval 生成基準X座標
2735  * @param ymax VaultのYサイズ
2736  * @param xmax VaultのXサイズ
2737  * @param data Vaultのデータ文字列
2738  * @param xoffset 変換基準X座標
2739  * @param yoffset 変換基準Y座標
2740  * @param transno 変換ID
2741  * @return なし
2742  */
2743 static void build_vault(POSITION yval, POSITION xval, POSITION ymax, POSITION xmax, cptr data,
2744                 POSITION xoffset, POSITION yoffset, int transno)
2745 {
2746         POSITION dx, dy, x, y, i, j;
2747         cptr t;
2748         cave_type *c_ptr;
2749
2750         /* Place dungeon features and objects */
2751         for (t = data, dy = 0; dy < ymax; dy++)
2752         {
2753                 for (dx = 0; dx < xmax; dx++, t++)
2754                 {
2755                         /* prevent loop counter from being overwritten */
2756                         i = dx;
2757                         j = dy;
2758
2759                         /* Flip / rotate */
2760                         coord_trans(&i, &j, xoffset, yoffset, transno);
2761
2762                         /* Extract the location */
2763                         if (transno % 2 == 0)
2764                         {
2765                                 /* no swap of x/y */
2766                                 x = xval - (xmax / 2) + i;
2767                                 y = yval - (ymax / 2) + j;
2768                         }
2769                         else
2770                         {
2771                                 /* swap of x/y */
2772                                 x = xval - (ymax / 2) + i;
2773                                 y = yval - (xmax / 2) + j;
2774                         }
2775
2776                         /* Hack -- skip "non-grids" */
2777                         if (*t == ' ') continue;
2778
2779                         /* Access the grid */
2780                         c_ptr = &cave[y][x];
2781
2782                         /* Lay down a floor */
2783                         place_floor_grid(c_ptr);
2784
2785                         /* Remove any mimic */
2786                         c_ptr->mimic = 0;
2787
2788                         /* Part of a vault */
2789                         c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
2790
2791                         /* Analyze the grid */
2792                         switch (*t)
2793                         {
2794                                 /* Granite wall (outer) */
2795                         case '%':
2796                                 place_outer_noperm_grid(c_ptr);
2797                                 break;
2798
2799                                 /* Granite wall (inner) */
2800                         case '#':
2801                                 place_inner_grid(c_ptr);
2802                                 break;
2803
2804                                 /* Glass wall (inner) */
2805                         case '$':
2806                                 place_inner_grid(c_ptr);
2807                                 c_ptr->feat = feat_glass_wall;
2808                                 break;
2809
2810                                 /* Permanent wall (inner) */
2811                         case 'X':
2812                                 place_inner_perm_grid(c_ptr);
2813                                 break;
2814
2815                                 /* Permanent glass wall (inner) */
2816                         case 'Y':
2817                                 place_inner_perm_grid(c_ptr);
2818                                 c_ptr->feat = feat_permanent_glass_wall;
2819                                 break;
2820
2821                                 /* Treasure/trap */
2822                         case '*':
2823                                 if (randint0(100) < 75)
2824                                 {
2825                                         place_object(y, x, 0L);
2826                                 }
2827                                 else
2828                                 {
2829                                         place_trap(y, x);
2830                                 }
2831                                 break;
2832
2833                                 /* Secret doors */
2834                         case '+':
2835                                 place_secret_door(y, x, DOOR_DEFAULT);
2836                                 break;
2837
2838                                 /* Secret glass doors */
2839                         case '-':
2840                                 place_secret_door(y, x, DOOR_GLASS_DOOR);
2841                                 if (is_closed_door(c_ptr->feat)) c_ptr->mimic = feat_glass_wall;
2842                                 break;
2843
2844                                 /* Curtains */
2845                         case '\'':
2846                                 place_secret_door(y, x, DOOR_CURTAIN);
2847                                 break;
2848
2849                                 /* Trap */
2850                         case '^':
2851                                 place_trap(y, x);
2852                                 break;
2853
2854                                 /* Black market in a dungeon */
2855                         case 'S':
2856                                 set_cave_feat(y, x, feat_black_market);
2857                                 store_init(NO_TOWN, STORE_BLACK);
2858                                 break;
2859
2860                                 /* The Pattern */
2861                         case 'p':
2862                                 set_cave_feat(y, x, feat_pattern_start);
2863                                 break;
2864
2865                         case 'a':
2866                                 set_cave_feat(y, x, feat_pattern_1);
2867                                 break;
2868
2869                         case 'b':
2870                                 set_cave_feat(y, x, feat_pattern_2);
2871                                 break;
2872
2873                         case 'c':
2874                                 set_cave_feat(y, x, feat_pattern_3);
2875                                 break;
2876
2877                         case 'd':
2878                                 set_cave_feat(y, x, feat_pattern_4);
2879                                 break;
2880
2881                         case 'P':
2882                                 set_cave_feat(y, x, feat_pattern_end);
2883                                 break;
2884
2885                         case 'B':
2886                                 set_cave_feat(y, x, feat_pattern_exit);
2887                                 break;
2888
2889                         case 'A':
2890                                 /* Reward for Pattern walk */
2891                                 object_level = base_level + 12;
2892                                 place_object(y, x, AM_GOOD | AM_GREAT);
2893                                 object_level = base_level;
2894                                 break;
2895                         }
2896                 }
2897         }
2898
2899
2900         /* Place dungeon monsters and objects */
2901         for (t = data, dy = 0; dy < ymax; dy++)
2902         {
2903                 for (dx = 0; dx < xmax; dx++, t++)
2904                 {
2905                         /* prevent loop counter from being overwritten */
2906                         i = dx;
2907                         j = dy;
2908
2909                         /* Flip / rotate */
2910                         coord_trans(&i, &j, xoffset, yoffset, transno);
2911
2912                         /* Extract the location */
2913                         if (transno % 2 == 0)
2914                         {
2915                                 /* no swap of x/y */
2916                                 x = xval - (xmax / 2) + i;
2917                                 y = yval - (ymax / 2) + j;
2918                         }
2919                         else
2920                         {
2921                                 /* swap of x/y */
2922                                 x = xval - (ymax / 2) + i;
2923                                 y = yval - (xmax / 2) + j;
2924                         }
2925
2926                         /* Hack -- skip "non-grids" */
2927                         if (*t == ' ') continue;
2928
2929                         /* Analyze the symbol */
2930                         switch (*t)
2931                         {
2932                                 /* Monster */
2933                                 case '&':
2934                                 {
2935                                         monster_level = base_level + 5;
2936                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2937                                         monster_level = base_level;
2938                                         break;
2939                                 }
2940
2941                                 /* Meaner monster */
2942                                 case '@':
2943                                 {
2944                                         monster_level = base_level + 11;
2945                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2946                                         monster_level = base_level;
2947                                         break;
2948                                 }
2949
2950                                 /* Meaner monster, plus treasure */
2951                                 case '9':
2952                                 {
2953                                         monster_level = base_level + 9;
2954                                         place_monster(y, x, PM_ALLOW_SLEEP);
2955                                         monster_level = base_level;
2956                                         object_level = base_level + 7;
2957                                         place_object(y, x, AM_GOOD);
2958                                         object_level = base_level;
2959                                         break;
2960                                 }
2961
2962                                 /* Nasty monster and treasure */
2963                                 case '8':
2964                                 {
2965                                         monster_level = base_level + 40;
2966                                         place_monster(y, x, PM_ALLOW_SLEEP);
2967                                         monster_level = base_level;
2968                                         object_level = base_level + 20;
2969                                         place_object(y, x, AM_GOOD | AM_GREAT);
2970                                         object_level = base_level;
2971                                         break;
2972                                 }
2973
2974                                 /* Monster and/or object */
2975                                 case ',':
2976                                 {
2977                                         if (randint0(100) < 50)
2978                                         {
2979                                                 monster_level = base_level + 3;
2980                                                 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2981                                                 monster_level = base_level;
2982                                         }
2983                                         if (randint0(100) < 50)
2984                                         {
2985                                                 object_level = base_level + 7;
2986                                                 place_object(y, x, 0L);
2987                                                 object_level = base_level;
2988                                         }
2989                                         break;
2990                                 }
2991
2992                         }
2993                 }
2994         }
2995 }
2996
2997
2998 /*!
2999  * @brief タイプ7の部屋…v_info.txtより小型vaultを生成する / Type 7 -- simple vaults (see "v_info.txt")
3000  * @return なし
3001  */
3002 static bool build_type7(void)
3003 {
3004         vault_type *v_ptr = NULL;
3005         int dummy;
3006         POSITION x, y;
3007         POSITION xval, yval;
3008         POSITION xoffset, yoffset;
3009         int transno;
3010
3011         /* Pick a lesser vault */
3012         for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
3013         {
3014                 /* Access a random vault record */
3015                 v_ptr = &v_info[randint0(max_v_idx)];
3016
3017                 /* Accept the first lesser vault */
3018                 if (v_ptr->typ == 7) break;
3019         }
3020
3021         /* No lesser vault found */
3022         if (dummy >= SAFE_MAX_ATTEMPTS)
3023         {
3024                 msg_print_wizard(CHEAT_DUNGEON, _("小型固定Vaultを配置できませんでした。", "Could not place lesser vault."));
3025                 return FALSE;
3026         }
3027
3028         /* pick type of transformation (0-7) */
3029         transno = randint0(8);
3030
3031         /* calculate offsets */
3032         x = v_ptr->wid;
3033         y = v_ptr->hgt;
3034
3035         /* Some huge vault cannot be ratated to fit in the dungeon */
3036         if (x+2 > cur_hgt-2)
3037         {
3038                 /* Forbid 90 or 270 degree ratation */
3039                 transno &= ~1;
3040         }
3041
3042         coord_trans(&x, &y, 0, 0, transno);
3043
3044         if (x < 0)
3045         {
3046                 xoffset = -x - 1;
3047         }
3048         else
3049         {
3050                 xoffset = 0;
3051         }
3052
3053         if (y < 0)
3054         {
3055                 yoffset = -y - 1;
3056         }
3057         else
3058         {
3059                 yoffset = 0;
3060         }
3061
3062         /* Find and reserve some space in the dungeon.  Get center of room. */
3063         if (!find_space(&yval, &xval, abs(y), abs(x))) return FALSE;
3064
3065 #ifdef FORCE_V_IDX
3066         v_ptr = &v_info[2];
3067 #endif
3068
3069         /* Message */
3070         msg_format_wizard(CHEAT_DUNGEON, _("小型Vault(%s)を生成しました。", "Lesser vault (%s)."), v_name + v_ptr->name);
3071
3072         /* Hack -- Build the vault */
3073         build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
3074                     v_text + v_ptr->text, xoffset, yoffset, transno);
3075
3076         return TRUE;
3077 }
3078
3079 /*!
3080  * @brief タイプ8の部屋…v_info.txtより大型vaultを生成する / Type 8 -- greater vaults (see "v_info.txt")
3081  * @return なし
3082  */
3083 static bool build_type8(void)
3084 {
3085         vault_type *v_ptr;
3086         int dummy;
3087         POSITION xval, yval;
3088         POSITION x, y;
3089         int transno;
3090         int xoffset, yoffset;
3091
3092         /* Pick a greater vault */
3093         for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
3094         {
3095                 /* Access a random vault record */
3096                 v_ptr = &v_info[randint0(max_v_idx)];
3097
3098                 /* Accept the first greater vault */
3099                 if (v_ptr->typ == 8) break;
3100         }
3101
3102         /* No greater vault found */
3103         if (dummy >= SAFE_MAX_ATTEMPTS)
3104         {
3105                 msg_print_wizard(CHEAT_DUNGEON, _("大型固定Vaultを配置できませんでした。", "Could not place greater vault."));
3106                 return FALSE;
3107         }
3108
3109         /* pick type of transformation (0-7) */
3110         transno = randint0(8);
3111
3112         /* calculate offsets */
3113         x = v_ptr->wid;
3114         y = v_ptr->hgt;
3115
3116         /* Some huge vault cannot be ratated to fit in the dungeon */
3117         if (x+2 > cur_hgt-2)
3118         {
3119                 /* Forbid 90 or 270 degree ratation */
3120                 transno &= ~1;
3121         }
3122
3123         coord_trans(&x, &y, 0, 0, transno);
3124
3125         if (x < 0)
3126         {
3127                 xoffset = - x - 1;
3128         }
3129         else
3130         {
3131                 xoffset = 0;
3132         }
3133
3134         if (y < 0)
3135         {
3136                 yoffset = - y - 1;
3137         }
3138         else
3139         {
3140                 yoffset = 0;
3141         }
3142
3143         /*
3144          * Try to allocate space for room.  If fails, exit
3145          *
3146          * Hack -- Prepare a bit larger space (+2, +2) to 
3147          * prevent generation of vaults with no-entrance.
3148          */
3149         /* Find and reserve some space in the dungeon.  Get center of room. */
3150         if (!find_space(&yval, &xval, (POSITION)(abs(y) + 2), (POSITION)(abs(x) + 2))) return FALSE;
3151
3152 #ifdef FORCE_V_IDX
3153         v_ptr = &v_info[76 + randint1(3)];
3154 #endif
3155
3156         msg_format_wizard(CHEAT_DUNGEON, _("大型固定Vault(%s)を生成しました。", "Greater vault (%s)."), v_name + v_ptr->name);
3157
3158         /* Hack -- Build the vault */
3159         build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
3160                     v_text + v_ptr->text, xoffset, yoffset, transno);
3161
3162         return TRUE;
3163 }
3164
3165 /*
3166  * Structure to hold all "fill" data
3167  */
3168
3169 typedef struct fill_data_type fill_data_type;
3170
3171 struct fill_data_type
3172 {
3173         /* area size */
3174         int xmin;
3175         int ymin;
3176         int xmax;
3177         int ymax;
3178
3179         /* cutoffs */
3180         int c1;
3181         int c2;
3182         int c3;
3183
3184         /* features to fill with */
3185         int feat1;
3186         int feat2;
3187         int feat3;
3188
3189         int info1;
3190         int info2;
3191         int info3;
3192
3193         /* number of filled squares */
3194         int amount;
3195 };
3196
3197 static fill_data_type fill_data;
3198
3199
3200 /* Store routine for the fractal cave generator */
3201 /* this routine probably should be an inline function or a macro. */
3202 static void store_height(int x, int y, int val)
3203 {
3204         /* if on boundary set val > cutoff so walls are not as square */
3205         if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
3206              (x == fill_data.xmax) || (y == fill_data.ymax)) &&
3207             (val <= fill_data.c1)) val = fill_data.c1 + 1;
3208
3209         /* store the value in height-map format */
3210         cave[y][x].feat = (s16b)val;
3211
3212         return;
3213 }
3214
3215
3216 /*
3217 * Explanation of the plasma fractal algorithm:
3218 *
3219 * A grid of points is created with the properties of a 'height-map'
3220 * This is done by making the corners of the grid have a random value.
3221 * The grid is then subdivided into one with twice the resolution.
3222 * The new points midway between two 'known' points can be calculated
3223 * by taking the average value of the 'known' ones and randomly adding
3224 * or subtracting an amount proportional to the distance between those
3225 * points.  The final 'middle' points of the grid are then calculated
3226 * by averaging all four of the originally 'known' corner points.  An
3227 * random amount is added or subtracted from this to get a value of the
3228 * height at that point.  The scaling factor here is adjusted to the
3229 * slightly larger distance diagonally as compared to orthogonally.
3230 *
3231 * This is then repeated recursively to fill an entire 'height-map'
3232 * A rectangular map is done the same way, except there are different
3233 * scaling factors along the x and y directions.
3234 *
3235 * A hack to change the amount of correlation between points is done using
3236 * the grd variable.  If the current step size is greater than grd then
3237 * the point will be random, otherwise it will be calculated by the
3238 * above algorithm.  This makes a maximum distance at which two points on
3239 * the height map can affect each other.
3240 *
3241 * How fractal caves are made:
3242 *
3243 * When the map is complete, a cut-off value is used to create a cave.
3244 * Heights below this value are "floor", and heights above are "wall".
3245 * This also can be used to create lakes, by adding more height levels
3246 * representing shallow and deep water/ lava etc.
3247 *
3248 * The grd variable affects the width of passages.
3249 * The roug variable affects the roughness of those passages
3250 *
3251 * The tricky part is making sure the created cave is connected.  This
3252 * is done by 'filling' from the inside and only keeping the 'filled'
3253 * floor.  Walls bounding the 'filled' floor are also kept.  Everything
3254 * else is converted to the normal _extra_.
3255  */
3256
3257
3258 /*
3259  *  Note that this uses the cave.feat array in a very hackish way
3260  *  the values are first set to zero, and then each array location
3261  *  is used as a "heightmap"
3262  *  The heightmap then needs to be converted back into the "feat" format.
3263  *
3264  *  grd=level at which fractal turns on.  smaller gives more mazelike caves
3265  *  roug=roughness level.  16=normal.  higher values make things more convoluted
3266  *    small values are good for smooth walls.
3267  *  size=length of the side of the square cave system.
3268  */
3269 static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cutoff)
3270 {
3271         int xhsize, yhsize, xsize, ysize, maxsize;
3272
3273         /*
3274          * fixed point variables- these are stored as 256 x normal value
3275          * this gives 8 binary places of fractional part + 8 places of normal part
3276          */
3277
3278         u16b xstep, xhstep, ystep, yhstep;
3279         u16b xstep2, xhstep2, ystep2, yhstep2;
3280         u16b i, j, ii, jj, diagsize, xxsize, yysize;
3281         
3282         /* Cache for speed */
3283         u16b xm, xp, ym, yp;
3284
3285         /* redefine size so can change the value if out of range */
3286         xsize = xsiz;
3287         ysize = ysiz;
3288
3289         /* Paranoia about size of the system of caves */
3290         if (xsize > 254) xsize = 254;
3291         if (xsize < 4) xsize = 4;
3292         if (ysize > 254) ysize = 254;
3293         if (ysize < 4) ysize = 4;
3294
3295         /* get offsets to middle of array */
3296         xhsize = xsize / 2;
3297         yhsize = ysize / 2;
3298
3299         /* fix rounding problem */
3300         xsize = xhsize * 2;
3301         ysize = yhsize * 2;
3302
3303         /* get limits of region */
3304         fill_data.xmin = x0 - xhsize;
3305         fill_data.ymin = y0 - yhsize;
3306         fill_data.xmax = x0 + xhsize;
3307         fill_data.ymax = y0 + yhsize;
3308
3309         /* Store cutoff in global for quick access */
3310         fill_data.c1 = cutoff;
3311
3312         /*
3313         * Scale factor for middle points:
3314         * About sqrt(2) * 256 - correct for a square lattice
3315         * approximately correct for everything else.
3316          */
3317         diagsize = 362;
3318
3319         /* maximum of xsize and ysize */
3320         maxsize = (xsize > ysize) ? xsize : ysize;
3321
3322         /* Clear the section */
3323         for (i = 0; i <= xsize; i++)
3324         {
3325                 for (j = 0; j <= ysize; j++)
3326                 {
3327                         /* -1 is a flag for "not done yet" */
3328                         cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
3329                         /* Clear icky flag because may be redoing the cave */
3330                         cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
3331                 }
3332         }
3333
3334         /* Boundaries are walls */
3335         cave[fill_data.ymin][fill_data.xmin].feat = (s16b)maxsize;
3336         cave[fill_data.ymax][fill_data.xmin].feat = (s16b)maxsize;
3337         cave[fill_data.ymin][fill_data.xmax].feat = (s16b)maxsize;
3338         cave[fill_data.ymax][fill_data.xmax].feat = (s16b)maxsize;
3339
3340         /* Set the middle square to be an open area. */
3341         cave[y0][x0].feat = 0;
3342
3343         /* Initialize the step sizes */
3344         xstep = xhstep = xsize * 256;
3345         ystep = yhstep = ysize * 256;
3346         xxsize = xsize * 256;
3347         yysize = ysize * 256;
3348
3349         /*
3350          * Fill in the rectangle with fractal height data -
3351          * like the 'plasma fractal' in fractint.
3352          */
3353         while ((xhstep > 256) || (yhstep > 256))
3354         {
3355                 /* Halve the step sizes */
3356                 xstep = xhstep;
3357                 xhstep /= 2;
3358                 ystep = yhstep;
3359                 yhstep /= 2;
3360
3361                 /* cache well used values */
3362                 xstep2 = xstep / 256;
3363                 ystep2 = ystep / 256;
3364
3365                 xhstep2 = xhstep / 256;
3366                 yhstep2 = yhstep / 256;
3367
3368                 /* middle top to bottom. */
3369                 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3370                 {
3371                         for (j = 0; j <= yysize; j += ystep)
3372                         {
3373                                 /* cache often used values */
3374                                 ii = i / 256 + fill_data.xmin;
3375                                 jj = j / 256 + fill_data.ymin;
3376
3377                                 /* Test square */
3378                                 if (cave[jj][ii].feat == -1)
3379                                 {
3380                                         if (xhstep2 > grd)
3381                                         {
3382                                                 /* If greater than 'grid' level then is random */
3383                                                 store_height(ii, jj, randint1(maxsize));
3384                                         }
3385                                         else
3386                                         {
3387                                                 /* Average of left and right points +random bit */
3388                                                 store_height(ii, jj,
3389                                                         (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
3390                                                          + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
3391                                                          + (randint1(xstep2) - xhstep2) * roug / 16);
3392                                         }
3393                                 }
3394                         }
3395                 }
3396
3397
3398                 /* middle left to right. */
3399                 for (j = yhstep; j <= yysize - yhstep; j += ystep)
3400                 {
3401                         for (i = 0; i <= xxsize; i += xstep)
3402                         {
3403                                 /* cache often used values */
3404                                 ii = i / 256 + fill_data.xmin;
3405                                 jj = j / 256 + fill_data.ymin;
3406
3407                                 /* Test square */
3408                                 if (cave[jj][ii].feat == -1)
3409                                 {
3410                                         if (xhstep2 > grd)
3411                                         {
3412                                                 /* If greater than 'grid' level then is random */
3413                                                 store_height(ii, jj, randint1(maxsize));
3414                                         }
3415                                         else
3416                                         {
3417                                                 /* Average of up and down points +random bit */
3418                                                 store_height(ii, jj,
3419                                                         (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
3420                                                         + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
3421                                                         + (randint1(ystep2) - yhstep2) * roug / 16);
3422                                         }
3423                                 }
3424                         }
3425                 }
3426
3427                 /* center. */
3428                 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3429                 {
3430                         for (j = yhstep; j <= yysize - yhstep; j += ystep)
3431                         {
3432                                 /* cache often used values */
3433                                 ii = i / 256 + fill_data.xmin;
3434                                 jj = j / 256 + fill_data.ymin;
3435
3436                                 /* Test square */
3437                                 if (cave[jj][ii].feat == -1)
3438                                 {
3439                                         if (xhstep2 > grd)
3440                                         {
3441                                                 /* If greater than 'grid' level then is random */
3442                                                 store_height(ii, jj, randint1(maxsize));
3443                                         }
3444                                         else
3445                                         {
3446                                                 /* Cache reused values. */
3447                                                 xm = fill_data.xmin + (i - xhstep) / 256;
3448                                                 xp = fill_data.xmin + (i + xhstep) / 256;
3449                                                 ym = fill_data.ymin + (j - yhstep) / 256;
3450                                                 yp = fill_data.ymin + (j + yhstep) / 256;
3451
3452                                                 /* 
3453                                                  * Average over all four corners + scale by diagsize to
3454                                                  * reduce the effect of the square grid on the shape of the fractal
3455                                                  */
3456                                                 store_height(ii, jj,
3457                                                         (cave[ym][xm].feat + cave[yp][xm].feat
3458                                                         + cave[ym][xp].feat + cave[yp][xp].feat) / 4
3459                                                         + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
3460                                         }
3461                                 }
3462                         }
3463                 }
3464         }
3465 }
3466
3467
3468 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)
3469 {
3470         /*
3471          * function used to convert from height-map back to the
3472          *  normal angband cave format
3473          */
3474         if (cave[y][x].info & CAVE_ICKY)
3475         {
3476                 /* already done */
3477                 return FALSE;
3478         }
3479         else
3480         {
3481                 /* Show that have looked at this square */
3482                 cave[y][x].info|= (CAVE_ICKY);
3483
3484                 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
3485                 if (cave[y][x].feat <= c1)
3486                 {
3487                         /* 25% of the time use the other tile : it looks better this way */
3488                         if (randint1(100) < 75)
3489                         {
3490                                 cave[y][x].feat = (s16b)feat1;
3491                                 cave[y][x].info &= ~(CAVE_MASK);
3492                                 cave[y][x].info |= info1;
3493                                 return TRUE;
3494                         }
3495                         else
3496                         {
3497                                 cave[y][x].feat = (s16b)feat2;
3498                                 cave[y][x].info &= ~(CAVE_MASK);
3499                                 cave[y][x].info |= info2;
3500                                 return TRUE;
3501                         }
3502                 }
3503                 else if (cave[y][x].feat <= c2)
3504                 {
3505                         /* 25% of the time use the other tile : it looks better this way */
3506                         if (randint1(100) < 75)
3507                         {
3508                                 cave[y][x].feat = (s16b)feat2;
3509                                 cave[y][x].info &= ~(CAVE_MASK);
3510                                 cave[y][x].info |= info2;
3511                                 return TRUE;
3512                         }
3513                         else
3514                         {
3515                                 cave[y][x].feat = (s16b)feat1;
3516                                 cave[y][x].info &= ~(CAVE_MASK);
3517                                 cave[y][x].info |= info1;
3518                                 return TRUE;
3519                         }
3520                 }
3521                 else if (cave[y][x].feat <= c3)
3522                 {
3523                         cave[y][x].feat = (s16b)feat3;
3524                         cave[y][x].info &= ~(CAVE_MASK);
3525                         cave[y][x].info |= info3;
3526                         return TRUE;
3527                 }
3528                 /* if greater than cutoff then is a wall */
3529                 else
3530                 {
3531                         place_outer_bold(y, x);
3532                         return FALSE;
3533                 }
3534         }
3535 }
3536
3537
3538
3539
3540 /*
3541  * Quick and nasty fill routine used to find the connected region
3542  * of floor in the middle of the cave
3543  */
3544 static void cave_fill(POSITION y, POSITION x)
3545 {
3546         int i, j, d;
3547         int ty, tx;
3548
3549         int flow_tail = 1;
3550         int flow_head = 0;
3551
3552
3553         /*** Start Grid ***/
3554
3555         /* Enqueue that entry */
3556         temp_y[0] = y;
3557         temp_x[0] = x;
3558
3559
3560         /* Now process the queue */
3561         while (flow_head != flow_tail)
3562         {
3563                 /* Extract the next entry */
3564                 ty = temp_y[flow_head];
3565                 tx = temp_x[flow_head];
3566
3567                 /* Forget that entry */
3568                 if (++flow_head == TEMP_MAX) flow_head = 0;
3569
3570                 /* Add the "children" */
3571                 for (d = 0; d < 8; d++)
3572                 {
3573                         int old_head = flow_tail;
3574
3575                         /* Child location */
3576                         j = ty + ddy_ddd[d];
3577                         i = tx + ddx_ddd[d];
3578
3579                         /* Paranoia Don't leave the cave */
3580                         if (!in_bounds(j, i))
3581                         {
3582                                 /* affect boundary */
3583                                 cave[j][i].info |= CAVE_ICKY;
3584 /*                              return; */
3585                         }
3586
3587                         /* If within bounds */
3588                         else if ((i > fill_data.xmin) && (i < fill_data.xmax)
3589                                 && (j > fill_data.ymin) && (j < fill_data.ymax))
3590                         {
3591                                 /* If not a wall or floor done before */
3592                                 if (hack_isnt_wall(j, i,
3593                                         fill_data.c1, fill_data.c2, fill_data.c3,
3594                                         fill_data.feat1, fill_data.feat2, fill_data.feat3,
3595                                         fill_data.info1, fill_data.info2, fill_data.info3))
3596                                 {
3597                                         /* Enqueue that entry */
3598                                         temp_y[flow_tail] = (byte_hack)j;
3599                                         temp_x[flow_tail] = (byte_hack)i;
3600
3601                                         /* Advance the queue */
3602                                         if (++flow_tail == TEMP_MAX) flow_tail = 0;
3603
3604                                         /* Hack -- Overflow by forgetting new entry */
3605                                         if (flow_tail == flow_head)
3606                                         {
3607                                                 flow_tail = old_head;
3608                                         }
3609                                         else
3610                                         {
3611                                                 /* keep tally of size of cave system */
3612                                                 (fill_data.amount)++;
3613                                         }
3614                                 }
3615                         }
3616                         else
3617                         {
3618                                 /* affect boundary */
3619                                 cave[j][i].info |= CAVE_ICKY;
3620                         }
3621                 }
3622         }
3623 }
3624
3625
3626 static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
3627 {
3628         int x, y, i, xhsize, yhsize;
3629
3630         /* offsets to middle from corner */
3631         xhsize = xsize / 2;
3632         yhsize = ysize / 2;
3633
3634
3635         /*
3636          * select region connected to center of cave system
3637          * this gets rid of alot of isolated one-sqaures that
3638          * can make teleport traps instadeaths...
3639          */
3640
3641         /* cutoffs */
3642         fill_data.c1 = cutoff;
3643         fill_data.c2 = 0;
3644         fill_data.c3 = 0;
3645
3646         /* features to fill with */
3647         fill_data.feat1 = floor_type[randint0(100)];
3648         fill_data.feat2 = floor_type[randint0(100)];
3649         fill_data.feat3 = floor_type[randint0(100)];
3650
3651         fill_data.info1 = CAVE_FLOOR;
3652         fill_data.info2 = CAVE_FLOOR;
3653         fill_data.info3 = CAVE_FLOOR;
3654
3655         /* number of filled squares */
3656         fill_data.amount = 0;
3657
3658         cave_fill((byte)y0, (byte)x0);
3659
3660         /* if tally too small, try again */
3661         if (fill_data.amount < 10)
3662         {
3663                 /* too small - clear area and try again later */
3664                 for (x = 0; x <= xsize; ++x)
3665                 {
3666                         for (y = 0; y <= ysize; ++y)
3667                         {
3668                                 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3669                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3670                         }
3671                 }
3672                 return FALSE;
3673         }
3674
3675         /*
3676          * Do boundarys-check to see if they are next to a filled region
3677          * If not then they are set to normal granite
3678          * If so then they are marked as room walls.
3679          */
3680         for (i = 0; i <= xsize; ++i)
3681         {
3682                 /* top boundary */
3683                 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3684                 {
3685                         /* Next to a 'filled' region? - set to be room walls */
3686                         place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3687                         if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
3688                         cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
3689                         place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3690                 }
3691                 else
3692                 {
3693                         /* set to be normal granite */
3694                         place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3695                 }
3696
3697                 /* bottom boundary */
3698                 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3699                 {
3700                         /* Next to a 'filled' region? - set to be room walls */
3701                         place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3702                         if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
3703                         cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
3704                         place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3705                 }
3706                 else
3707                 {
3708                         /* set to be normal granite */
3709                         place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3710                 }
3711
3712                 /* clear the icky flag-don't need it any more */
3713                 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3714                 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3715         }
3716
3717         /* Do the left and right boundaries minus the corners (done above) */
3718         for (i = 1; i < ysize; ++i)
3719         {
3720                 /* left boundary */
3721                 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
3722                 {
3723                         /* room boundary */
3724                         place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3725                         if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
3726                         cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
3727                         place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3728                 }
3729                 else
3730                 {
3731                         /* outside room */
3732                         place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3733                 }
3734                 /* right boundary */
3735                 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
3736                 {
3737                         /* room boundary */
3738                         place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3739                         if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
3740                         cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
3741                         place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3742                 }
3743                 else
3744                 {
3745                         /* outside room */
3746                         place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3747                 }
3748
3749                 /* clear icky flag -done with it */
3750                 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3751                 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3752         }
3753
3754
3755         /* Do the rest: convert back to the normal format */
3756         for (x = 1; x < xsize; ++x)
3757         {
3758                 for (y = 1; y < ysize; ++y)
3759                 {
3760                         if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3761                             (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3762                         {
3763                                 /* Clear the icky flag in the filled region */
3764                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
3765
3766                                 /* Set appropriate flags */
3767                                 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3768                                 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3769                         }
3770                         else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3771                                  (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3772                         {
3773                                 /* Walls */
3774                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3775                                 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3776                                 if (room)
3777                                 {
3778                                         cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3779                                 }
3780                                 else
3781                                 {
3782
3783                                         place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3784                                         cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
3785                                 }
3786                         }
3787                         else
3788                         {
3789                                 /* Clear the unconnected regions */
3790                                 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3791                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3792                         }
3793                 }
3794         }
3795
3796         /*
3797          * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
3798          * Extra doors appear inside the system.  (Its not very noticeable though.)
3799          * This can be removed by "filling" from the outside in.  This allows a separation
3800          * from _outer_ with _inner_.  (Internal walls are  _outer_ instead.)
3801          * The extra effort for what seems to be only a minor thing (even non-existant if you
3802          * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
3803          * worth it.
3804          */
3805
3806         return TRUE;
3807 }
3808
3809
3810 /*!
3811  * @brief タイプ9の部屋…フラクタルカーブによる洞窟生成 / Type 9 -- Driver routine to create fractal cave system
3812  * @return なし
3813  */
3814 static bool build_type9(void)
3815 {
3816         int grd, roug, cutoff;
3817         POSITION xsize, ysize, y0, x0;
3818
3819         bool done, light, room;
3820
3821         /* get size: note 'Evenness'*/
3822         xsize = randint1(22) * 2 + 6;
3823         ysize = randint1(15) * 2 + 6;
3824
3825         /* Find and reserve some space in the dungeon.  Get center of room. */
3826         if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3827         {
3828                 /* Limit to the minimum room size, and retry */
3829                 xsize = 8;
3830                 ysize = 8;
3831
3832                 /* Find and reserve some space in the dungeon.  Get center of room. */
3833                 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3834                 {
3835                         /*
3836                          * Still no space?!
3837                          * Try normal room
3838                          */
3839                         return build_type1();
3840                 }
3841         }
3842
3843         light = done = FALSE;
3844         room = TRUE;
3845
3846         if ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3847
3848         while (!done)
3849         {
3850                 /* Note: size must be even or there are rounding problems
3851                 * This causes the tunnels not to connect properly to the room */
3852
3853                 /* testing values for these parameters feel free to adjust */
3854                 grd = 1 << (randint0(4));
3855
3856                 /* want average of about 16 */
3857                 roug = randint1(8) * randint1(4);
3858
3859                 /* about size/2 */
3860                 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
3861                          randint1(xsize / 4) + randint1(ysize / 4);
3862
3863                 /* make it */
3864                 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
3865
3866                 /* Convert to normal format + clean up */
3867                 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
3868         }
3869
3870         return TRUE;
3871 }
3872
3873 #ifdef ALLOW_CAVERNS_AND_LAKES
3874 /*
3875  * Builds a cave system in the center of the dungeon.
3876  */
3877 void build_cavern(void)
3878 {
3879         int grd, roug, cutoff, xsize, ysize, x0, y0;
3880         bool done, light;
3881
3882         light = done = FALSE;
3883         if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3884
3885         /* Make a cave the size of the dungeon */
3886         xsize = cur_wid - 1;
3887         ysize = cur_hgt - 1;
3888         x0 = xsize / 2;
3889         y0 = ysize / 2;
3890
3891         /* Paranoia: make size even */
3892         xsize = x0 * 2;
3893         ysize = y0 * 2;
3894
3895         while (!done)
3896         {
3897                 /* testing values for these parameters: feel free to adjust */
3898                 grd = randint1(4) + 4;
3899
3900                 /* want average of about 16 */
3901                 roug = randint1(8) * randint1(4);
3902
3903                 /* about size/2 */
3904                 cutoff = xsize / 2;
3905
3906                  /* make it */
3907                 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
3908
3909                 /* Convert to normal format+ clean up */
3910                 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
3911         }
3912 }
3913
3914 static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
3915 {
3916         int x, y, i, xhsize, yhsize;
3917         int feat1, feat2, feat3;
3918
3919         /* offsets to middle from corner */
3920         xhsize = xsize / 2;
3921         yhsize = ysize / 2;
3922
3923         /* Get features based on type */
3924         switch (type)
3925         {
3926         case LAKE_T_LAVA: /* Lava */
3927                 feat1 = feat_deep_lava;
3928                 feat2 = feat_shallow_lava;
3929                 feat3 = floor_type[randint0(100)];
3930                 break;
3931         case LAKE_T_WATER: /* Water */
3932                 feat1 = feat_deep_water;
3933                 feat2 = feat_shallow_water;
3934                 feat3 = floor_type[randint0(100)];
3935                 break;
3936         case LAKE_T_CAVE: /* Collapsed cave */
3937                 feat1 = floor_type[randint0(100)];
3938                 feat2 = floor_type[randint0(100)];
3939                 feat3 = feat_rubble;
3940                 break;
3941         case LAKE_T_EARTH_VAULT: /* Earth vault */
3942                 feat1 = feat_rubble;
3943                 feat2 = floor_type[randint0(100)];
3944                 feat3 = feat_rubble;
3945                 break;
3946         case LAKE_T_AIR_VAULT: /* Air vault */
3947                 feat1 = feat_grass;
3948                 feat2 = feat_tree;
3949                 feat3 = feat_grass;
3950                 break;
3951         case LAKE_T_WATER_VAULT: /* Water vault */
3952                 feat1 = feat_shallow_water;
3953                 feat2 = feat_deep_water;
3954                 feat3 = feat_shallow_water;
3955                 break;
3956         case LAKE_T_FIRE_VAULT: /* Fire Vault */
3957                 feat1 = feat_shallow_lava;
3958                 feat2 = feat_deep_lava;
3959                 feat3 = feat_shallow_lava;
3960                 break;
3961
3962         /* Paranoia */
3963         default: return FALSE;
3964         }
3965
3966         /*
3967          * select region connected to center of cave system
3968          * this gets rid of alot of isolated one-sqaures that
3969          * can make teleport traps instadeaths...
3970          */
3971
3972         /* cutoffs */
3973         fill_data.c1 = c1;
3974         fill_data.c2 = c2;
3975         fill_data.c3 = c3;
3976
3977         /* features to fill with */
3978         fill_data.feat1 = feat1;
3979         fill_data.feat2 = feat2;
3980         fill_data.feat3 = feat3;
3981
3982         fill_data.info1 = 0;
3983         fill_data.info2 = 0;
3984         fill_data.info3 = 0;
3985
3986         /* number of filled squares */
3987         fill_data.amount = 0;
3988
3989         /* select region connected to center of cave system
3990         * this gets rid of alot of isolated one-sqaures that
3991         * can make teleport traps instadeaths... */
3992         cave_fill((byte)y0, (byte)x0);
3993
3994         /* if tally too small, try again */
3995         if (fill_data.amount < 10)
3996         {
3997                 /* too small -clear area and try again later */
3998                 for (x = 0; x <= xsize; ++x)
3999                 {
4000                         for (y = 0; y <= ysize; ++y)
4001                         {
4002                                 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
4003                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
4004                         }
4005                 }
4006                 return FALSE;
4007         }
4008
4009         /* Do boundarys- set to normal granite */
4010         for (i = 0; i <= xsize; ++i)
4011         {
4012                 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
4013                 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
4014
4015                 /* clear the icky flag-don't need it any more */
4016                 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
4017                 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
4018         }
4019
4020         /* Do the left and right boundaries minus the corners (done above) */
4021
4022         for (i = 1; i < ysize; ++i)
4023         {
4024                 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
4025                 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
4026
4027                 /* clear icky flag -done with it */
4028                 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
4029                 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
4030         }
4031
4032
4033         /* Do the rest: convert back to the normal format */
4034         for (x = 1; x < xsize; ++x)
4035         {
4036                 for (y = 1; y < ysize; ++y)
4037                 {
4038                         /* Fill unconnected regions with granite */
4039                         if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
4040                                 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
4041                                 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
4042
4043                         /* turn off icky flag (no longer needed.) */
4044                         cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
4045
4046                         /* Light lava */
4047                         if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
4048                         {
4049                                 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
4050                         }
4051                 }
4052         }
4053
4054         return TRUE;
4055 }
4056
4057
4058 /*
4059  * makes a lake/collapsed cave system in the center of the dungeon
4060  */
4061 void build_lake(int type)
4062 {
4063         int grd, roug, xsize, ysize, x0, y0;
4064         bool done = FALSE;
4065         int c1, c2, c3;
4066
4067         /* paranoia - exit if lake type out of range. */
4068         if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
4069         {
4070                 msg_format("Invalid lake type (%d)", type);
4071                 return;
4072         }
4073
4074         /* Make the size of the dungeon */
4075         xsize = cur_wid - 1;
4076         ysize = cur_hgt - 1;
4077         x0 = xsize / 2;
4078         y0 = ysize / 2;
4079
4080         /* Paranoia: make size even */
4081         xsize = x0 * 2;
4082         ysize = y0 * 2;
4083
4084         while (!done)
4085         {
4086                 /* testing values for these parameters: feel free to adjust */
4087                 grd = randint1(3) + 4;
4088
4089                 /* want average of about 16 */
4090                 roug = randint1(8) * randint1(4);
4091
4092                 /* Make up size of various componants */
4093                 /* Floor */
4094                 c3 = 3 * xsize / 4;
4095
4096                 /* Deep water/lava */
4097                 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
4098
4099                 /* Shallow boundary */
4100                 c2 = (c1 + c3) / 2;
4101
4102                 /* make it */
4103                 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
4104
4105                 /* Convert to normal format+ clean up */
4106                 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
4107         }
4108 }
4109 #endif /* ALLOW_CAVERNS_AND_LAKES */
4110
4111
4112 /*
4113  * Routine used by the random vault creators to add a door to a location
4114  * Note that range checking has to be done in the calling routine.
4115  *
4116  * The doors must be INSIDE the allocated region.
4117  */
4118 static void add_door(int x, int y)
4119 {
4120         /* Need to have a wall in the center square */
4121         if (!is_outer_bold(y, x)) return;
4122
4123         /* look at:
4124          *  x#x
4125          *  .#.
4126          *  x#x
4127          *
4128          *  where x=don't care
4129          *  .=floor, #=wall
4130          */
4131
4132         if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
4133             (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
4134         {
4135                 /* secret door */
4136                 place_secret_door(y, x, DOOR_DEFAULT);
4137
4138                 /* set boundarys so don't get wide doors */
4139                 place_solid_bold(y, x - 1);
4140                 place_solid_bold(y, x + 1);
4141         }
4142
4143
4144         /* look at:
4145          *  x#x
4146          *  .#.
4147          *  x#x
4148          *
4149          *  where x = don't care
4150          *  .=floor, #=wall
4151          */
4152         if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
4153             is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
4154         {
4155                 /* secret door */
4156                 place_secret_door(y, x, DOOR_DEFAULT);
4157
4158                 /* set boundarys so don't get wide doors */
4159                 place_solid_bold(y - 1, x);
4160                 place_solid_bold(y + 1, x);
4161         }
4162 }
4163
4164
4165 /*
4166  * Routine that fills the empty areas of a room with treasure and monsters.
4167  */
4168 static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
4169 {
4170         int x, y, cx, cy, size;
4171         s32b value;
4172
4173         /* center of room:*/
4174         cx = (x1 + x2) / 2;
4175         cy = (y1 + y2) / 2;
4176
4177         /* Rough measure of size of vault= sum of lengths of sides */
4178         size = abs(x2 - x1) + abs(y2 - y1);
4179
4180         for (x = x1; x <= x2; x++)
4181         {
4182                 for (y = y1; y <= y2; y++)
4183                 {
4184                         /* Thing added based on distance to center of vault
4185                          * Difficulty is 1-easy to 10-hard */
4186                         value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
4187
4188                         /* hack- empty square part of the time */
4189                         if ((randint1(100) - difficulty * 3) > 50) value = 20;
4190
4191                          /* if floor, shallow water and lava */
4192                         if (is_floor_bold(y, x) ||
4193                             (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
4194                         {
4195                                 /* The smaller 'value' is, the better the stuff */
4196                                 if (value < 0)
4197                                 {
4198                                         /* Meanest monster + treasure */
4199                                         monster_level = base_level + 40;
4200                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4201                                         monster_level = base_level;
4202                                         object_level = base_level + 20;
4203                                         place_object(y, x, AM_GOOD);
4204                                         object_level = base_level;
4205                                 }
4206                                 else if (value < 5)
4207                                 {
4208                                         /* Mean monster +treasure */
4209                                         monster_level = base_level + 20;
4210                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4211                                         monster_level = base_level;
4212                                         object_level = base_level + 10;
4213                                         place_object(y, x, AM_GOOD);
4214                                         object_level = base_level;
4215                                 }
4216                                 else if (value < 10)
4217                                 {
4218                                         /* Monster */
4219                                         monster_level = base_level + 9;
4220                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4221                                         monster_level = base_level;
4222                                 }
4223                                 else if (value < 17)
4224                                 {
4225                                         /* Intentional Blank space */
4226
4227                                         /*
4228                                          * (Want some of the vault to be empty
4229                                          * so have room for group monsters.
4230                                          * This is used in the hack above to lower
4231                                          * the density of stuff in the vault.)
4232                                          */
4233                                 }
4234                                 else if (value < 23)
4235                                 {
4236                                         /* Object or trap */
4237                                         if (randint0(100) < 25)
4238                                         {
4239                                                 place_object(y, x, 0L);
4240                                         }
4241                                         else
4242                                         {
4243                                                 place_trap(y, x);
4244                                         }
4245                                 }
4246                                 else if (value < 30)
4247                                 {
4248                                         /* Monster and trap */
4249                                         monster_level = base_level + 5;
4250                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4251                                         monster_level = base_level;
4252                                         place_trap(y, x);
4253                                 }
4254                                 else if (value < 40)
4255                                 {
4256                                         /* Monster or object */
4257                                         if (randint0(100) < 50)
4258                                         {
4259                                                 monster_level = base_level + 3;
4260                                                 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4261                                                 monster_level = base_level;
4262                                         }
4263                                         if (randint0(100) < 50)
4264                                         {
4265                                                 object_level = base_level + 7;
4266                                                 place_object(y, x, 0L);
4267                                                 object_level = base_level;
4268                                         }
4269                                 }
4270                                 else if (value < 50)
4271                                 {
4272                                         /* Trap */
4273                                         place_trap(y, x);
4274                                 }
4275                                 else
4276                                 {
4277                                         /* Various Stuff */
4278
4279                                         /* 20% monster, 40% trap, 20% object, 20% blank space */
4280                                         if (randint0(100) < 20)
4281                                         {
4282                                                 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4283                                         }
4284                                         else if (randint0(100) < 50)
4285                                         {
4286                                                 place_trap(y, x);
4287                                         }
4288                                         else if (randint0(100) < 50)
4289                                         {
4290                                                 place_object(y, x, 0L);
4291                                         }
4292                                 }
4293
4294                         }
4295                 }
4296         }
4297 }
4298
4299
4300 /*
4301  * This function creates a random vault that looks like a collection of bubbles.
4302  * It works by getting a set of coordinates that represent the center of each
4303  * bubble.  The entire room is made by seeing which bubble center is closest. If
4304  * two centers are equidistant then the square is a wall, otherwise it is a floor.
4305  * The only exception is for squares really near a center, these are always floor.
4306  * (It looks better than without this check.)
4307  *
4308  * Note: If two centers are on the same point then this algorithm will create a
4309  *       blank bubble filled with walls. - This is prevented from happening.
4310  */
4311 static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
4312 {
4313         #define BUBBLENUM 10            /* number of bubbles */
4314
4315         /* array of center points of bubbles */
4316         coord center[BUBBLENUM];
4317
4318         int i, j, x, y;
4319         u16b min1, min2, temp;
4320         bool done;
4321
4322         /* Offset from center to top left hand corner */
4323         int xhsize = xsize / 2;
4324         int yhsize = ysize / 2;
4325
4326         msg_print_wizard(CHEAT_DUNGEON, _("泡型ランダムVaultを生成しました。", "Room Vault."));
4327
4328         /* Allocate center of bubbles */
4329         center[0].x = (byte)randint1(xsize - 3) + 1;
4330         center[0].y = (byte)randint1(ysize - 3) + 1;
4331
4332         for (i = 1; i < BUBBLENUM; i++)
4333         {
4334                 done = FALSE;
4335
4336                 /* get center and check to see if it is unique */
4337                 while (!done)
4338                 {
4339                         done = TRUE;
4340
4341                         x = randint1(xsize - 3) + 1;
4342                         y = randint1(ysize - 3) + 1;
4343
4344                         for (j = 0; j < i; j++)
4345                         {
4346                                 /* rough test to see if there is an overlap */
4347                                 if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
4348                         }
4349                 }
4350
4351                 center[i].x = (byte_hack)x;
4352                 center[i].y = (byte_hack)y;
4353         }
4354
4355
4356         /* Top and bottom boundaries */
4357         for (i = 0; i < xsize; i++)
4358         {
4359                 int side_x = x0 - xhsize + i;
4360
4361                 place_outer_noperm_bold(y0 - yhsize + 0, side_x);
4362                 cave[y0 - yhsize + 0][side_x].info |= (CAVE_ROOM | CAVE_ICKY);
4363                 place_outer_noperm_bold(y0 - yhsize + ysize - 1, side_x);
4364                 cave[y0 - yhsize + ysize - 1][side_x].info |= (CAVE_ROOM | CAVE_ICKY);
4365         }
4366
4367         /* Left and right boundaries */
4368         for (i = 1; i < ysize - 1; i++)
4369         {
4370                 int side_y = y0 - yhsize + i;
4371
4372                 place_outer_noperm_bold(side_y, x0 - xhsize + 0);
4373                 cave[side_y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
4374                 place_outer_noperm_bold(side_y, x0 - xhsize + xsize - 1);
4375                 cave[side_y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
4376         }
4377
4378         /* Fill in middle with bubbles */
4379         for (x = 1; x < xsize - 1; x++)
4380         {
4381                 for (y = 1; y < ysize - 1; y++)
4382                 {
4383                         /* Get distances to two closest centers */
4384
4385                         /* initialize */
4386                         min1 = (u16b)distance(x, y, center[0].x, center[0].y);
4387                         min2 = (u16b)distance(x, y, center[1].x, center[1].y);
4388
4389                         if (min1 > min2)
4390                         {
4391                                 /* swap if in wrong order */
4392                                 temp = min1;
4393                                 min1 = min2;
4394                                 min2 = temp;
4395                         }
4396
4397                         /* Scan the rest */
4398                         for (i = 2; i < BUBBLENUM; i++)
4399                         {
4400                                 temp = (u16b)distance(x, y, center[i].x, center[i].y);
4401
4402                                 if (temp < min1)
4403                                 {
4404                                         /* smallest */
4405                                         min2 = min1;
4406                                         min1 = temp;
4407                                 }
4408                                 else if (temp < min2)
4409                                 {
4410                                         /* second smallest */
4411                                         min2 = temp;
4412                                 }
4413                         }
4414                         if (((min2 - min1) <= 2) && (!(min1 < 3)))
4415                         {
4416                                 /* Boundary at midpoint+ not at inner region of bubble */
4417                                 place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
4418                         }
4419                         else
4420                         {
4421                                 /* middle of a bubble */
4422                                 place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
4423                         }
4424
4425                         /* clean up rest of flags */
4426                         cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
4427                 }
4428         }
4429
4430         /* Try to add some random doors */
4431         for (i = 0; i < 500; i++)
4432         {
4433                 x = randint1(xsize - 3) - xhsize + x0 + 1;
4434                 y = randint1(ysize - 3) - yhsize + y0 + 1;
4435                 add_door(x, y);
4436         }
4437
4438         /* Fill with monsters and treasure, low difficulty */
4439         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
4440 }
4441
4442
4443 /*
4444  * Overlay a rectangular room given its bounds
4445  * This routine is used by build_room_vault
4446  * The area inside the walls is not touched:
4447  * only granite is removed- normal walls stay
4448  */
4449 static void build_room(int x1, int x2, int y1, int y2)
4450 {
4451         int x, y, i, xsize, ysize, temp;
4452
4453         /* Check if rectangle has no width */
4454         if ((x1 == x2) || (y1 == y2)) return;
4455
4456         /* initialize */
4457         if (x1 > x2)
4458         {
4459                 /* Swap boundaries if in wrong order */
4460                 temp = x1;
4461                 x1 = x2;
4462                 x2 = temp;
4463         }
4464
4465         if (y1 > y2)
4466         {
4467                 /* Swap boundaries if in wrong order */
4468                 temp = y1;
4469                 y1 = y2;
4470                 y2 = temp;
4471         }
4472
4473         /* get total widths */
4474         xsize = x2 - x1;
4475         ysize = y2 - y1;
4476
4477
4478         /* Top and bottom boundaries */
4479         for (i = 0; i <= xsize; i++)
4480         {
4481                 place_outer_noperm_bold(y1, x1 + i);
4482                 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4483                 place_outer_noperm_bold(y2, x1 + i);
4484                 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4485         }
4486
4487         /* Left and right boundaries */
4488         for (i = 1; i < ysize; i++)
4489         {
4490                 place_outer_noperm_bold(y1 + i, x1);
4491                 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
4492                 place_outer_noperm_bold(y1 + i, x2);
4493                 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
4494         }
4495
4496         /* Middle */
4497         for (x = 1; x < xsize; x++)
4498         {
4499                 for (y = 1; y < ysize; y++)
4500                 {
4501                         if (is_extra_bold(y1+y, x1+x))
4502                         {
4503                                 /* clear the untouched region */
4504                                 place_floor_bold(y1 + y, x1 + x);
4505                                 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4506                         }
4507                         else
4508                         {
4509                                 /* make it a room- but don't touch */
4510                                 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4511                         }
4512                 }
4513         }
4514 }
4515
4516
4517 /* Create a random vault that looks like a collection of overlapping rooms */
4518
4519 static void build_room_vault(int x0, int y0, int xsize, int ysize)
4520 {
4521         int i, x1, x2, y1, y2, xhsize, yhsize;
4522
4523         /* get offset from center */
4524         xhsize = xsize / 2;
4525         yhsize = ysize / 2;
4526
4527         msg_print_wizard(CHEAT_DUNGEON, _("部屋型ランダムVaultを生成しました。", "Room Vault."));
4528
4529         /* fill area so don't get problems with arena levels */
4530         for (x1 = 0; x1 < xsize; x1++)
4531         {
4532                 int x = x0 - xhsize + x1;
4533
4534                 for (y1 = 0; y1 < ysize; y1++)
4535                 {
4536                         int y = y0 - yhsize + y1;
4537
4538                         place_extra_bold(y, x);
4539                         cave[y][x].info &= (~CAVE_ICKY);
4540                 }
4541         }
4542
4543         /* add ten random rooms */
4544         for (i = 0; i < 10; i++)
4545         {
4546                 x1 = randint1(xhsize) * 2 + x0 - xhsize;
4547                 x2 = randint1(xhsize) * 2 + x0 - xhsize;
4548                 y1 = randint1(yhsize) * 2 + y0 - yhsize;
4549                 y2 = randint1(yhsize) * 2 + y0 - yhsize;
4550                 build_room(x1, x2, y1, y2);
4551         }
4552
4553         /* Add some random doors */
4554         for (i = 0; i < 500; i++)
4555         {
4556                 x1 = randint1(xsize - 3) - xhsize + x0 + 1;
4557                 y1 = randint1(ysize - 3) - yhsize + y0 + 1;
4558                 add_door(x1, y1);
4559         }
4560
4561         /* Fill with monsters and treasure, high difficulty */
4562         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
4563 }
4564
4565
4566 /* Create a random vault out of a fractal cave */
4567 static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
4568 {
4569         int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y;
4570         bool done, light, room;
4571
4572         /* round to make sizes even */
4573         xhsize = xsiz / 2;
4574         yhsize = ysiz / 2;
4575         xsize = xhsize * 2;
4576         ysize = yhsize * 2;
4577
4578         msg_print_wizard(CHEAT_DUNGEON, _("洞穴ランダムVaultを生成しました。", "Cave Vault."));
4579
4580         light = done = FALSE;
4581         room = TRUE;
4582
4583         while (!done)
4584         {
4585                 /* testing values for these parameters feel free to adjust */
4586                 grd = 1 << randint0(4);
4587
4588                 /* want average of about 16 */
4589                 roug = randint1(8) * randint1(4);
4590
4591                 /* about size/2 */
4592                 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
4593                          randint1(xsize / 4) + randint1(ysize / 4);
4594
4595                 /* make it */
4596                 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
4597
4598                 /* Convert to normal format+ clean up */
4599                 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
4600         }
4601
4602         /* Set icky flag because is a vault */
4603         for (x = 0; x <= xsize; x++)
4604         {
4605                 for (y = 0; y <= ysize; y++)
4606                 {
4607                         cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
4608                 }
4609         }
4610
4611         /* Fill with monsters and treasure, low difficulty */
4612         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
4613 }
4614
4615 /*
4616  * maze vault -- rectangular labyrinthine rooms
4617  *
4618  * maze vault uses two routines:
4619  *    r_visit - a recursive routine that builds the labyrinth
4620  *    build_maze_vault - a driver routine that calls r_visit and adds
4621  *                   monsters, traps and treasure
4622  *
4623  * The labyrinth is built by creating a spanning tree of a graph.
4624  * The graph vertices are at
4625  *    (x, y) = (2j + x1, 2k + y1)   j = 0,...,m-1    k = 0,...,n-1
4626  * and the edges are the vertical and horizontal nearest neighbors.
4627  *
4628  * The spanning tree is created by performing a suitably randomized
4629  * depth-first traversal of the graph. The only adjustable parameter
4630  * is the randint0(3) below; it governs the relative density of
4631  * twists and turns in the labyrinth: smaller number, more twists.
4632  */
4633 static void r_visit(int y1, int x1, int y2, int x2,
4634                     int node, int dir, int *visited)
4635 {
4636         int i, j, m, n, temp, x, y, adj[4];
4637
4638         /* dimensions of vertex array */
4639         m = (x2 - x1) / 2 + 1;
4640         n = (y2 - y1) / 2 + 1;
4641
4642         /* mark node visited and set it to a floor */
4643         visited[node] = 1;
4644         x = 2 * (node % m) + x1;
4645         y = 2 * (node / m) + y1;
4646         place_floor_bold(y, x);
4647
4648         /* setup order of adjacent node visits */
4649         if (one_in_(3))
4650         {
4651                 /* pick a random ordering */
4652                 for (i = 0; i < 4; i++)
4653                         adj[i] = i;
4654                 for (i = 0; i < 4; i++)
4655                 {
4656                         j = randint0(4);
4657                         temp = adj[i];
4658                         adj[i] = adj[j];
4659                         adj[j] = temp;
4660                 }
4661                 dir = adj[0];
4662         }
4663         else
4664         {
4665                 /* pick a random ordering with dir first */
4666                 adj[0] = dir;
4667                 for (i = 1; i < 4; i++)
4668                         adj[i] = i;
4669                 for (i = 1; i < 4; i++)
4670                 {
4671                         j = 1 + randint0(3);
4672                         temp = adj[i];
4673                         adj[i] = adj[j];
4674                         adj[j] = temp;
4675                 }
4676         }
4677
4678         for (i = 0; i < 4; i++)
4679         {
4680                 switch (adj[i])
4681                 {
4682                         case 0:
4683                                 /* (0,+) - check for bottom boundary */
4684                                 if ((node / m < n - 1) && (visited[node + m] == 0))
4685                                 {
4686                                         place_floor_bold(y + 1, x);
4687                                         r_visit(y1, x1, y2, x2, node + m, dir, visited);
4688                                 }
4689                                 break;
4690                         case 1:
4691                                 /* (0,-) - check for top boundary */
4692                                 if ((node / m > 0) && (visited[node - m] == 0))
4693                                 {
4694                                         place_floor_bold(y - 1, x);
4695                                         r_visit(y1, x1, y2, x2, node - m, dir, visited);
4696                                 }
4697                                 break;
4698                         case 2:
4699                                 /* (+,0) - check for right boundary */
4700                                 if ((node % m < m - 1) && (visited[node + 1] == 0))
4701                                 {
4702                                         place_floor_bold(y, x + 1);
4703                                         r_visit(y1, x1, y2, x2, node + 1, dir, visited);
4704                                 }
4705                                 break;
4706                         case 3:
4707                                 /* (-,0) - check for left boundary */
4708                                 if ((node % m > 0) && (visited[node - 1] == 0))
4709                                 {
4710                                         place_floor_bold(y, x - 1);
4711                                         r_visit(y1, x1, y2, x2, node - 1, dir, visited);
4712                                 }
4713                 } /* end switch */
4714         }
4715 }
4716
4717
4718 void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
4719 {
4720         int y, x, dy, dx;
4721         int y1, x1, y2, x2;
4722         int m, n, num_vertices, *visited;
4723         bool light;
4724         cave_type *c_ptr;
4725
4726         msg_print_wizard(CHEAT_DUNGEON, _("迷路ランダムVaultを生成しました。", "Maze Vault."));
4727
4728         /* Choose lite or dark */
4729         light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
4730
4731         /* Pick a random room size - randomized by calling routine */
4732         dy = ysize / 2 - 1;
4733         dx = xsize / 2 - 1;
4734
4735         y1 = y0 - dy;
4736         x1 = x0 - dx;
4737         y2 = y0 + dy;
4738         x2 = x0 + dx;
4739
4740         /* generate the room */
4741         for (y = y1 - 1; y <= y2 + 1; y++)
4742         {
4743                 for (x = x1 - 1; x <= x2 + 1; x++)
4744                 {
4745                         c_ptr = &cave[y][x];
4746                         c_ptr->info |= CAVE_ROOM;
4747                         if (is_vault) c_ptr->info |= CAVE_ICKY;
4748                         if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
4749                         {
4750                                 place_outer_grid(c_ptr);
4751                         }
4752                         else if (!is_vault)
4753                         {
4754                                 place_extra_grid(c_ptr);
4755                         }
4756                         else
4757                         {
4758                                 place_inner_grid(c_ptr);
4759                         }
4760                         if (light) c_ptr->info |= (CAVE_GLOW);
4761                 }
4762         }
4763
4764         /* dimensions of vertex array */
4765         m = dx + 1;
4766         n = dy + 1;
4767         num_vertices = m * n;
4768
4769         /* initialize array of visited vertices */
4770         C_MAKE(visited, num_vertices, int);
4771
4772         /* traverse the graph to create a spaning tree, pick a random root */
4773         r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4774
4775         /* Fill with monsters and treasure, low difficulty */
4776         if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
4777
4778         C_KILL(visited, num_vertices, int);
4779 }
4780
4781
4782 /* Build a "mini" checkerboard vault
4783  *
4784  * This is done by making a permanent wall maze and setting
4785  * the diagonal sqaures of the checker board to be granite.
4786  * The vault has two entrances on opposite sides to guarantee
4787  * a way to get in even if the vault abuts a side of the dungeon.
4788  */
4789 static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
4790 {
4791         int dy, dx;
4792         int y1, x1, y2, x2, y, x, total;
4793         int m, n, num_vertices;
4794         int *visited;
4795
4796         msg_print_wizard(CHEAT_DUNGEON, _("小型チェッカーランダムVaultを生成しました。", "Mini Checker Board Vault."));
4797
4798         /* Pick a random room size */
4799         dy = ysize / 2 - 1;
4800         dx = xsize / 2 - 1;
4801
4802         y1 = y0 - dy;
4803         x1 = x0 - dx;
4804         y2 = y0 + dy;
4805         x2 = x0 + dx;
4806
4807
4808         /* generate the room */
4809         for (x = x1 - 2; x <= x2 + 2; x++)
4810         {
4811                 if (!in_bounds(y1-2,x)) break;
4812
4813                 cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4814
4815                 place_outer_noperm_bold(y1-2, x);
4816         }
4817
4818         for (x = x1 - 2; x <= x2 + 2; x++)
4819         {
4820                 if (!in_bounds(y2+2,x)) break;
4821
4822                 cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4823
4824                 place_outer_noperm_bold(y2+2, x);
4825         }
4826
4827         for (y = y1 - 2; y <= y2 + 2; y++)
4828         {
4829                 if (!in_bounds(y,x1-2)) break;
4830
4831                 cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY);
4832
4833                 place_outer_noperm_bold(y, x1-2);
4834         }
4835
4836         for (y = y1 - 2; y <= y2 + 2; y++)
4837         {
4838                 if (!in_bounds(y,x2+2)) break;
4839
4840                 cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY);
4841
4842                 place_outer_noperm_bold(y, x2+2);
4843         }
4844
4845         for (y = y1 - 1; y <= y2 + 1; y++)
4846         {
4847                 for (x = x1 - 1; x <= x2 + 1; x++)
4848                 {
4849                         cave_type *c_ptr = &cave[y][x];
4850
4851                         c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
4852
4853                         /* Permanent walls */
4854                         place_inner_perm_grid(c_ptr);
4855                 }
4856         }
4857
4858
4859         /* dimensions of vertex array */
4860         m = dx + 1;
4861         n = dy + 1;
4862         num_vertices = m * n;
4863
4864         /* initialize array of visited vertices */
4865         C_MAKE(visited, num_vertices, int);
4866
4867         /* traverse the graph to create a spannng tree, pick a random root */
4868         r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4869
4870         /* Make it look like a checker board vault */
4871         for (x = x1; x <= x2; x++)
4872         {
4873                 for (y = y1; y <= y2; y++)
4874                 {
4875                         total = x - x1 + y - y1;
4876                         /* If total is odd- and is a floor then make a wall */
4877                         if ((total % 2 == 1) && is_floor_bold(y, x))
4878                         {
4879                                 place_inner_bold(y, x);
4880                         }
4881                 }
4882         }
4883
4884         /* Make a couple of entrances */
4885         if (one_in_(2))
4886         {
4887                 /* left and right */
4888                 y = randint1(dy) + dy / 2;
4889                 place_inner_bold(y1 + y, x1 - 1);
4890                 place_inner_bold(y1 + y, x2 + 1);
4891         }
4892         else
4893         {
4894                 /* top and bottom */
4895                 x = randint1(dx) + dx / 2;
4896                 place_inner_bold(y1 - 1, x1 + x);
4897                 place_inner_bold(y2 + 1, x1 + x);
4898         }
4899
4900         /* Fill with monsters and treasure, highest difficulty */
4901         fill_treasure(x1, x2, y1, y2, 10);
4902
4903         C_KILL(visited, num_vertices, int);
4904 }
4905
4906
4907 /* Build a town/ castle by using a recursive algorithm.
4908  * Basically divide each region in a probalistic way to create
4909  * smaller regions.  When the regions get too small stop.
4910  *
4911  * The power variable is a measure of how well defended a region is.
4912  * This alters the possible choices.
4913  */
4914 static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
4915 {
4916         int xsize, ysize;
4917         int x, y;
4918         int choice;
4919
4920         /* Temp variables */
4921         int t1, t2, t3, t4;
4922
4923         xsize = x2 - x1;
4924         ysize = y2 - y1;
4925
4926         if ((power < 3) && (xsize > 12) && (ysize > 12))
4927         {
4928                 /* Need outside wall +keep */
4929                 choice = 1;
4930         }
4931         else
4932         {
4933                 if (power < 10)
4934                 {
4935                         /* Make rooms + subdivide */
4936                         if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
4937                         {
4938                                 choice = 4;
4939                         }
4940                         else
4941                         {
4942                                 choice = randint1(2) + 1;
4943                         }
4944                 }
4945                 else
4946                 {
4947                         /* Mostly subdivide */
4948                         choice = randint1(3) + 1;
4949                 }
4950         }
4951
4952         /* Based on the choice made above, do something */
4953
4954         switch (choice)
4955         {
4956                 case 1:
4957                 {
4958                         /* Outer walls */
4959
4960                         /* top and bottom */
4961                         for (x = x1; x <= x2; x++)
4962                         {
4963                                 place_outer_bold(y1, x);
4964                                 place_outer_bold(y2, x);
4965                         }
4966
4967                         /* left and right */
4968                         for (y = y1 + 1; y < y2; y++)
4969                         {
4970                                 place_outer_bold(y, x1);
4971                                 place_outer_bold(y, x2);
4972                         }
4973
4974                         /* Make a couple of entrances */
4975                         if (one_in_(2))
4976                         {
4977                                 /* left and right */
4978                                 y = randint1(ysize) + y1;
4979                                 place_floor_bold(y, x1);
4980                                 place_floor_bold(y, x2);
4981                         }
4982                         else
4983                         {
4984                                 /* top and bottom */
4985                                 x = randint1(xsize) + x1;
4986                                 place_floor_bold(y1, x);
4987                                 place_floor_bold(y2, x);
4988                         }
4989
4990                         /* Select size of keep */
4991                         t1 = randint1(ysize / 3) + y1;
4992                         t2 = y2 - randint1(ysize / 3);
4993                         t3 = randint1(xsize / 3) + x1;
4994                         t4 = x2 - randint1(xsize / 3);
4995
4996                         /* Do outside areas */
4997
4998                         /* Above and below keep */
4999                         build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
5000                         build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
5001
5002                         /* Left and right of keep */
5003                         build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
5004                         build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
5005
5006                         /* Make the keep itself: */
5007                         x1 = t3;
5008                         x2 = t4;
5009                         y1 = t1;
5010                         y2 = t2;
5011                         xsize = x2 - x1;
5012                         ysize = y2 - y1;
5013                         power += 2;
5014
5015                         /* Fall through */
5016                 }
5017                 case 4:
5018                 {
5019                         /* Try to build a room */
5020                         if ((xsize < 3) || (ysize < 3))
5021                         {
5022                                 for (y = y1; y < y2; y++)
5023                                 {
5024                                         for (x = x1; x < x2; x++)
5025                                         {
5026                                                 place_inner_bold(y, x);
5027                                         }
5028                                 }
5029
5030                                 /* Too small */
5031                                 return;
5032                         }
5033
5034                         /* Make outside walls */
5035                         /* top and bottom */
5036                         for (x = x1 + 1; x <= x2 - 1; x++)
5037                         {
5038                                 place_inner_bold(y1 + 1, x);
5039                                 place_inner_bold(y2 - 1, x);
5040                         }
5041
5042                         /* left and right */
5043                         for (y = y1 + 1; y <= y2 - 1; y++)
5044                         {
5045                                 place_inner_bold(y, x1 + 1);
5046                                 place_inner_bold(y, x2 - 1);
5047                         }
5048
5049                         /* Make a door */
5050                         y = randint1(ysize - 3) + y1 + 1;
5051
5052                         if (one_in_(2))
5053                         {
5054                                 /* left */
5055                                 place_floor_bold(y, x1 + 1);
5056                         }
5057                         else
5058                         {
5059                                 /* right */
5060                                 place_floor_bold(y, x2 - 1);
5061                         }
5062
5063                         /* Build the room */
5064                         build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
5065                         break;
5066                 }
5067                 case 2:
5068                 {
5069                         /* Try and divide vertically */
5070                         if (xsize < 3)
5071                         {
5072                                 /* Too small */
5073                                 for (y = y1; y < y2; y++)
5074                                 {
5075                                         for (x = x1; x < x2; x++)
5076                                         {
5077                                                 place_inner_bold(y, x);
5078                                         }
5079                                 }
5080                                 return;
5081                         }
5082
5083                         t1 = randint1(xsize - 2) + x1 + 1;
5084                         build_recursive_room(x1, y1, t1, y2, power - 2);
5085                         build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
5086                         break;
5087                 }
5088                 case 3:
5089                 {
5090                         /* Try and divide horizontally */
5091                         if (ysize < 3)
5092                         {
5093                                 /* Too small */
5094                                 for (y = y1; y < y2; y++)
5095                                 {
5096                                         for (x = x1; x < x2; x++)
5097                                         {
5098                                                 place_inner_bold(y, x);
5099                                         }
5100                                 }
5101                                 return;
5102                         }
5103
5104                         t1 = randint1(ysize - 2) + y1 + 1;
5105                         build_recursive_room(x1, y1, x2, t1, power - 2);
5106                         build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
5107                         break;
5108                 }
5109         }
5110 }
5111
5112
5113 /* Build a castle */
5114
5115 /* Driver routine: clear the region and call the recursive
5116 * room routine.
5117 *
5118 *This makes a vault that looks like a castle/ city in the dungeon.
5119 */
5120 static void build_castle_vault(int x0, int y0, int xsize, int ysize)
5121 {
5122         int dy, dx;
5123         int y1, x1, y2, x2;
5124         int y, x;
5125
5126         /* Pick a random room size */
5127         dy = ysize / 2 - 1;
5128         dx = xsize / 2 - 1;
5129
5130         y1 = y0 - dy;
5131         x1 = x0 - dx;
5132         y2 = y0 + dy;
5133         x2 = x0 + dx;
5134
5135         msg_print_wizard(CHEAT_DUNGEON, _("城型ランダムVaultを生成しました。", "Castle Vault"));
5136
5137         /* generate the room */
5138         for (y = y1 - 1; y <= y2 + 1; y++)
5139         {
5140                 for (x = x1 - 1; x <= x2 + 1; x++)
5141                 {
5142                         cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
5143                         /* Make everything a floor */
5144                         place_floor_bold(y, x);
5145                 }
5146         }
5147
5148         /* Make the castle */
5149         build_recursive_room(x1, y1, x2, y2, randint1(5));
5150
5151         /* Fill with monsters and treasure, low difficulty */
5152         fill_treasure(x1, x2, y1, y2, randint1(3));
5153 }
5154
5155
5156 /*
5157  * Add outer wall to a floored region
5158  * Note: no range checking is done so must be inside dungeon
5159  * This routine also stomps on doors
5160  */
5161 static void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
5162 {
5163         cave_type *c_ptr;
5164         feature_type *f_ptr;
5165         int i, j;
5166
5167         if (!in_bounds(y, x)) return;
5168
5169         c_ptr = &cave[y][x];
5170
5171         /* hack- check to see if square has been visited before
5172         * if so, then exit (use room flag to do this) */
5173         if (c_ptr->info & CAVE_ROOM) return;
5174
5175         /* set room flag */
5176         c_ptr->info |= CAVE_ROOM;
5177
5178         f_ptr = &f_info[c_ptr->feat];
5179
5180         if (is_floor_bold(y, x))
5181         {
5182                 for (i = -1; i <= 1; i++)
5183                 {
5184                         for (j = -1; j <= 1; j++)
5185                         {
5186                                 if ((x + i >= x1) && (x + i <= x2) &&
5187                                          (y + j >= y1) && (y + j <= y2))
5188                                 {
5189                                         add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
5190                                         if (light) c_ptr->info |= CAVE_GLOW;
5191                                 }
5192                         }
5193                 }
5194         }
5195         else if (is_extra_bold(y, x))
5196         {
5197                 /* Set bounding walls */
5198                 place_outer_bold(y, x);
5199                 if (light) c_ptr->info |= CAVE_GLOW;
5200         }
5201         else if (permanent_wall(f_ptr))
5202         {
5203                 /* Set bounding walls */
5204                 if (light) c_ptr->info |= CAVE_GLOW;
5205         }
5206 }
5207
5208
5209 /*
5210  * Hacked distance formula - gives the 'wrong' answer.
5211  * Used to build crypts
5212  */
5213 static int dist2(int x1, int y1, int x2, int y2,
5214                  int h1, int h2, int h3, int h4)
5215 {
5216         int dx, dy;
5217         dx = abs(x2 - x1);
5218         dy = abs(y2 - y1);
5219
5220         /* Basically this works by taking the normal pythagorean formula
5221          * and using an expansion to express this in a way without the
5222          * square root.  This approximate formula is then perturbed to give
5223          * the distorted results.  (I found this by making a mistake when I was
5224          * trying to fix the circular rooms.)
5225          */
5226
5227         /* h1-h4 are constants that describe the metric */
5228         if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
5229         if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
5230         return (((dx + dy) * 128) / 181 +
5231                 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
5232         /* 128/181 is approx. 1/sqrt(2) */
5233 }
5234
5235
5236 /*
5237  * Build target vault.
5238  * This is made by two concentric "crypts" with perpendicular
5239  * walls creating the cross-hairs.
5240  */
5241 static void build_target_vault(int x0, int y0, int xsize, int ysize)
5242 {
5243         int rad, x, y;
5244
5245         /* Make a random metric */
5246         int h1, h2, h3, h4;
5247         h1 = randint1(32) - 16;
5248         h2 = randint1(16);
5249         h3 = randint1(32);
5250         h4 = randint1(32) - 16;
5251
5252         msg_print_wizard(CHEAT_DUNGEON, _("対称形ランダムVaultを生成しました。", "Elemental Vault"));
5253
5254         /* work out outer radius */
5255         if (xsize > ysize)
5256         {
5257                 rad = ysize / 2;
5258         }
5259         else
5260         {
5261                 rad = xsize / 2;
5262         }
5263
5264         /* Make floor */
5265         for (x = x0 - rad; x <= x0 + rad; x++)
5266         {
5267                 for (y = y0 - rad; y <= y0 + rad; y++)
5268                 {
5269                         /* clear room flag */
5270                         cave[y][x].info &= ~(CAVE_ROOM);
5271
5272                         /* Vault - so is "icky" */
5273                         cave[y][x].info |= CAVE_ICKY;
5274
5275                         if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5276                         {
5277                                 /* inside- so is floor */
5278                                 place_floor_bold(y, x);
5279                         }
5280                         else
5281                         {
5282                                 /* make granite outside so arena works */
5283                                 place_extra_bold(y, x);
5284                         }
5285
5286                         /* proper boundary for arena */
5287                         if (((y + rad) == y0) || ((y - rad) == y0) ||
5288                             ((x + rad) == x0) || ((x - rad) == x0))
5289                         {
5290                                 place_extra_bold(y, x);
5291                         }
5292                 }
5293         }
5294
5295         /* Find visible outer walls and set to be FEAT_OUTER */
5296         add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
5297                        x0 + rad + 1, y0 + rad + 1);
5298
5299         /* Add inner wall */
5300         for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
5301         {
5302                 for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
5303                 {
5304                         if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
5305                         {
5306                                 /* Make an internal wall */
5307                                 place_inner_bold(y, x);
5308                         }
5309                 }
5310         }
5311
5312         /* Add perpendicular walls */
5313         for (x = x0 - rad; x <= x0 + rad; x++)
5314         {
5315                 place_inner_bold(y0, x);
5316         }
5317
5318         for (y = y0 - rad; y <= y0 + rad; y++)
5319         {
5320                 place_inner_bold(y, x0);
5321         }
5322
5323         /* Make inner vault */
5324         for (y = y0 - 1; y <= y0 + 1; y++)
5325         {
5326                 place_inner_bold(y, x0 - 1);
5327                 place_inner_bold(y, x0 + 1);
5328         }
5329         for (x = x0 - 1; x <= x0 + 1; x++)
5330         {
5331                 place_inner_bold(y0 - 1, x);
5332                 place_inner_bold(y0 + 1, x);
5333         }
5334
5335         place_floor_bold(y0, x0);
5336
5337
5338         /* Add doors to vault */
5339         /* get two distances so can place doors relative to centre */
5340         x = (rad - 2) / 4 + 1;
5341         y = rad / 2 + x;
5342
5343         add_door(x0 + x, y0);
5344         add_door(x0 + y, y0);
5345         add_door(x0 - x, y0);
5346         add_door(x0 - y, y0);
5347         add_door(x0, y0 + x);
5348         add_door(x0, y0 + y);
5349         add_door(x0, y0 - x);
5350         add_door(x0, y0 - y);
5351
5352         /* Fill with stuff - medium difficulty */
5353         fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
5354 }
5355
5356
5357 #ifdef ALLOW_CAVERNS_AND_LAKES
5358 /*
5359  * This routine uses a modified version of the lake code to make a
5360  * distribution of some terrain type over the vault.  This type
5361  * depends on the dungeon depth.
5362  *
5363  * Miniture rooms are then scattered across the vault.
5364  */
5365 static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
5366 {
5367         int grd, roug;
5368         int c1, c2, c3;
5369         bool done = FALSE;
5370         int xsize, ysize, xhsize, yhsize, x, y, i;
5371         int type;
5372
5373         msg_print_wizard(CHEAT_DUNGEON, _("精霊界ランダムVaultを生成しました。", "Elemental Vault"));
5374
5375         /* round to make sizes even */
5376         xhsize = xsiz / 2;
5377         yhsize = ysiz / 2;
5378         xsize = xhsize * 2;
5379         ysize = yhsize * 2;
5380
5381         if (dun_level < 25)
5382         {
5383                 /* Earth vault  (Rubble) */
5384                 type = LAKE_T_EARTH_VAULT;
5385         }
5386         else if (dun_level < 50)
5387         {
5388                 /* Air vault (Trees) */
5389                 type = LAKE_T_AIR_VAULT;
5390         }
5391         else if (dun_level < 75)
5392         {
5393                 /* Water vault (shallow water) */
5394                 type = LAKE_T_WATER_VAULT;
5395         }
5396         else
5397         {
5398                 /* Fire vault (shallow lava) */
5399                 type = LAKE_T_FIRE_VAULT;
5400         }
5401
5402         while (!done)
5403         {
5404                 /* testing values for these parameters: feel free to adjust */
5405                 grd = 1 << (randint0(3));
5406
5407                 /* want average of about 16 */
5408                 roug = randint1(8) * randint1(4);
5409
5410                 /* Make up size of various componants */
5411                 /* Floor */
5412                 c3 = 2 * xsize / 3;
5413
5414                 /* Deep water/lava */
5415                 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
5416
5417                 /* Shallow boundary */
5418                 c2 = (c1 + c3) / 2;
5419
5420                 /* make it */
5421                 generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
5422
5423                 /* Convert to normal format+ clean up */
5424                 done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
5425         }
5426
5427         /* Set icky flag because is a vault */
5428         for (x = 0; x <= xsize; x++)
5429         {
5430                 for (y = 0; y <= ysize; y++)
5431                 {
5432                         cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
5433                 }
5434         }
5435
5436         /* make a few rooms in the vault */
5437         for (i = 1; i <= (xsize * ysize) / 50; i++)
5438         {
5439                 build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
5440                                  y0 + randint0(ysize - 4) - ysize / 2 + 2);
5441         }
5442
5443         /* Fill with monsters and treasure, low difficulty */
5444         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
5445                       y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
5446 }
5447 #endif /* ALLOW_CAVERNS_AND_LAKES */
5448
5449
5450 /*!
5451  * @brief タイプ10の部屋…ランダム生成vault / Type 10 -- Random vaults
5452  * @return なし
5453  */
5454 static bool build_type10(void)
5455 {
5456         POSITION y0, x0, xsize, ysize, vtype;
5457
5458         /* Get size */
5459         /* big enough to look good, small enough to be fairly common. */
5460         xsize = randint1(22) + 22;
5461         ysize = randint1(11) + 11;
5462
5463         /* Find and reserve some space in the dungeon.  Get center of room. */
5464         if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
5465
5466         /* Select type of vault */
5467 #ifdef ALLOW_CAVERNS_AND_LAKES
5468         do
5469         {
5470                 vtype = randint1(15);
5471         }
5472         while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
5473                 ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11)));
5474 #else /* ALLOW_CAVERNS_AND_LAKES */
5475         do
5476         {
5477                 vtype = randint1(7);
5478         }
5479         while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
5480                 ((vtype == 1) || (vtype == 3)));
5481 #endif /* ALLOW_CAVERNS_AND_LAKES */
5482
5483         switch (vtype)
5484         {
5485                 /* Build an appropriate room */
5486                 case 1: case  9: build_bubble_vault(x0, y0, xsize, ysize); break;
5487                 case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
5488                 case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
5489                 case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
5490                 case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
5491                 case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
5492                 case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
5493 #ifdef ALLOW_CAVERNS_AND_LAKES
5494                 case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
5495 #endif /* ALLOW_CAVERNS_AND_LAKES */
5496                 /* I know how to add a few more... give me some time. */
5497
5498                 /* Paranoia */
5499                 default: return FALSE;
5500         }
5501
5502         return TRUE;
5503 }
5504
5505
5506 /*!
5507  * @brief タイプ11の部屋…円形部屋の生成 / Type 11 -- Build an vertical oval room.
5508  * @return なし
5509  * @details
5510  * For every grid in the possible square, check the distance.\n
5511  * If it's less than the radius, make it a room square.\n
5512  *\n
5513  * When done fill from the inside to find the walls,\n
5514  */
5515 static bool build_type11(void)
5516 {
5517         POSITION rad, x, y, x0, y0;
5518         int light = FALSE;
5519
5520         /* Occasional light */
5521         if ((randint1(dun_level) <= 15) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5522
5523         rad = randint0(9);
5524
5525         /* Find and reserve some space in the dungeon.  Get center of room. */
5526         if (!find_space(&y0, &x0, rad * 2 + 1, rad * 2 + 1)) return FALSE;
5527
5528         /* Make circular floor */
5529         for (x = x0 - rad; x <= x0 + rad; x++)
5530         {
5531                 for (y = y0 - rad; y <= y0 + rad; y++)
5532                 {
5533                         if (distance(y0, x0, y, x) <= rad - 1)
5534                         {
5535                                 /* inside- so is floor */
5536                                 place_floor_bold(y, x);
5537                         }
5538                         else if (distance(y0, x0, y, x) <= rad + 1)
5539                         {
5540                                 /* make granite outside so arena works */
5541                                 place_extra_bold(y, x);
5542                         }
5543                 }
5544         }
5545
5546         /* Find visible outer walls and set to be FEAT_OUTER */
5547         add_outer_wall(x0, y0, light, x0 - rad, y0 - rad, x0 + rad, y0 + rad);
5548
5549         return TRUE;
5550 }
5551
5552
5553 /*!
5554  * @brief タイプ12の部屋…ドーム型部屋の生成 / Type 12 -- Build crypt room.
5555  * @return なし
5556  * @details
5557  * For every grid in the possible square, check the (fake) distance.\n
5558  * If it's less than the radius, make it a room square.\n
5559  *\n
5560  * When done fill from the inside to find the walls,\n
5561  */
5562 static bool build_type12(void)
5563 {
5564         POSITION rad, x, y, x0, y0;
5565         int light = FALSE;
5566         bool emptyflag = TRUE;
5567
5568         /* Make a random metric */
5569         int h1, h2, h3, h4;
5570         h1 = randint1(32) - 16;
5571         h2 = randint1(16);
5572         h3 = randint1(32);
5573         h4 = randint1(32) - 16;
5574
5575         /* Occasional light */
5576         if ((randint1(dun_level) <= 5) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5577
5578         rad = randint1(9);
5579
5580         /* Find and reserve some space in the dungeon.  Get center of room. */
5581         if (!find_space(&y0, &x0, rad * 2 + 3, rad * 2 + 3)) return FALSE;
5582
5583         /* Make floor */
5584         for (x = x0 - rad; x <= x0 + rad; x++)
5585         {
5586                 for (y = y0 - rad; y <= y0 + rad; y++)
5587                 {
5588                         /* clear room flag */
5589                         cave[y][x].info &= ~(CAVE_ROOM);
5590
5591                         if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5592                         {
5593                                 /* inside - so is floor */
5594                                 place_floor_bold(y, x);
5595                         }
5596                         else if (distance(y0, x0, y, x) < 3)
5597                         {
5598                                 place_floor_bold(y, x);
5599                         }
5600                         else
5601                         {
5602                                 /* make granite outside so arena works */
5603                                 place_extra_bold(y, x);
5604                         }
5605
5606                         /* proper boundary for arena */
5607                         if (((y + rad) == y0) || ((y - rad) == y0) ||
5608                             ((x + rad) == x0) || ((x - rad) == x0))
5609                         {
5610                                 place_extra_bold(y, x);
5611                         }
5612                 }
5613         }
5614
5615         /* Find visible outer walls and set to be FEAT_OUTER */
5616         add_outer_wall(x0, y0, light, x0 - rad - 1, y0 - rad - 1,
5617                        x0 + rad + 1, y0 + rad + 1);
5618
5619         /* Check to see if there is room for an inner vault */
5620         for (x = x0 - 2; x <= x0 + 2; x++)
5621         {
5622                 for (y = y0 - 2; y <= y0 + 2; y++)
5623                 {
5624                         if (!is_floor_bold(y, x))
5625                         {
5626                                 /* Wall in the way */
5627                                 emptyflag = FALSE;
5628                         }
5629                 }
5630         }
5631
5632         if (emptyflag && one_in_(2))
5633         {
5634                 /* Build the vault */
5635                 build_small_room(x0, y0);
5636
5637                 /* Place a treasure in the vault */
5638                 place_object(y0, x0, 0L);
5639
5640                 /* Let's guard the treasure well */
5641                 vault_monsters(y0, x0, randint0(2) + 3);
5642
5643                 /* Traps naturally */
5644                 vault_traps(y0, x0, 4, 4, randint0(3) + 2);
5645         }
5646
5647         return TRUE;
5648 }
5649
5650
5651 /*
5652  * Helper function for "trapped monster pit"
5653  */
5654 static bool vault_aux_trapped_pit(MONRACE_IDX r_idx)
5655 {
5656         monster_race *r_ptr = &r_info[r_idx];
5657
5658         /* Validate the monster */
5659         if (!vault_monster_okay(r_idx)) return (FALSE);
5660
5661         /* No wall passing monster */
5662         if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return (FALSE);
5663
5664         /* Okay */
5665         return (TRUE);
5666 }
5667
5668
5669 /*!
5670  * @brief タイプ13の部屋…トラップpitの生成 / Type 13 -- Trapped monster pits
5671  * @return なし
5672  * @details
5673  * A trapped monster pit is a "big" room with a straight corridor in\n
5674  * which wall opening traps are placed, and with two "inner" rooms\n
5675  * containing a "collection" of monsters of a given type organized in\n
5676  * the room.\n
5677  *\n
5678  * The trapped monster pit appears as shown below, where the actual\n
5679  * monsters in each location depend on the type of the pit\n
5680  *\n
5681  *  XXXXXXXXXXXXXXXXXXXXXXXXX\n
5682  *  X                       X\n
5683  *  XXXXXXXXXXXXXXXXXXXXXXX X\n
5684  *  XXXXX001123454321100XXX X\n
5685  *  XXX0012234567654322100X X\n
5686  *  XXXXXXXXXXXXXXXXXXXXXXX X\n
5687  *  X           ^           X\n
5688  *  X XXXXXXXXXXXXXXXXXXXXXXX\n
5689  *  X X0012234567654322100XXX\n
5690  *  X XXX001123454321100XXXXX\n
5691  *  X XXXXXXXXXXXXXXXXXXXXXXX\n
5692  *  X                       X\n
5693  *  XXXXXXXXXXXXXXXXXXXXXXXXX\n
5694  *\n
5695  * Note that the monsters in the pit are now chosen by using "get_mon_num()"\n
5696  * to request 16 "appropriate" monsters, sorting them by level, and using\n
5697  * the "even" entries in this sorted list for the contents of the pit.\n
5698  *\n
5699  * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",\n
5700  * which is handled by requiring a specific "breath" attack for all of the\n
5701  * dragons.  This may include "multi-hued" breath.  Note that "wyrms" may\n
5702  * be present in many of the dragon pits, if they have the proper breath.\n
5703  *\n
5704  * Note the use of the "get_mon_num_prep()" function, and the special\n
5705  * "get_mon_num_hook()" restriction function, to prepare the "monster\n
5706  * allocation table" in such a way as to optimize the selection of\n
5707  * "appropriate" non-unique monsters for the pit.\n
5708  *\n
5709  * Note that the "get_mon_num()" function may (rarely) fail, in which case\n
5710  * the pit will be empty.\n
5711  *\n
5712  * Note that "monster pits" will never contain "unique" monsters.\n
5713  */
5714 static bool build_type13(void)
5715 {
5716         static int placing[][3] = {
5717                 {-2, -9, 0}, {-2, -8, 0}, {-3, -7, 0}, {-3, -6, 0},
5718                 {+2, -9, 0}, {+2, -8, 0}, {+3, -7, 0}, {+3, -6, 0},
5719                 {-2, +9, 0}, {-2, +8, 0}, {-3, +7, 0}, {-3, +6, 0},
5720                 {+2, +9, 0}, {+2, +8, 0}, {+3, +7, 0}, {+3, +6, 0},
5721                 {-2, -7, 1}, {-3, -5, 1}, {-3, -4, 1}, 
5722                 {+2, -7, 1}, {+3, -5, 1}, {+3, -4, 1}, 
5723                 {-2, +7, 1}, {-3, +5, 1}, {-3, +4, 1}, 
5724                 {+2, +7, 1}, {+3, +5, 1}, {+3, +4, 1},
5725                 {-2, -6, 2}, {-2, -5, 2}, {-3, -3, 2},
5726                 {+2, -6, 2}, {+2, -5, 2}, {+3, -3, 2},
5727                 {-2, +6, 2}, {-2, +5, 2}, {-3, +3, 2},
5728                 {+2, +6, 2}, {+2, +5, 2}, {+3, +3, 2},
5729                 {-2, -4, 3}, {-3, -2, 3},
5730                 {+2, -4, 3}, {+3, -2, 3},
5731                 {-2, +4, 3}, {-3, +2, 3},
5732                 {+2, +4, 3}, {+3, +2, 3},
5733                 {-2, -3, 4}, {-3, -1, 4},
5734                 {+2, -3, 4}, {+3, -1, 4},
5735                 {-2, +3, 4}, {-3, +1, 4},
5736                 {+2, +3, 4}, {+3, +1, 4},
5737                 {-2, -2, 5}, {-3, 0, 5}, {-2, +2, 5},
5738                 {+2, -2, 5}, {+3, 0, 5}, {+2, +2, 5},
5739                 {-2, -1, 6}, {-2, +1, 6},
5740                 {+2, -1, 6}, {+2, +1, 6},
5741                 {-2, 0, 7}, {+2, 0, 7},
5742                 {0, 0, -1}
5743         };
5744
5745         POSITION y, x, y1, x1, y2, x2, xval, yval;
5746         int i, j;
5747
5748         MONRACE_IDX what[16];
5749
5750         monster_type align;
5751
5752         cave_type *c_ptr;
5753
5754         int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
5755         vault_aux_type *n_ptr;
5756
5757         /* Only in Angband */
5758         if (dungeon_type != DUNGEON_ANGBAND) return FALSE;
5759
5760         /* No type available */
5761         if (cur_pit_type < 0) return FALSE;
5762
5763         n_ptr = &pit_types[cur_pit_type];
5764
5765         /* Process a preparation function if necessary */
5766         if (n_ptr->prep_func) (*(n_ptr->prep_func))();
5767
5768         /* Prepare allocation table */
5769         get_mon_num_prep(n_ptr->hook_func, vault_aux_trapped_pit);
5770
5771         align.sub_align = SUB_ALIGN_NEUTRAL;
5772
5773         /* Pick some monster types */
5774         for (i = 0; i < 16; i++)
5775         {
5776                 MONRACE_IDX r_idx = 0;
5777                 int attempts = 100;
5778                 monster_race *r_ptr = NULL;
5779
5780                 while (attempts--)
5781                 {
5782                         /* Get a (hard) monster type */
5783                         r_idx = get_mon_num(dun_level + 0);
5784                         r_ptr = &r_info[r_idx];
5785
5786                         /* Decline incorrect alignment */
5787                         if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
5788
5789                         /* Accept this monster */
5790                         break;
5791                 }
5792
5793                 /* Notice failure */
5794                 if (!r_idx || !attempts) return FALSE;
5795
5796                 /* Note the alignment */
5797                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
5798                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
5799
5800                 what[i] = r_idx;
5801         }
5802
5803         /* Find and reserve some space in the dungeon.  Get center of room. */
5804         if (!find_space(&yval, &xval, 13, 25)) return FALSE;
5805
5806         /* Large room */
5807         y1 = yval - 5;
5808         y2 = yval + 5;
5809         x1 = xval - 11;
5810         x2 = xval + 11;
5811
5812         /* Fill with inner walls */
5813         for (y = y1 - 1; y <= y2 + 1; y++)
5814         {
5815                 for (x = x1 - 1; x <= x2 + 1; x++)
5816                 {
5817                         c_ptr = &cave[y][x];
5818                         place_inner_grid(c_ptr);
5819                         c_ptr->info |= (CAVE_ROOM);
5820                 }
5821         }
5822
5823         /* Place the floor area 1 */
5824         for (x = x1 + 3; x <= x2 - 3; x++)
5825         {
5826                 c_ptr = &cave[yval-2][x];
5827                 place_floor_grid(c_ptr);
5828                 add_cave_info(yval-2, x, CAVE_ICKY);
5829
5830                 c_ptr = &cave[yval+2][x];
5831                 place_floor_grid(c_ptr);
5832                 add_cave_info(yval+2, x, CAVE_ICKY);
5833         }
5834
5835         /* Place the floor area 2 */
5836         for (x = x1 + 5; x <= x2 - 5; x++)
5837         {
5838                 c_ptr = &cave[yval-3][x];
5839                 place_floor_grid(c_ptr);
5840                 add_cave_info(yval-3, x, CAVE_ICKY);
5841
5842                 c_ptr = &cave[yval+3][x];
5843                 place_floor_grid(c_ptr);
5844                 add_cave_info(yval+3, x, CAVE_ICKY);
5845         }
5846
5847         /* Corridor */
5848         for (x = x1; x <= x2; x++)
5849         {
5850                 c_ptr = &cave[yval][x];
5851                 place_floor_grid(c_ptr);
5852                 c_ptr = &cave[y1][x];
5853                 place_floor_grid(c_ptr);
5854                 c_ptr = &cave[y2][x];
5855                 place_floor_grid(c_ptr);
5856         }
5857
5858         /* Place the outer walls */
5859         for (y = y1 - 1; y <= y2 + 1; y++)
5860         {
5861                 c_ptr = &cave[y][x1 - 1];
5862                 place_outer_grid(c_ptr);
5863                 c_ptr = &cave[y][x2 + 1];
5864                 place_outer_grid(c_ptr);
5865         }
5866         for (x = x1 - 1; x <= x2 + 1; x++)
5867         {
5868                 c_ptr = &cave[y1 - 1][x];
5869                 place_outer_grid(c_ptr);
5870                 c_ptr = &cave[y2 + 1][x];
5871                 place_outer_grid(c_ptr);
5872         }
5873
5874         /* Random corridor */
5875         if (one_in_(2))
5876         {
5877                 for (y = y1; y <= yval; y++)
5878                 {
5879                         place_floor_bold(y, x2);
5880                         place_solid_bold(y, x1-1);
5881                 }
5882                 for (y = yval; y <= y2 + 1; y++)
5883                 {
5884                         place_floor_bold(y, x1);
5885                         place_solid_bold(y, x2+1);
5886                 }
5887         }
5888         else
5889         {
5890                 for (y = yval; y <= y2 + 1; y++)
5891                 {
5892                         place_floor_bold(y, x1);
5893                         place_solid_bold(y, x2+1);
5894                 }
5895                 for (y = y1; y <= yval; y++)
5896                 {
5897                         place_floor_bold(y, x2);
5898                         place_solid_bold(y, x1-1);
5899                 }
5900         }
5901
5902         /* Place the wall open trap */
5903         cave[yval][xval].mimic = cave[yval][xval].feat;
5904         cave[yval][xval].feat = feat_trap_open;
5905
5906         /* Sort the entries */
5907         for (i = 0; i < 16 - 1; i++)
5908         {
5909                 /* Sort the entries */
5910                 for (j = 0; j < 16 - 1; j++)
5911                 {
5912                         int i1 = j;
5913                         int i2 = j + 1;
5914
5915                         int p1 = r_info[what[i1]].level;
5916                         int p2 = r_info[what[i2]].level;
5917
5918                         /* Bubble */
5919                         if (p1 > p2)
5920                         {
5921                                 MONRACE_IDX tmp = what[i1];
5922                                 what[i1] = what[i2];
5923                                 what[i2] = tmp;
5924                         }
5925                 }
5926         }
5927
5928         msg_format_wizard(CHEAT_DUNGEON, _("%s%sの罠ピットが生成されました。", "Trapped monster pit (%s%s)"),
5929                 n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5930
5931         /* Select the entries */
5932         for (i = 0; i < 8; i++)
5933         {
5934                 /* Every other entry */
5935                 what[i] = what[i * 2];
5936
5937                 if (cheat_hear)
5938                 {
5939                         /* Message */
5940                         msg_print(r_name + r_info[what[i]].name);
5941                 }
5942         }
5943
5944         for (i = 0; placing[i][2] >= 0; i++)
5945         {
5946                 y = yval + placing[i][0];
5947                 x = xval + placing[i][1];
5948                 place_monster_aux(0, y, x, what[placing[i][2]], PM_NO_KAGE);
5949         }
5950
5951         return TRUE;
5952 }
5953
5954
5955 /*!
5956  * @brief タイプ14の部屋…特殊トラップ部屋の生成 / Type 14 -- trapped rooms
5957  * @return なし
5958  * @details
5959  * A special trap is placed at center of the room
5960  */
5961 static bool build_type14(void)
5962 {
5963         POSITION y, x, y2, x2, yval, xval;
5964         POSITION y1, x1, xsize, ysize;
5965
5966         bool light;
5967
5968         cave_type *c_ptr;
5969         s16b trap;
5970
5971         /* Pick a room size */
5972         y1 = randint1(4);
5973         x1 = randint1(11);
5974         y2 = randint1(3);
5975         x2 = randint1(11);
5976
5977         xsize = x1 + x2 + 1;
5978         ysize = y1 + y2 + 1;
5979
5980         /* Find and reserve some space in the dungeon.  Get center of room. */
5981         if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
5982
5983         /* Choose lite or dark */
5984         light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
5985
5986
5987         /* Get corner values */
5988         y1 = yval - ysize / 2;
5989         x1 = xval - xsize / 2;
5990         y2 = yval + (ysize - 1) / 2;
5991         x2 = xval + (xsize - 1) / 2;
5992
5993
5994         /* Place a full floor under the room */
5995         for (y = y1 - 1; y <= y2 + 1; y++)
5996         {
5997                 for (x = x1 - 1; x <= x2 + 1; x++)
5998                 {
5999                         c_ptr = &cave[y][x];
6000                         place_floor_grid(c_ptr);
6001                         c_ptr->info |= (CAVE_ROOM);
6002                         if (light) c_ptr->info |= (CAVE_GLOW);
6003                 }
6004         }
6005
6006         /* Walls around the room */
6007         for (y = y1 - 1; y <= y2 + 1; y++)
6008         {
6009                 c_ptr = &cave[y][x1 - 1];
6010                 place_outer_grid(c_ptr);
6011                 c_ptr = &cave[y][x2 + 1];
6012                 place_outer_grid(c_ptr);
6013         }
6014         for (x = x1 - 1; x <= x2 + 1; x++)
6015         {
6016                 c_ptr = &cave[y1 - 1][x];
6017                 place_outer_grid(c_ptr);
6018                 c_ptr = &cave[y2 + 1][x];
6019                 place_outer_grid(c_ptr);
6020         }
6021
6022         if (dun_level < 30 + randint1(30))
6023                 trap = feat_trap_piranha;
6024         else
6025                 trap = feat_trap_armageddon;
6026
6027         /* Place a special trap */
6028         c_ptr = &cave[rand_spread(yval, ysize/4)][rand_spread(xval, xsize/4)];
6029         c_ptr->mimic = c_ptr->feat;
6030         c_ptr->feat = trap;
6031
6032         msg_format_wizard(CHEAT_DUNGEON, _("%sの部屋が生成されました。", "Room of %s was generated."), f_name + f_info[trap].name);
6033
6034         return TRUE;
6035 }
6036
6037
6038 /*
6039  * Helper function for "glass room"
6040  */
6041 static bool vault_aux_lite(MONRACE_IDX r_idx)
6042 {
6043         monster_race *r_ptr = &r_info[r_idx];
6044
6045         /* Validate the monster */
6046         if (!vault_monster_okay(r_idx)) return FALSE;
6047
6048         /* Require lite attack */
6049         if (!(r_ptr->flags4 & RF4_BR_LITE) && !(r_ptr->a_ability_flags1 & RF5_BA_LITE)) return FALSE;
6050
6051         /* No wall passing monsters */
6052         if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return FALSE;
6053
6054         /* No disintegrating monsters */
6055         if (r_ptr->flags4 & RF4_BR_DISI) return FALSE;
6056
6057         return TRUE;
6058 }
6059
6060 /*
6061  * Helper function for "glass room"
6062  */
6063 static bool vault_aux_shards(MONRACE_IDX r_idx)
6064 {
6065         monster_race *r_ptr = &r_info[r_idx];
6066
6067         /* Validate the monster */
6068         if (!vault_monster_okay(r_idx)) return FALSE;
6069
6070         /* Require shards breath attack */
6071         if (!(r_ptr->flags4 & RF4_BR_SHAR)) return FALSE;
6072
6073         return TRUE;
6074 }
6075
6076 /*
6077  * Hack -- determine if a template is potion
6078  */
6079 static bool kind_is_potion(int k_idx)
6080 {
6081         return k_info[k_idx].tval == TV_POTION;
6082 }
6083
6084 /*!
6085  * @brief タイプ15の部屋…ガラス部屋の生成 / Type 15 -- glass rooms
6086  * @return なし
6087  */
6088 static bool build_type15(void)
6089 {
6090         POSITION y, x, y2, x2, yval, xval;
6091         POSITION y1, x1, xsize, ysize;
6092         bool light;
6093
6094         cave_type *c_ptr;
6095
6096         /* Pick a room size */
6097         xsize = rand_range(9, 13);
6098         ysize = rand_range(9, 13);
6099
6100         /* Find and reserve some space in the dungeon.  Get center of room. */
6101         if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
6102
6103         /* Choose lite or dark */
6104         light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
6105
6106         /* Get corner values */
6107         y1 = yval - ysize / 2;
6108         x1 = xval - xsize / 2;
6109         y2 = yval + (ysize - 1) / 2;
6110         x2 = xval + (xsize - 1) / 2;
6111
6112         /* Place a full floor under the room */
6113         for (y = y1 - 1; y <= y2 + 1; y++)
6114         {
6115                 for (x = x1 - 1; x <= x2 + 1; x++)
6116                 {
6117                         c_ptr = &cave[y][x];
6118                         place_floor_grid(c_ptr);
6119                         c_ptr->feat = feat_glass_floor;
6120                         c_ptr->info |= (CAVE_ROOM);
6121                         if (light) c_ptr->info |= (CAVE_GLOW);
6122                 }
6123         }
6124
6125         /* Walls around the room */
6126         for (y = y1 - 1; y <= y2 + 1; y++)
6127         {
6128                 c_ptr = &cave[y][x1 - 1];
6129                 place_outer_grid(c_ptr);
6130                 c_ptr->feat = feat_glass_wall;
6131                 c_ptr = &cave[y][x2 + 1];
6132                 place_outer_grid(c_ptr);
6133                 c_ptr->feat = feat_glass_wall;
6134         }
6135         for (x = x1 - 1; x <= x2 + 1; x++)
6136         {
6137                 c_ptr = &cave[y1 - 1][x];
6138                 place_outer_grid(c_ptr);
6139                 c_ptr->feat = feat_glass_wall;
6140                 c_ptr = &cave[y2 + 1][x];
6141                 place_outer_grid(c_ptr);
6142                 c_ptr->feat = feat_glass_wall;
6143         }
6144
6145         switch (randint1(3))
6146         {
6147         case 1: /* 4 lite breathers + potion */
6148                 {
6149                         int dir1, dir2;
6150
6151                         /* Prepare allocation table */
6152                         get_mon_num_prep(vault_aux_lite, NULL);
6153
6154                         /* Place fixed lite berathers */
6155                         for (dir1 = 4; dir1 < 8; dir1++)
6156                         {
6157                                 MONRACE_IDX r_idx = get_mon_num(dun_level);
6158
6159                                 y = yval + 2 * ddy_ddd[dir1];
6160                                 x = xval + 2 * ddx_ddd[dir1];
6161                                 if (r_idx) place_monster_aux(0, y, x, r_idx, PM_ALLOW_SLEEP);
6162
6163                                 /* Walls around the breather */
6164                                 for (dir2 = 0; dir2 < 8; dir2++)
6165                                 {
6166                                         c_ptr = &cave[y + ddy_ddd[dir2]][x + ddx_ddd[dir2]];
6167                                         place_inner_grid(c_ptr);
6168                                         c_ptr->feat = feat_glass_wall;
6169                                 }
6170                         }
6171
6172                         /* Walls around the potion */
6173                         for (dir1 = 0; dir1 < 4; dir1++)
6174                         {
6175                                 y = yval + 2 * ddy_ddd[dir1];
6176                                 x = xval + 2 * ddx_ddd[dir1];
6177                                 c_ptr = &cave[y][x];
6178                                 place_inner_perm_grid(c_ptr);
6179                                 c_ptr->feat = feat_permanent_glass_wall;
6180                                 cave[yval + ddy_ddd[dir1]][xval + ddx_ddd[dir1]].info |= (CAVE_ICKY);
6181                         }
6182
6183                         /* Glass door */
6184                         dir1 = randint0(4);
6185                         y = yval + 2 * ddy_ddd[dir1];
6186                         x = xval + 2 * ddx_ddd[dir1];
6187                         place_secret_door(y, x, DOOR_GLASS_DOOR);
6188                         c_ptr = &cave[y][x];
6189                         if (is_closed_door(c_ptr->feat)) c_ptr->mimic = feat_glass_wall;
6190
6191                         /* Place a potion */
6192                         get_obj_num_hook = kind_is_potion;
6193                         place_object(yval, xval, AM_NO_FIXED_ART);
6194                         cave[yval][xval].info |= (CAVE_ICKY);
6195                 }
6196                 break;
6197
6198         case 2: /* 1 lite breather + random object */
6199                 {
6200                         MONRACE_IDX r_idx;
6201                         DIRECTION dir1;
6202
6203                         /* Pillars */
6204                         c_ptr = &cave[y1 + 1][x1 + 1];
6205                         place_inner_grid(c_ptr);
6206                         c_ptr->feat = feat_glass_wall;
6207
6208                         c_ptr = &cave[y1 + 1][x2 - 1];
6209                         place_inner_grid(c_ptr);
6210                         c_ptr->feat = feat_glass_wall;
6211
6212                         c_ptr = &cave[y2 - 1][x1 + 1];
6213                         place_inner_grid(c_ptr);
6214                         c_ptr->feat = feat_glass_wall;
6215
6216                         c_ptr = &cave[y2 - 1][x2 - 1];
6217                         place_inner_grid(c_ptr);
6218                         c_ptr->feat = feat_glass_wall;
6219
6220                         /* Prepare allocation table */
6221                         get_mon_num_prep(vault_aux_lite, NULL);
6222
6223                         r_idx = get_mon_num(dun_level);
6224                         if (r_idx) place_monster_aux(0, yval, xval, r_idx, 0L);
6225
6226                         /* Walls around the breather */
6227                         for (dir1 = 0; dir1 < 8; dir1++)
6228                         {
6229                                 c_ptr = &cave[yval + ddy_ddd[dir1]][xval + ddx_ddd[dir1]];
6230                                 place_inner_grid(c_ptr);
6231                                 c_ptr->feat = feat_glass_wall;
6232                         }
6233
6234                         /* Curtains around the breather */
6235                         for (y = yval - 1; y <= yval + 1; y++)
6236                         {
6237                                 place_closed_door(y, xval - 2, DOOR_CURTAIN);
6238                                 place_closed_door(y, xval + 2, DOOR_CURTAIN);
6239                         }
6240                         for (x = xval - 1; x <= xval + 1; x++)
6241                         {
6242                                 place_closed_door(yval - 2, x, DOOR_CURTAIN);
6243                                 place_closed_door(yval + 2, x, DOOR_CURTAIN);
6244                         }
6245
6246                         /* Place an object */
6247                         place_object(yval, xval, AM_NO_FIXED_ART);
6248                         cave[yval][xval].info |= (CAVE_ICKY);
6249                 }
6250                 break;
6251
6252         case 3: /* 4 shards breathers + 2 potions */
6253                 {
6254                         int dir1;
6255
6256                         /* Walls around the potion */
6257                         for (y = yval - 2; y <= yval + 2; y++)
6258                         {
6259                                 c_ptr = &cave[y][xval - 3];
6260                                 place_inner_grid(c_ptr);
6261                                 c_ptr->feat = feat_glass_wall;
6262                                 c_ptr = &cave[y][xval + 3];
6263                                 place_inner_grid(c_ptr);
6264                                 c_ptr->feat = feat_glass_wall;
6265                         }
6266                         for (x = xval - 2; x <= xval + 2; x++)
6267                         {
6268                                 c_ptr = &cave[yval - 3][x];
6269                                 place_inner_grid(c_ptr);
6270                                 c_ptr->feat = feat_glass_wall;
6271                                 c_ptr = &cave[yval + 3][x];
6272                                 place_inner_grid(c_ptr);
6273                                 c_ptr->feat = feat_glass_wall;
6274                         }
6275                         for (dir1 = 4; dir1 < 8; dir1++)
6276                         {
6277                                 c_ptr = &cave[yval + 2 * ddy_ddd[dir1]][xval + 2 * ddx_ddd[dir1]];
6278                                 place_inner_grid(c_ptr);
6279                                 c_ptr->feat = feat_glass_wall;
6280                         }
6281
6282                         /* Prepare allocation table */
6283                         get_mon_num_prep(vault_aux_shards, NULL);
6284
6285                         /* Place shard berathers */
6286                         for (dir1 = 4; dir1 < 8; dir1++)
6287                         {
6288                                 MONRACE_IDX r_idx = get_mon_num(dun_level);
6289
6290                                 y = yval + ddy_ddd[dir1];
6291                                 x = xval + ddx_ddd[dir1];
6292                                 if (r_idx) place_monster_aux(0, y, x, r_idx, 0L);
6293                         }
6294
6295                         /* Place two potions */
6296                         if (one_in_(2))
6297                         {
6298                                 get_obj_num_hook = kind_is_potion;
6299                                 place_object(yval, xval - 1, AM_NO_FIXED_ART);
6300                                 get_obj_num_hook = kind_is_potion;
6301                                 place_object(yval, xval + 1, AM_NO_FIXED_ART);
6302                         }
6303                         else
6304                         {
6305                                 get_obj_num_hook = kind_is_potion;
6306                                 place_object(yval - 1, xval, AM_NO_FIXED_ART);
6307                                 get_obj_num_hook = kind_is_potion;
6308                                 place_object(yval + 1, xval, AM_NO_FIXED_ART);
6309                         }
6310
6311                         for (y = yval - 2; y <= yval + 2; y++)
6312                                 for (x = xval - 2; x <= xval + 2; x++)
6313                                         cave[y][x].info |= (CAVE_ICKY);
6314
6315                 }
6316                 break;
6317         }
6318
6319         msg_print_wizard(CHEAT_DUNGEON, _("ガラスの部屋が生成されました。", "Glass room was generated."));
6320
6321         return TRUE;
6322 }
6323
6324
6325 /* Create a new floor room with optional light */
6326 void generate_room_floor(int y1, int x1, int y2, int x2, int light)
6327 {
6328         int y, x;
6329         
6330         cave_type *c_ptr;
6331
6332         for (y = y1; y <= y2; y++)
6333         {
6334                 for (x = x1; x <= x2; x++)
6335                 {
6336                         /* Point to grid */
6337                         c_ptr = &cave[y][x];
6338                         place_floor_grid(c_ptr);
6339                         c_ptr->info |= (CAVE_ROOM);
6340                         if (light) c_ptr->info |= (CAVE_GLOW);
6341                 }
6342         }
6343 }
6344
6345 void generate_fill_perm_bold(int y1, int x1, int y2, int x2)
6346 {
6347         int y, x;
6348
6349         for (y = y1; y <= y2; y++)
6350         {
6351                 for (x = x1; x <= x2; x++)
6352                 {
6353                         /* Point to grid */
6354                         place_inner_perm_bold(y, x);
6355                 }
6356         }
6357 }
6358
6359 /* Minimum & maximum town size */
6360 #define MIN_TOWN_WID ((MAX_WID / 3) / 2)
6361 #define MIN_TOWN_HGT ((MAX_HGT / 3) / 2)
6362 #define MAX_TOWN_WID ((MAX_WID / 3) * 2 / 3)
6363 #define MAX_TOWN_HGT ((MAX_HGT / 3) * 2 / 3)
6364
6365 /* Struct for build underground buildings */
6366 typedef struct
6367 {
6368         int y0, x0; /* North-west corner (relative) */
6369         int y1, x1; /* South-east corner (relative) */
6370 }
6371 ugbldg_type;
6372
6373 ugbldg_type *ugbldg;
6374
6375 /*
6376  * Precalculate buildings' location of underground arcade
6377  */
6378 static bool precalc_ugarcade(int town_hgt, int town_wid, int n)
6379 {
6380         int i, y, x, center_y, center_x, tmp, attempt = 10000;
6381         int max_bldg_hgt = 3 * town_hgt / MAX_TOWN_HGT;
6382         int max_bldg_wid = 5 * town_wid / MAX_TOWN_WID;
6383         ugbldg_type *cur_ugbldg;
6384         bool **ugarcade_used, abort;
6385
6386         /* Allocate "ugarcade_used" array (2-dimension) */
6387         C_MAKE(ugarcade_used, town_hgt, bool *);
6388         C_MAKE(*ugarcade_used, town_hgt * town_wid, bool);
6389         for (y = 1; y < town_hgt; y++) ugarcade_used[y] = *ugarcade_used + y * town_wid;
6390
6391         /* Calculate building locations */
6392         for (i = 0; i < n; i++)
6393         {
6394                 cur_ugbldg = &ugbldg[i];
6395                 (void)WIPE(cur_ugbldg, ugbldg_type);
6396
6397                 do
6398                 {
6399                         /* Find the "center" of the store */
6400                         center_y = rand_range(2, town_hgt - 3);
6401                         center_x = rand_range(2, town_wid - 3);
6402
6403                         /* Determine the store boundaries */
6404                         tmp = center_y - randint1(max_bldg_hgt);
6405                         cur_ugbldg->y0 = MAX(tmp, 1);
6406                         tmp = center_x - randint1(max_bldg_wid);
6407                         cur_ugbldg->x0 = MAX(tmp, 1);
6408                         tmp = center_y + randint1(max_bldg_hgt);
6409                         cur_ugbldg->y1 = MIN(tmp, town_hgt - 2);
6410                         tmp = center_x + randint1(max_bldg_wid);
6411                         cur_ugbldg->x1 = MIN(tmp, town_wid - 2);
6412
6413                         /* Scan this building's area */
6414                         for (abort = FALSE, y = cur_ugbldg->y0; (y <= cur_ugbldg->y1) && !abort; y++)
6415                         {
6416                                 for (x = cur_ugbldg->x0; x <= cur_ugbldg->x1; x++)
6417                                 {
6418                                         if (ugarcade_used[y][x])
6419                                         {
6420                                                 abort = TRUE;
6421                                                 break;
6422                                         }
6423                                 }
6424                         }
6425
6426                         attempt--;
6427                 }
6428                 while (abort && attempt); /* Accept this building if no overlapping */
6429
6430                 /* Failed to generate underground arcade */
6431                 if (!attempt) break;
6432
6433                 /*
6434                  * Mark to ugarcade_used[][] as "used"
6435                  * Note: Building-adjacent grids are included for preventing
6436                  * connected bulidings.
6437                  */
6438                 for (y = cur_ugbldg->y0 - 1; y <= cur_ugbldg->y1 + 1; y++)
6439                 {
6440                         for (x = cur_ugbldg->x0 - 1; x <= cur_ugbldg->x1 + 1; x++)
6441                         {
6442                                 ugarcade_used[y][x] = TRUE;
6443                         }
6444                 }
6445         }
6446
6447         /* Free "ugarcade_used" array (2-dimension) */
6448         C_KILL(*ugarcade_used, town_hgt * town_wid, bool);
6449         C_KILL(ugarcade_used, town_hgt, bool *);
6450
6451         /* If i < n, generation is not allowed */
6452         return i == n;
6453 }
6454
6455 /*!
6456  * @brief タイプ16の部屋…地下都市生成のサブルーチン / Actually create buildings
6457  * @return なし
6458  * @param ltcy 生成基準Y座標
6459  * @param ltcx 生成基準X座標
6460  * @param stotes[] 生成する店舗のリスト
6461  * @param n 生成する店舗の数
6462  * @note
6463  * Note: ltcy and ltcx indicate "left top corner".
6464  */
6465 static void build_stores(int ltcy, int ltcx, int stores[], int n)
6466 {
6467         int i, y, x;
6468         IDX j;
6469         ugbldg_type *cur_ugbldg;
6470
6471         for (i = 0; i < n; i++)
6472         {
6473                 cur_ugbldg = &ugbldg[i];
6474
6475                 /* Generate new room */
6476                 generate_room_floor(
6477                         ltcy + cur_ugbldg->y0 - 2, ltcx + cur_ugbldg->x0 - 2,
6478                         ltcy + cur_ugbldg->y1 + 2, ltcx + cur_ugbldg->x1 + 2,
6479                         FALSE);
6480         }
6481
6482         for (i = 0; i < n; i++)
6483         {
6484                 cur_ugbldg = &ugbldg[i];
6485
6486                 /* Build an invulnerable rectangular building */
6487                 generate_fill_perm_bold(
6488                         ltcy + cur_ugbldg->y0, ltcx + cur_ugbldg->x0,
6489                         ltcy + cur_ugbldg->y1, ltcx + cur_ugbldg->x1);
6490
6491                 /* Pick a door direction (S,N,E,W) */
6492                 switch (randint0(4))
6493                 {
6494                 /* Bottom side */
6495                 case 0:
6496                         y = cur_ugbldg->y1;
6497                         x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
6498                         break;
6499
6500                 /* Top side */
6501                 case 1:
6502                         y = cur_ugbldg->y0;
6503                         x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
6504                         break;
6505
6506                 /* Right side */
6507                 case 2:
6508                         y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
6509                         x = cur_ugbldg->x1;
6510                         break;
6511
6512                 /* Left side */
6513                 default:
6514                         y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
6515                         x = cur_ugbldg->x0;
6516                         break;
6517                 }
6518
6519                 for (j = 0; j < max_f_idx; j++)
6520                 {
6521                         if (have_flag(f_info[j].flags, FF_STORE))
6522                         {
6523                                 if (f_info[j].subtype == stores[i]) break;
6524                         }
6525                 }
6526
6527                 /* Clear previous contents, add a store door */
6528                 if (j < max_f_idx)
6529                 {
6530                         cave_set_feat(ltcy + y, ltcx + x, j);
6531
6532                         /* Init store */
6533                         store_init(NO_TOWN, stores[i]);
6534                 }
6535         }
6536 }
6537
6538
6539 /*!
6540  * @brief タイプ16の部屋…地下都市の生成 / Type 16 -- Underground Arcade
6541  * @return なし
6542  * @details
6543  * Town logic flow for generation of new town\n
6544  * Originally from Vanilla 3.0.3\n
6545  *\n
6546  * We start with a fully wiped cave of normal floors.\n
6547  *\n
6548  * Note that town_gen_hack() plays games with the R.N.G.\n
6549  *\n
6550  * This function does NOT do anything about the owners of the stores,\n
6551  * nor the contents thereof.  It only handles the physical layout.\n
6552  */
6553 static bool build_type16(void)
6554 {
6555         int stores[] =
6556         {
6557                 STORE_GENERAL, STORE_ARMOURY, STORE_WEAPON, STORE_TEMPLE,
6558                 STORE_ALCHEMIST, STORE_MAGIC, STORE_BLACK, STORE_BOOK,
6559         };
6560         int n = sizeof stores / sizeof (int);
6561         POSITION i, y, x, y1, x1, yval, xval;
6562         int town_hgt = rand_range(MIN_TOWN_HGT, MAX_TOWN_HGT);
6563         int town_wid = rand_range(MIN_TOWN_WID, MAX_TOWN_WID);
6564         bool prevent_bm = FALSE;
6565
6566         /* Hack -- If already exist black market, prevent building */
6567         for (y = 0; (y < cur_hgt) && !prevent_bm; y++)
6568         {
6569                 for (x = 0; x < cur_wid; x++)
6570                 {
6571                         if (cave[y][x].feat == FF_STORE)
6572                         {
6573                                 prevent_bm = (f_info[cave[y][x].feat].subtype == STORE_BLACK);
6574                                 break;
6575                         }
6576                 }
6577         }
6578         for (i = 0; i < n; i++)
6579         {
6580                 if ((stores[i] == STORE_BLACK) && prevent_bm) stores[i] = stores[--n];
6581         }
6582         if (!n) return FALSE;
6583
6584         /* Allocate buildings array */
6585         C_MAKE(ugbldg, n, ugbldg_type);
6586
6587         /* If cannot build stores, abort */
6588         if (!precalc_ugarcade(town_hgt, town_wid, n))
6589         {
6590                 /* Free buildings array */
6591                 C_KILL(ugbldg, n, ugbldg_type);
6592                 return FALSE;
6593         }
6594
6595         /* Find and reserve some space in the dungeon.  Get center of room. */
6596         if (!find_space(&yval, &xval, town_hgt + 4, town_wid + 4))
6597         {
6598                 /* Free buildings array */
6599                 C_KILL(ugbldg, n, ugbldg_type);
6600                 return FALSE;
6601         }
6602
6603         /* Get top left corner */
6604         y1 = yval - (town_hgt / 2);
6605         x1 = xval - (town_wid / 2);
6606
6607         /* Generate new room */
6608         generate_room_floor(
6609                 y1 + town_hgt / 3, x1 + town_wid / 3,
6610                 y1 + town_hgt * 2 / 3, x1 + town_wid * 2 / 3, FALSE);
6611
6612         /* Build stores */
6613         build_stores(y1, x1, stores, n);
6614
6615         msg_print_wizard(CHEAT_DUNGEON, _("地下街を生成しました", "Underground arcade was generated."));
6616
6617         /* Free buildings array */
6618         C_KILL(ugbldg, n, ugbldg_type);
6619
6620         return TRUE;
6621 }
6622
6623
6624 /*!
6625  * @brief 与えられた部屋型IDに応じて部屋の生成処理分岐を行い結果を返す / Attempt to build a room of the given type at the given block
6626  * @param type 部屋型ID
6627  * @note that we restrict the number of "crowded" rooms to reduce the chance of overflowing the monster list during level creation.
6628  * @return 部屋の精製に成功した場合 TRUE を返す。
6629  */
6630 static bool room_build(int typ)
6631 {
6632         /* Build a room */
6633         switch (typ)
6634         {
6635         /* Build an appropriate room */
6636         case ROOM_T_NORMAL:        return build_type1();
6637         case ROOM_T_OVERLAP:       return build_type2();
6638         case ROOM_T_CROSS:         return build_type3();
6639         case ROOM_T_INNER_FEAT:    return build_type4();
6640         case ROOM_T_NEST:          return build_type5();
6641         case ROOM_T_PIT:           return build_type6();
6642         case ROOM_T_LESSER_VAULT:  return build_type7();
6643         case ROOM_T_GREATER_VAULT: return build_type8();
6644         case ROOM_T_FRACAVE:       return build_type9();
6645         case ROOM_T_RANDOM_VAULT:  return build_type10();
6646         case ROOM_T_OVAL:          return build_type11();
6647         case ROOM_T_CRYPT:         return build_type12();
6648         case ROOM_T_TRAP_PIT:      return build_type13();
6649         case ROOM_T_TRAP:          return build_type14();
6650         case ROOM_T_GLASS:         return build_type15();
6651         case ROOM_T_ARCADE:        return build_type16();
6652         }
6653
6654         /* Paranoia */
6655         return FALSE;
6656 }
6657
6658 /*!
6659  * @brief 指定した部屋の生成確率を別の部屋に加算し、指定した部屋の生成率を0にする
6660  * @param dst 確率を移す先の部屋種ID
6661  * @param src 確率を与える元の部屋種ID
6662  */
6663 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0) 
6664
6665 /*!
6666  * @brief 部屋生成処理のメインルーチン(Sangbandを経由してOangbandからの実装を引用) / Generate rooms in dungeon.  Build bigger rooms at first. [from SAngband (originally from OAngband)]
6667  * @return 部屋生成に成功した場合 TRUE を返す。
6668  */
6669 bool generate_rooms(void)
6670 {
6671         int i;
6672         bool remain;
6673         int crowded = 0;
6674         int total_prob;
6675         int prob_list[ROOM_T_MAX];
6676         int rooms_built = 0;
6677         int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
6678         int level_index = MIN(10, div_round(dun_level, 10));
6679
6680         /* Number of each type of room on this level */
6681         s16b room_num[ROOM_T_MAX];
6682
6683         /* Limit number of rooms */
6684         int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
6685
6686         /* Assume normal cave */
6687         room_info_type *room_info_ptr = room_info_normal;
6688
6689         /*
6690          * Initialize probability list.
6691          */
6692         for (i = 0; i < ROOM_T_MAX; i++)
6693         {
6694                 /* No rooms allowed above their minimum depth. */
6695                 if (dun_level < room_info_ptr[i].min_level)
6696                 {
6697                         prob_list[i] = 0;
6698                 }
6699                 else
6700                 {
6701                         prob_list[i] = room_info_ptr[i].prob[level_index];
6702                 }
6703         }
6704
6705         /*
6706          * XXX -- Various dungeon types and options.
6707          */
6708
6709         /*! @details ダンジョンにBEGINNER、CHAMELEON、SMALLESTいずれのフラグもなく、かつ「常に通常でない部屋を生成する」フラグがONならば、GRATER_VAULTのみを生成対象とする。 / Ironman sees only Greater Vaults */
6710         if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
6711         {
6712                 for (i = 0; i < ROOM_T_MAX; i++)
6713                 {
6714                         if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
6715                         else prob_list[i] = 0;
6716                 }
6717         }
6718
6719         /*! @details ダンジョンにNO_VAULTフラグがあるならば、LESSER_VAULT / GREATER_VAULT/ RANDOM_VAULTを除外 / Forbidden vaults */
6720         else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
6721         {
6722                 prob_list[ROOM_T_LESSER_VAULT] = 0;
6723                 prob_list[ROOM_T_GREATER_VAULT] = 0;
6724                 prob_list[ROOM_T_RANDOM_VAULT] = 0;
6725         }
6726
6727         /*! @details ダンジョンにNO_CAVEフラグがある場合、FRACAVEの生成枠がNORMALに与えられる。CRIPT、OVALの生成枠がINNER_Fに与えられる。/ NO_CAVE dungeon (Castle)*/
6728         if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
6729         {
6730                 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
6731                 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
6732                 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
6733         }
6734
6735         /*! @details ダンジョンにCAVEフラグがある場合、NORMALの生成枠がFRACAVEに与えられる。/ CAVE dungeon (Orc cave etc.) */
6736         else if (d_info[dungeon_type].flags1 & DF1_CAVE)
6737         {
6738                 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
6739         }
6740
6741         /*! @details ダンジョンの基本地形が最初から渓谷かアリーナ型の場合 FRACAVE は生成から除外。 /  No caves when a (random) cavern exists: they look bad */
6742         else if (dun->cavern || dun->empty_level)
6743         {
6744                 prob_list[ROOM_T_FRACAVE] = 0;
6745         }
6746
6747         /*! @details ダンジョンに最初からGLASS_ROOMフラグがある場合、GLASS を生成から除外。/ Forbidden glass rooms */
6748         if (!(d_info[dungeon_type].flags1 & DF1_GLASS_ROOM))
6749         {
6750                 prob_list[ROOM_T_GLASS] = 0;
6751         }
6752
6753         /*! @details ARCADEは同フラグがダンジョンにないと生成されない。 / Forbidden glass rooms */
6754         if (!(d_info[dungeon_type].flags1 & DF1_ARCADE))
6755         {
6756                 prob_list[ROOM_T_ARCADE] = 0;
6757         }
6758
6759         /*
6760          * Initialize number of rooms,
6761          * And calcurate total probability.
6762          */
6763         for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
6764         {
6765                 room_num[i] = 0;
6766                 total_prob += prob_list[i];
6767         }
6768
6769         /*
6770          * Prepare the number of rooms, of all types, we should build
6771          * on this level.
6772          */
6773         for (i = dun_rooms; i > 0; i--)
6774         {
6775                 int room_type;
6776                 int rand = randint0(total_prob);
6777
6778                 /* Get room_type randomly */
6779                 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
6780                 {
6781                         if (rand < prob_list[room_type]) break;
6782                         else rand -= prob_list[room_type];
6783                 }
6784
6785                 /* Paranoia */
6786                 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
6787
6788                 /* Increase the number of rooms of that type we should build. */
6789                 room_num[room_type]++;
6790
6791                 switch (room_type)
6792                 {
6793                 case ROOM_T_NEST:
6794                 case ROOM_T_PIT:
6795                 case ROOM_T_LESSER_VAULT:
6796                 case ROOM_T_TRAP_PIT:
6797                 case ROOM_T_GLASS:
6798                 case ROOM_T_ARCADE:
6799
6800                         /* Large room */
6801                         i -= 2;
6802                         break;
6803
6804                 case ROOM_T_GREATER_VAULT:
6805                 case ROOM_T_RANDOM_VAULT:
6806
6807                         /* Largest room */
6808                         i -= 3;
6809                         break;
6810                 }
6811         }
6812
6813         /*
6814          * Build each type of room one by one until we cannot build any more.
6815          * [from SAngband (originally from OAngband)]
6816          */
6817         while (TRUE)
6818         {
6819                 /* Assume no remaining rooms */
6820                 remain = FALSE;
6821
6822                 for (i = 0; i < ROOM_T_MAX; i++)
6823                 {
6824                         /* What type of room are we building now? */
6825                         int room_type = room_build_order[i];
6826
6827                         /* Go next if none available */
6828                         if (!room_num[room_type]) continue;
6829
6830                         /* Use up one unit */
6831                         room_num[room_type]--;
6832
6833                         /* Build the room. */
6834                         if (room_build(room_type))
6835                         {
6836                                 /* Increase the room built count. */
6837                                 rooms_built++;
6838
6839                                 /* Mark as there was some remaining rooms */
6840                                 remain = TRUE;
6841
6842                                 switch (room_type)
6843                                 {
6844                                 case ROOM_T_PIT:
6845                                 case ROOM_T_NEST:
6846                                 case ROOM_T_TRAP_PIT:
6847
6848                                         /* Avoid too many monsters */
6849                                         if (++crowded >= 2)
6850                                         {
6851                                                 room_num[ROOM_T_PIT] = 0;
6852                                                 room_num[ROOM_T_NEST] = 0;
6853                                                 room_num[ROOM_T_TRAP_PIT] = 0;
6854                                         }
6855                                         break;
6856
6857                                 case ROOM_T_ARCADE:
6858
6859                                         /* Avoid double-town */
6860                                         room_num[ROOM_T_ARCADE] = 0;
6861                                         break;
6862                                 }
6863                         }
6864                 }
6865
6866                 /* End loop if no room remain */
6867                 if (!remain) break;
6868         }
6869
6870         /*! @details 部屋生成数が2未満の場合生成失敗を返す */
6871         if (rooms_built < 2)
6872         {
6873                 msg_format_wizard(CHEAT_DUNGEON, _("部屋数が2未満でした。生成を再試行します。", "Number of rooms was under 2. Retry."), rooms_built);
6874                 return FALSE;
6875         }
6876
6877         msg_format_wizard(CHEAT_DUNGEON, _("このダンジョンの部屋数は %d です。", "Number of Rooms: %d"), rooms_built);
6878
6879         return TRUE;
6880 }