OSDN Git Service

Extend features of tiling. (separation of Cell size and Tile size / add offset position.)
[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(int *y, int *x, int height, int 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 = *y;
490                 dun->cent[dun->cent_n].x = *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         int y, x, y2, x2, yval, xval;
525         int 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         int                     y, x, xval, yval;
720         int                     y1a, x1a, y2a, x2a;
721         int                     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         int                     y, x, dy, dx, wy, wx;
844         int                     y1a, x1a, y2a, x2a;
845         int                     y1b, x1b, y2b, x2b;
846         int                     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         int         y, x, y1, x1;
1102         int         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(int 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(int 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(int 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(int 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(int 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(int 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(int 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(int 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(int 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(int 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(int 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(int 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(int 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(int 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(int 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(int 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         int 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(int 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)(int 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         int 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                 int r_idx = 0, attempts = 100;
2291                 monster_race *r_ptr = NULL;
2292
2293                 while (attempts--)
2294                 {
2295                         /* Get a (hard) monster type */
2296                         r_idx = get_mon_num(dun_level + 11);
2297                         r_ptr = &r_info[r_idx];
2298
2299                         /* Decline incorrect alignment */
2300                         if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2301
2302                         /* Accept this monster */
2303                         break;
2304                 }
2305
2306                 /* Notice failure */
2307                 if (!r_idx || !attempts) return FALSE;
2308
2309                 /* Note the alignment */
2310                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2311                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2312
2313                 nest_mon_info[i].r_idx = r_idx;
2314                 nest_mon_info[i].used = FALSE;
2315         }
2316
2317         /* Find and reserve some space in the dungeon.  Get center of room. */
2318         if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2319
2320         /* Large room */
2321         y1 = yval - 4;
2322         y2 = yval + 4;
2323         x1 = xval - 11;
2324         x2 = xval + 11;
2325
2326         /* Place the floor area */
2327         for (y = y1 - 1; y <= y2 + 1; y++)
2328         {
2329                 for (x = x1 - 1; x <= x2 + 1; x++)
2330                 {
2331                         c_ptr = &cave[y][x];
2332                         place_floor_grid(c_ptr);
2333                         c_ptr->info |= (CAVE_ROOM);
2334                 }
2335         }
2336
2337         /* Place the outer walls */
2338         for (y = y1 - 1; y <= y2 + 1; y++)
2339         {
2340                 c_ptr = &cave[y][x1 - 1];
2341                 place_outer_grid(c_ptr);
2342                 c_ptr = &cave[y][x2 + 1];
2343                 place_outer_grid(c_ptr);
2344         }
2345         for (x = x1 - 1; x <= x2 + 1; x++)
2346         {
2347                 c_ptr = &cave[y1 - 1][x];
2348                 place_outer_grid(c_ptr);
2349                 c_ptr = &cave[y2 + 1][x];
2350                 place_outer_grid(c_ptr);
2351         }
2352
2353
2354         /* Advance to the center room */
2355         y1 = y1 + 2;
2356         y2 = y2 - 2;
2357         x1 = x1 + 2;
2358         x2 = x2 - 2;
2359
2360         /* The inner walls */
2361         for (y = y1 - 1; y <= y2 + 1; y++)
2362         {
2363                 c_ptr = &cave[y][x1 - 1];
2364                 place_inner_grid(c_ptr);
2365                 c_ptr = &cave[y][x2 + 1];
2366                 place_inner_grid(c_ptr);
2367         }
2368
2369         for (x = x1 - 1; x <= x2 + 1; x++)
2370         {
2371                 c_ptr = &cave[y1 - 1][x];
2372                 place_inner_grid(c_ptr);
2373                 c_ptr = &cave[y2 + 1][x];
2374                 place_inner_grid(c_ptr);
2375         }
2376         for (y = y1; y <= y2; y++)
2377         {
2378                 for (x = x1; x <= x2; x++)
2379                 {
2380                         add_cave_info(y, x, CAVE_ICKY);
2381                 }
2382         }
2383
2384         /* Place a secret door */
2385         switch (randint1(4))
2386         {
2387                 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
2388                 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
2389                 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
2390                 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
2391         }
2392
2393         /* Describe */
2394         if (cheat_room)
2395         {
2396                 /* Room type */
2397 #ifdef JP
2398                 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(nest)(%s%s)", n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
2399 #else
2400                 msg_format("Monster nest (%s%s)", n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
2401 #endif
2402         }
2403
2404         /* Place some monsters */
2405         for (y = yval - 2; y <= yval + 2; y++)
2406         {
2407                 for (x = xval - 9; x <= xval + 9; x++)
2408                 {
2409                         int r_idx;
2410
2411                         i = randint0(NUM_NEST_MON_TYPE);
2412                         r_idx = nest_mon_info[i].r_idx;
2413
2414                         /* Place that "random" monster (no groups) */
2415                         (void)place_monster_aux(0, y, x, r_idx, 0L);
2416
2417                         nest_mon_info[i].used = TRUE;
2418                 }
2419         }
2420
2421         if (cheat_room && cheat_hear)
2422         {
2423                 ang_sort_comp = ang_sort_comp_nest_mon_info;
2424                 ang_sort_swap = ang_sort_swap_nest_mon_info;
2425                 ang_sort(nest_mon_info, NULL, NUM_NEST_MON_TYPE);
2426
2427                 /* Dump the entries (prevent multi-printing) */
2428                 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
2429                 {
2430                         if (!nest_mon_info[i].used) break;
2431                         for (; i < NUM_NEST_MON_TYPE - 1; i++)
2432                         {
2433                                 if (nest_mon_info[i].r_idx != nest_mon_info[i + 1].r_idx) break;
2434                                 if (!nest_mon_info[i + 1].used) break;
2435                         }
2436                         msg_print(r_name + r_info[nest_mon_info[i].r_idx].name);
2437                 }
2438         }
2439
2440         return TRUE;
2441 }
2442
2443
2444 /*!
2445  * @brief ¥¿¥¤¥×6¤ÎÉô²°¡Äpit¤òÀ¸À®¤¹¤ë / Type 6 -- Monster pits
2446  * @return ¤Ê¤·
2447  * @details
2448  * A monster pit is a "big" room, with an "inner" room, containing\n
2449  * a "collection" of monsters of a given type organized in the room.\n
2450  *\n
2451  * The inside room in a monster pit appears as shown below, where the\n
2452  * actual monsters in each location depend on the type of the pit\n
2453  *\n
2454  *   XXXXXXXXXXXXXXXXXXXXX\n
2455  *   X0000000000000000000X\n
2456  *   X0112233455543322110X\n
2457  *   X0112233467643322110X\n
2458  *   X0112233455543322110X\n
2459  *   X0000000000000000000X\n
2460  *   XXXXXXXXXXXXXXXXXXXXX\n
2461  *\n
2462  * Note that the monsters in the pit are now chosen by using "get_mon_num()"\n
2463  * to request 16 "appropriate" monsters, sorting them by level, and using\n
2464  * the "even" entries in this sorted list for the contents of the pit.\n
2465  *\n
2466  * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",\n
2467  * which is handled by requiring a specific "breath" attack for all of the\n
2468  * dragons.  This may include "multi-hued" breath.  Note that "wyrms" may\n
2469  * be present in many of the dragon pits, if they have the proper breath.\n
2470  *\n
2471  * Note the use of the "get_mon_num_prep()" function, and the special\n
2472  * "get_mon_num_hook()" restriction function, to prepare the "monster\n
2473  * allocation table" in such a way as to optimize the selection of\n
2474  * "appropriate" non-unique monsters for the pit.\n
2475  *\n
2476  * Note that the "get_mon_num()" function may (rarely) fail, in which case\n
2477  * the pit will be empty.\n
2478  *\n
2479  * Note that "monster pits" will never contain "unique" monsters.\n
2480  */
2481 static bool build_type6(void)
2482 {
2483         int y, x, y1, x1, y2, x2, xval, yval;
2484         int i, j;
2485
2486         int what[16];
2487
2488         monster_type align;
2489
2490         cave_type *c_ptr;
2491
2492         int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
2493         vault_aux_type *n_ptr;
2494
2495         /* No type available */
2496         if (cur_pit_type < 0) return FALSE;
2497
2498         n_ptr = &pit_types[cur_pit_type];
2499
2500         /* Process a preparation function if necessary */
2501         if (n_ptr->prep_func) (*(n_ptr->prep_func))();
2502
2503         /* Prepare allocation table */
2504         get_mon_num_prep(n_ptr->hook_func, NULL);
2505
2506         align.sub_align = SUB_ALIGN_NEUTRAL;
2507
2508         /* Pick some monster types */
2509         for (i = 0; i < 16; i++)
2510         {
2511                 int r_idx = 0, attempts = 100;
2512                 monster_race *r_ptr = NULL;
2513
2514                 while (attempts--)
2515                 {
2516                         /* Get a (hard) monster type */
2517                         r_idx = get_mon_num(dun_level + 11);
2518                         r_ptr = &r_info[r_idx];
2519
2520                         /* Decline incorrect alignment */
2521                         if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2522
2523                         /* Accept this monster */
2524                         break;
2525                 }
2526
2527                 /* Notice failure */
2528                 if (!r_idx || !attempts) return FALSE;
2529
2530                 /* Note the alignment */
2531                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2532                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2533
2534                 what[i] = r_idx;
2535         }
2536
2537         /* Find and reserve some space in the dungeon.  Get center of room. */
2538         if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2539
2540         /* Large room */
2541         y1 = yval - 4;
2542         y2 = yval + 4;
2543         x1 = xval - 11;
2544         x2 = xval + 11;
2545
2546         /* Place the floor area */
2547         for (y = y1 - 1; y <= y2 + 1; y++)
2548         {
2549                 for (x = x1 - 1; x <= x2 + 1; x++)
2550                 {
2551                         c_ptr = &cave[y][x];
2552                         place_floor_grid(c_ptr);
2553                         c_ptr->info |= (CAVE_ROOM);
2554                 }
2555         }
2556
2557         /* Place the outer walls */
2558         for (y = y1 - 1; y <= y2 + 1; y++)
2559         {
2560                 c_ptr = &cave[y][x1 - 1];
2561                 place_outer_grid(c_ptr);
2562                 c_ptr = &cave[y][x2 + 1];
2563                 place_outer_grid(c_ptr);
2564         }
2565         for (x = x1 - 1; x <= x2 + 1; x++)
2566         {
2567                 c_ptr = &cave[y1 - 1][x];
2568                 place_outer_grid(c_ptr);
2569                 c_ptr = &cave[y2 + 1][x];
2570                 place_outer_grid(c_ptr);
2571         }
2572
2573         /* Advance to the center room */
2574         y1 = y1 + 2;
2575         y2 = y2 - 2;
2576         x1 = x1 + 2;
2577         x2 = x2 - 2;
2578
2579         /* The inner walls */
2580         for (y = y1 - 1; y <= y2 + 1; y++)
2581         {
2582                 c_ptr = &cave[y][x1 - 1];
2583                 place_inner_grid(c_ptr);
2584                 c_ptr = &cave[y][x2 + 1];
2585                 place_inner_grid(c_ptr);
2586         }
2587         for (x = x1 - 1; x <= x2 + 1; x++)
2588         {
2589                 c_ptr = &cave[y1 - 1][x];
2590                 place_inner_grid(c_ptr);
2591                 c_ptr = &cave[y2 + 1][x];
2592                 place_inner_grid(c_ptr);
2593         }
2594         for (y = y1; y <= y2; y++)
2595         {
2596                 for (x = x1; x <= x2; x++)
2597                 {
2598                         add_cave_info(y, x, CAVE_ICKY);
2599                 }
2600         }
2601
2602         /* Place a secret door */
2603         switch (randint1(4))
2604         {
2605                 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
2606                 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
2607                 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
2608                 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
2609         }
2610
2611         /* Sort the entries */
2612         for (i = 0; i < 16 - 1; i++)
2613         {
2614                 /* Sort the entries */
2615                 for (j = 0; j < 16 - 1; j++)
2616                 {
2617                         int i1 = j;
2618                         int i2 = j + 1;
2619
2620                         int p1 = r_info[what[i1]].level;
2621                         int p2 = r_info[what[i2]].level;
2622
2623                         /* Bubble */
2624                         if (p1 > p2)
2625                         {
2626                                 int tmp = what[i1];
2627                                 what[i1] = what[i2];
2628                                 what[i2] = tmp;
2629                         }
2630                 }
2631         }
2632
2633         /* Message */
2634         if (cheat_room)
2635         {
2636                 /* Room type */
2637 #ifdef JP
2638                 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(pit)(%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
2639 #else
2640                 msg_format("Monster pit (%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
2641 #endif
2642         }
2643
2644         /* Select the entries */
2645         for (i = 0; i < 8; i++)
2646         {
2647                 /* Every other entry */
2648                 what[i] = what[i * 2];
2649
2650                 if (cheat_hear)
2651                 {
2652                         /* Message */
2653                         msg_print(r_name + r_info[what[i]].name);
2654                 }
2655         }
2656
2657         /* Top and bottom rows */
2658         for (x = xval - 9; x <= xval + 9; x++)
2659         {
2660                 place_monster_aux(0, yval - 2, x, what[0], PM_NO_KAGE);
2661                 place_monster_aux(0, yval + 2, x, what[0], PM_NO_KAGE);
2662         }
2663
2664         /* Middle columns */
2665         for (y = yval - 1; y <= yval + 1; y++)
2666         {
2667                 place_monster_aux(0, y, xval - 9, what[0], PM_NO_KAGE);
2668                 place_monster_aux(0, y, xval + 9, what[0], PM_NO_KAGE);
2669
2670                 place_monster_aux(0, y, xval - 8, what[1], PM_NO_KAGE);
2671                 place_monster_aux(0, y, xval + 8, what[1], PM_NO_KAGE);
2672
2673                 place_monster_aux(0, y, xval - 7, what[1], PM_NO_KAGE);
2674                 place_monster_aux(0, y, xval + 7, what[1], PM_NO_KAGE);
2675
2676                 place_monster_aux(0, y, xval - 6, what[2], PM_NO_KAGE);
2677                 place_monster_aux(0, y, xval + 6, what[2], PM_NO_KAGE);
2678
2679                 place_monster_aux(0, y, xval - 5, what[2], PM_NO_KAGE);
2680                 place_monster_aux(0, y, xval + 5, what[2], PM_NO_KAGE);
2681
2682                 place_monster_aux(0, y, xval - 4, what[3], PM_NO_KAGE);
2683                 place_monster_aux(0, y, xval + 4, what[3], PM_NO_KAGE);
2684
2685                 place_monster_aux(0, y, xval - 3, what[3], PM_NO_KAGE);
2686                 place_monster_aux(0, y, xval + 3, what[3], PM_NO_KAGE);
2687
2688                 place_monster_aux(0, y, xval - 2, what[4], PM_NO_KAGE);
2689                 place_monster_aux(0, y, xval + 2, what[4], PM_NO_KAGE);
2690         }
2691
2692         /* Above/Below the center monster */
2693         for (x = xval - 1; x <= xval + 1; x++)
2694         {
2695                 place_monster_aux(0, yval + 1, x, what[5], PM_NO_KAGE);
2696                 place_monster_aux(0, yval - 1, x, what[5], PM_NO_KAGE);
2697         }
2698
2699         /* Next to the center monster */
2700         place_monster_aux(0, yval, xval + 1, what[6], PM_NO_KAGE);
2701         place_monster_aux(0, yval, xval - 1, what[6], PM_NO_KAGE);
2702
2703         /* Center monster */
2704         place_monster_aux(0, yval, xval, what[7], PM_NO_KAGE);
2705
2706         return TRUE;
2707 }
2708
2709
2710 /*!
2711  * @brief VaultÃÏ·Á¤ò²óž¡¢¾å²¼º¸±¦È¿Å¾¤¹¤ë¤¿¤á¤ÎºÂɸÊÑ´¹¤òÊÖ¤¹ / coordinate translation code
2712  * @param x ÊÑ´¹¤·¤¿¤¤ÅÀ¤ÎXºÂɸ»²¾È¥Ý¥¤¥ó¥¿
2713  * @param y ÊÑ´¹¤·¤¿¤¤ÅÀ¤ÎYºÂɸ»²¾È¥Ý¥¤¥ó¥¿
2714  * @param xoffset VaultÀ¸À®»þ¤Î´ð½àXºÂɸ
2715  * @param yoffset VaultÀ¸À®»þ¤Î´ð½àYºÂɸ
2716  * @param transno ½èÍýID
2717  * @return ¤Ê¤·
2718  */
2719 static void coord_trans(int *x, int *y, int xoffset, int yoffset, int transno)
2720 {
2721         int i;
2722         int temp;
2723
2724         /*
2725          * transno specifies what transformation is required. (0-7)
2726          * The lower two bits indicate by how much the vault is rotated,
2727          * and the upper bit indicates a reflection.
2728          * This is done by using rotation matrices... however since
2729          * these are mostly zeros for rotations by 90 degrees this can
2730          * be expressed simply in terms of swapping and inverting the
2731          * x and y coordinates.
2732          */
2733         for (i = 0; i < transno % 4; i++)
2734         {
2735                 /* rotate by 90 degrees */
2736                 temp = *x;
2737                 *x = -(*y);
2738                 *y = temp;
2739         }
2740
2741         if (transno / 4)
2742         {
2743                 /* Reflect depending on status of 3rd bit. */
2744                 *x = -(*x);
2745         }
2746
2747         /* Add offsets so vault stays in the first quadrant */
2748         *x += xoffset;
2749         *y += yoffset;
2750 }
2751
2752 /*!
2753  * @brief Vault¤ò¥Õ¥í¥¢¤ËÇÛÃÖ¤¹¤ë / Hack -- fill in "vault" rooms
2754  * @param yval À¸À®´ð½àYºÂɸ
2755  * @param xval À¸À®´ð½àXºÂɸ
2756  * @param ymax Vault¤ÎY¥µ¥¤¥º
2757  * @param xmax Vault¤ÎX¥µ¥¤¥º
2758  * @param data Vault¤Î¥Ç¡¼¥¿Ê¸»úÎó
2759  * @param xoffset ÊÑ´¹´ð½àXºÂɸ
2760  * @param yoffset ÊÑ´¹´ð½àYºÂɸ
2761  * @param transno ÊÑ´¹ID
2762  * @return ¤Ê¤·
2763  */
2764 static void build_vault(int yval, int xval, int ymax, int xmax, cptr data,
2765                 int xoffset, int yoffset, int transno)
2766 {
2767         int dx, dy, x, y, i, j;
2768
2769         cptr t;
2770
2771         cave_type *c_ptr;
2772
2773
2774         /* Place dungeon features and objects */
2775         for (t = data, dy = 0; dy < ymax; dy++)
2776         {
2777                 for (dx = 0; dx < xmax; dx++, t++)
2778                 {
2779                         /* prevent loop counter from being overwritten */
2780                         i = dx;
2781                         j = dy;
2782
2783                         /* Flip / rotate */
2784                         coord_trans(&i, &j, xoffset, yoffset, transno);
2785
2786                         /* Extract the location */
2787                         if (transno % 2 == 0)
2788                         {
2789                                 /* no swap of x/y */
2790                                 x = xval - (xmax / 2) + i;
2791                                 y = yval - (ymax / 2) + j;
2792                         }
2793                         else
2794                         {
2795                                 /* swap of x/y */
2796                                 x = xval - (ymax / 2) + i;
2797                                 y = yval - (xmax / 2) + j;
2798                         }
2799
2800                         /* Hack -- skip "non-grids" */
2801                         if (*t == ' ') continue;
2802
2803                         /* Access the grid */
2804                         c_ptr = &cave[y][x];
2805
2806                         /* Lay down a floor */
2807                         place_floor_grid(c_ptr);
2808
2809                         /* Remove any mimic */
2810                         c_ptr->mimic = 0;
2811
2812                         /* Part of a vault */
2813                         c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
2814
2815                         /* Analyze the grid */
2816                         switch (*t)
2817                         {
2818                                 /* Granite wall (outer) */
2819                         case '%':
2820                                 place_outer_noperm_grid(c_ptr);
2821                                 break;
2822
2823                                 /* Granite wall (inner) */
2824                         case '#':
2825                                 place_inner_grid(c_ptr);
2826                                 break;
2827
2828                                 /* Glass wall (inner) */
2829                         case '$':
2830                                 place_inner_grid(c_ptr);
2831                                 c_ptr->feat = feat_glass_wall;
2832                                 break;
2833
2834                                 /* Permanent wall (inner) */
2835                         case 'X':
2836                                 place_inner_perm_grid(c_ptr);
2837                                 break;
2838
2839                                 /* Permanent glass wall (inner) */
2840                         case 'Y':
2841                                 place_inner_perm_grid(c_ptr);
2842                                 c_ptr->feat = feat_permanent_glass_wall;
2843                                 break;
2844
2845                                 /* Treasure/trap */
2846                         case '*':
2847                                 if (randint0(100) < 75)
2848                                 {
2849                                         place_object(y, x, 0L);
2850                                 }
2851                                 else
2852                                 {
2853                                         place_trap(y, x);
2854                                 }
2855                                 break;
2856
2857                                 /* Secret doors */
2858                         case '+':
2859                                 place_secret_door(y, x, DOOR_DEFAULT);
2860                                 break;
2861
2862                                 /* Secret glass doors */
2863                         case '-':
2864                                 place_secret_door(y, x, DOOR_GLASS_DOOR);
2865                                 if (is_closed_door(c_ptr->feat)) c_ptr->mimic = feat_glass_wall;
2866                                 break;
2867
2868                                 /* Curtains */
2869                         case '\'':
2870                                 place_secret_door(y, x, DOOR_CURTAIN);
2871                                 break;
2872
2873                                 /* Trap */
2874                         case '^':
2875                                 place_trap(y, x);
2876                                 break;
2877
2878                                 /* Black market in a dungeon */
2879                         case 'S':
2880                                 set_cave_feat(y, x, feat_black_market);
2881                                 store_init(NO_TOWN, STORE_BLACK);
2882                                 break;
2883
2884                                 /* The Pattern */
2885                         case 'p':
2886                                 set_cave_feat(y, x, feat_pattern_start);
2887                                 break;
2888
2889                         case 'a':
2890                                 set_cave_feat(y, x, feat_pattern_1);
2891                                 break;
2892
2893                         case 'b':
2894                                 set_cave_feat(y, x, feat_pattern_2);
2895                                 break;
2896
2897                         case 'c':
2898                                 set_cave_feat(y, x, feat_pattern_3);
2899                                 break;
2900
2901                         case 'd':
2902                                 set_cave_feat(y, x, feat_pattern_4);
2903                                 break;
2904
2905                         case 'P':
2906                                 set_cave_feat(y, x, feat_pattern_end);
2907                                 break;
2908
2909                         case 'B':
2910                                 set_cave_feat(y, x, feat_pattern_exit);
2911                                 break;
2912
2913                         case 'A':
2914                                 /* Reward for Pattern walk */
2915                                 object_level = base_level + 12;
2916                                 place_object(y, x, AM_GOOD | AM_GREAT);
2917                                 object_level = base_level;
2918                                 break;
2919                         }
2920                 }
2921         }
2922
2923
2924         /* Place dungeon monsters and objects */
2925         for (t = data, dy = 0; dy < ymax; dy++)
2926         {
2927                 for (dx = 0; dx < xmax; dx++, t++)
2928                 {
2929                         /* prevent loop counter from being overwritten */
2930                         i = dx;
2931                         j = dy;
2932
2933                         /* Flip / rotate */
2934                         coord_trans(&i, &j, xoffset, yoffset, transno);
2935
2936                         /* Extract the location */
2937                         if (transno % 2 == 0)
2938                         {
2939                                 /* no swap of x/y */
2940                                 x = xval - (xmax / 2) + i;
2941                                 y = yval - (ymax / 2) + j;
2942                         }
2943                         else
2944                         {
2945                                 /* swap of x/y */
2946                                 x = xval - (ymax / 2) + i;
2947                                 y = yval - (xmax / 2) + j;
2948                         }
2949
2950                         /* Hack -- skip "non-grids" */
2951                         if (*t == ' ') continue;
2952
2953                         /* Analyze the symbol */
2954                         switch (*t)
2955                         {
2956                                 /* Monster */
2957                                 case '&':
2958                                 {
2959                                         monster_level = base_level + 5;
2960                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2961                                         monster_level = base_level;
2962                                         break;
2963                                 }
2964
2965                                 /* Meaner monster */
2966                                 case '@':
2967                                 {
2968                                         monster_level = base_level + 11;
2969                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2970                                         monster_level = base_level;
2971                                         break;
2972                                 }
2973
2974                                 /* Meaner monster, plus treasure */
2975                                 case '9':
2976                                 {
2977                                         monster_level = base_level + 9;
2978                                         place_monster(y, x, PM_ALLOW_SLEEP);
2979                                         monster_level = base_level;
2980                                         object_level = base_level + 7;
2981                                         place_object(y, x, AM_GOOD);
2982                                         object_level = base_level;
2983                                         break;
2984                                 }
2985
2986                                 /* Nasty monster and treasure */
2987                                 case '8':
2988                                 {
2989                                         monster_level = base_level + 40;
2990                                         place_monster(y, x, PM_ALLOW_SLEEP);
2991                                         monster_level = base_level;
2992                                         object_level = base_level + 20;
2993                                         place_object(y, x, AM_GOOD | AM_GREAT);
2994                                         object_level = base_level;
2995                                         break;
2996                                 }
2997
2998                                 /* Monster and/or object */
2999                                 case ',':
3000                                 {
3001                                         if (randint0(100) < 50)
3002                                         {
3003                                                 monster_level = base_level + 3;
3004                                                 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3005                                                 monster_level = base_level;
3006                                         }
3007                                         if (randint0(100) < 50)
3008                                         {
3009                                                 object_level = base_level + 7;
3010                                                 place_object(y, x, 0L);
3011                                                 object_level = base_level;
3012                                         }
3013                                         break;
3014                                 }
3015
3016                         }
3017                 }
3018         }
3019 }
3020
3021
3022 /*!
3023  * @brief ¥¿¥¤¥×7¤ÎÉô²°¡Äv_info.txt¤è¤ê¾®·¿vault¤òÀ¸À®¤¹¤ë / Type 7 -- simple vaults (see "v_info.txt")
3024  * @return ¤Ê¤·
3025  */
3026 static bool build_type7(void)
3027 {
3028         vault_type *v_ptr;
3029         int dummy;
3030         int x, y;
3031         int xval, yval;
3032         int xoffset, yoffset;
3033         int transno;
3034
3035         /* Pick a lesser vault */
3036         for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
3037         {
3038                 /* Access a random vault record */
3039                 v_ptr = &v_info[randint0(max_v_idx)];
3040
3041                 /* Accept the first lesser vault */
3042                 if (v_ptr->typ == 7) break;
3043         }
3044
3045         /* No lesser vault found */
3046         if (dummy >= SAFE_MAX_ATTEMPTS)
3047         {
3048                 if (cheat_room)
3049                 {
3050 #ifdef JP
3051                         msg_print("·Ù¹ð¡ª¾®¤µ¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ­¤Þ¤»¤ó¡ª");
3052 #else
3053                         msg_print("Warning! Could not place lesser vault!");
3054 #endif
3055                 }
3056                 return FALSE;
3057         }
3058
3059         /* pick type of transformation (0-7) */
3060         transno = randint0(8);
3061
3062         /* calculate offsets */
3063         x = v_ptr->wid;
3064         y = v_ptr->hgt;
3065
3066         /* Some huge vault cannot be ratated to fit in the dungeon */
3067         if (x+2 > cur_hgt-2)
3068         {
3069                 /* Forbid 90 or 270 degree ratation */
3070                 transno &= ~1;
3071         }
3072
3073         coord_trans(&x, &y, 0, 0, transno);
3074
3075         if (x < 0)
3076         {
3077                 xoffset = -x - 1;
3078         }
3079         else
3080         {
3081                 xoffset = 0;
3082         }
3083
3084         if (y < 0)
3085         {
3086                 yoffset = -y - 1;
3087         }
3088         else
3089         {
3090                 yoffset = 0;
3091         }
3092
3093         /* Find and reserve some space in the dungeon.  Get center of room. */
3094         if (!find_space(&yval, &xval, abs(y), abs(x))) return FALSE;
3095
3096 #ifdef FORCE_V_IDX
3097         v_ptr = &v_info[2];
3098 #endif
3099
3100         /* Message */
3101 #ifdef JP
3102         if (cheat_room) msg_format("¾®¤µ¤ÊÃϲ¼¼¼(%s)", v_name + v_ptr->name);
3103 #else
3104         if (cheat_room) msg_format("Lesser vault (%s)", v_name + v_ptr->name);
3105 #endif
3106
3107         /* Hack -- Build the vault */
3108         build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
3109                     v_text + v_ptr->text, xoffset, yoffset, transno);
3110
3111         return TRUE;
3112 }
3113
3114 /*!
3115  * @brief ¥¿¥¤¥×8¤ÎÉô²°¡Äv_info.txt¤è¤êÂç·¿vault¤òÀ¸À®¤¹¤ë / Type 8 -- greater vaults (see "v_info.txt")
3116  * @return ¤Ê¤·
3117  */
3118 static bool build_type8(void)
3119 {
3120         vault_type *v_ptr;
3121         int dummy;
3122         int xval, yval;
3123         int x, y;
3124         int transno;
3125         int xoffset, yoffset;
3126
3127         /* Pick a greater vault */
3128         for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
3129         {
3130                 /* Access a random vault record */
3131                 v_ptr = &v_info[randint0(max_v_idx)];
3132
3133                 /* Accept the first greater vault */
3134                 if (v_ptr->typ == 8) break;
3135         }
3136
3137         /* No greater vault found */
3138         if (dummy >= SAFE_MAX_ATTEMPTS)
3139         {
3140                 if (cheat_room)
3141                 {
3142 #ifdef JP
3143                         msg_print("·Ù¹ð¡ªµðÂç¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ­¤Þ¤»¤ó¡ª");
3144 #else
3145                         msg_print("Warning! Could not place greater vault!");
3146 #endif
3147                 }
3148                 return FALSE;
3149         }
3150
3151         /* pick type of transformation (0-7) */
3152         transno = randint0(8);
3153
3154         /* calculate offsets */
3155         x = v_ptr->wid;
3156         y = v_ptr->hgt;
3157
3158         /* Some huge vault cannot be ratated to fit in the dungeon */
3159         if (x+2 > cur_hgt-2)
3160         {
3161                 /* Forbid 90 or 270 degree ratation */
3162                 transno &= ~1;
3163         }
3164
3165         coord_trans(&x, &y, 0, 0, transno);
3166
3167         if (x < 0)
3168         {
3169                 xoffset = - x - 1;
3170         }
3171         else
3172         {
3173                 xoffset = 0;
3174         }
3175
3176         if (y < 0)
3177         {
3178                 yoffset = - y - 1;
3179         }
3180         else
3181         {
3182                 yoffset = 0;
3183         }
3184
3185         /*
3186          * Try to allocate space for room.  If fails, exit
3187          *
3188          * Hack -- Prepare a bit larger space (+2, +2) to 
3189          * prevent generation of vaults with no-entrance.
3190          */
3191         /* Find and reserve some space in the dungeon.  Get center of room. */
3192         if (!find_space(&yval, &xval, abs(y) + 2, abs(x) + 2)) return FALSE;
3193
3194 #ifdef FORCE_V_IDX
3195         v_ptr = &v_info[76 + randint1(3)];
3196 #endif
3197
3198         /* Message */
3199 #ifdef JP
3200         if (cheat_room) msg_format("µðÂç¤ÊÃϲ¼¼¼(%s)", v_name + v_ptr->name);
3201 #else
3202         if (cheat_room) msg_format("Greater vault (%s)", v_name + v_ptr->name);
3203 #endif
3204
3205         /* Hack -- Build the vault */
3206         build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
3207                     v_text + v_ptr->text, xoffset, yoffset, transno);
3208
3209         return TRUE;
3210 }
3211
3212 /*
3213  * Structure to hold all "fill" data
3214  */
3215
3216 typedef struct fill_data_type fill_data_type;
3217
3218 struct fill_data_type
3219 {
3220         /* area size */
3221         int xmin;
3222         int ymin;
3223         int xmax;
3224         int ymax;
3225
3226         /* cutoffs */
3227         int c1;
3228         int c2;
3229         int c3;
3230
3231         /* features to fill with */
3232         int feat1;
3233         int feat2;
3234         int feat3;
3235
3236         int info1;
3237         int info2;
3238         int info3;
3239
3240         /* number of filled squares */
3241         int amount;
3242 };
3243
3244 static fill_data_type fill_data;
3245
3246
3247 /* Store routine for the fractal cave generator */
3248 /* this routine probably should be an inline function or a macro. */
3249 static void store_height(int x, int y, int val)
3250 {
3251         /* if on boundary set val > cutoff so walls are not as square */
3252         if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
3253              (x == fill_data.xmax) || (y == fill_data.ymax)) &&
3254             (val <= fill_data.c1)) val = fill_data.c1 + 1;
3255
3256         /* store the value in height-map format */
3257         cave[y][x].feat = val;
3258
3259         return;
3260 }
3261
3262
3263 /*
3264 * Explanation of the plasma fractal algorithm:
3265 *
3266 * A grid of points is created with the properties of a 'height-map'
3267 * This is done by making the corners of the grid have a random value.
3268 * The grid is then subdivided into one with twice the resolution.
3269 * The new points midway between two 'known' points can be calculated
3270 * by taking the average value of the 'known' ones and randomly adding
3271 * or subtracting an amount proportional to the distance between those
3272 * points.  The final 'middle' points of the grid are then calculated
3273 * by averaging all four of the originally 'known' corner points.  An
3274 * random amount is added or subtracted from this to get a value of the
3275 * height at that point.  The scaling factor here is adjusted to the
3276 * slightly larger distance diagonally as compared to orthogonally.
3277 *
3278 * This is then repeated recursively to fill an entire 'height-map'
3279 * A rectangular map is done the same way, except there are different
3280 * scaling factors along the x and y directions.
3281 *
3282 * A hack to change the amount of correlation between points is done using
3283 * the grd variable.  If the current step size is greater than grd then
3284 * the point will be random, otherwise it will be calculated by the
3285 * above algorithm.  This makes a maximum distance at which two points on
3286 * the height map can affect each other.
3287 *
3288 * How fractal caves are made:
3289 *
3290 * When the map is complete, a cut-off value is used to create a cave.
3291 * Heights below this value are "floor", and heights above are "wall".
3292 * This also can be used to create lakes, by adding more height levels
3293 * representing shallow and deep water/ lava etc.
3294 *
3295 * The grd variable affects the width of passages.
3296 * The roug variable affects the roughness of those passages
3297 *
3298 * The tricky part is making sure the created cave is connected.  This
3299 * is done by 'filling' from the inside and only keeping the 'filled'
3300 * floor.  Walls bounding the 'filled' floor are also kept.  Everything
3301 * else is converted to the normal _extra_.
3302  */
3303
3304
3305 /*
3306  *  Note that this uses the cave.feat array in a very hackish way
3307  *  the values are first set to zero, and then each array location
3308  *  is used as a "heightmap"
3309  *  The heightmap then needs to be converted back into the "feat" format.
3310  *
3311  *  grd=level at which fractal turns on.  smaller gives more mazelike caves
3312  *  roug=roughness level.  16=normal.  higher values make things more convoluted
3313  *    small values are good for smooth walls.
3314  *  size=length of the side of the square cave system.
3315  */
3316 static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cutoff)
3317 {
3318         int xhsize, yhsize, xsize, ysize, maxsize;
3319
3320         /*
3321          * fixed point variables- these are stored as 256 x normal value
3322          * this gives 8 binary places of fractional part + 8 places of normal part
3323          */
3324
3325         u16b xstep, xhstep, ystep, yhstep;
3326         u16b xstep2, xhstep2, ystep2, yhstep2;
3327         u16b i, j, ii, jj, diagsize, xxsize, yysize;
3328         
3329         /* Cache for speed */
3330         u16b xm, xp, ym, yp;
3331
3332         /* redefine size so can change the value if out of range */
3333         xsize = xsiz;
3334         ysize = ysiz;
3335
3336         /* Paranoia about size of the system of caves */
3337         if (xsize > 254) xsize = 254;
3338         if (xsize < 4) xsize = 4;
3339         if (ysize > 254) ysize = 254;
3340         if (ysize < 4) ysize = 4;
3341
3342         /* get offsets to middle of array */
3343         xhsize = xsize / 2;
3344         yhsize = ysize / 2;
3345
3346         /* fix rounding problem */
3347         xsize = xhsize * 2;
3348         ysize = yhsize * 2;
3349
3350         /* get limits of region */
3351         fill_data.xmin = x0 - xhsize;
3352         fill_data.ymin = y0 - yhsize;
3353         fill_data.xmax = x0 + xhsize;
3354         fill_data.ymax = y0 + yhsize;
3355
3356         /* Store cutoff in global for quick access */
3357         fill_data.c1 = cutoff;
3358
3359         /*
3360         * Scale factor for middle points:
3361         * About sqrt(2) * 256 - correct for a square lattice
3362         * approximately correct for everything else.
3363          */
3364         diagsize = 362;
3365
3366         /* maximum of xsize and ysize */
3367         maxsize = (xsize > ysize) ? xsize : ysize;
3368
3369         /* Clear the section */
3370         for (i = 0; i <= xsize; i++)
3371         {
3372                 for (j = 0; j <= ysize; j++)
3373                 {
3374                         /* -1 is a flag for "not done yet" */
3375                         cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
3376                         /* Clear icky flag because may be redoing the cave */
3377                         cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
3378                 }
3379         }
3380
3381         /* Boundaries are walls */
3382         cave[fill_data.ymin][fill_data.xmin].feat = maxsize;
3383         cave[fill_data.ymax][fill_data.xmin].feat = maxsize;
3384         cave[fill_data.ymin][fill_data.xmax].feat = maxsize;
3385         cave[fill_data.ymax][fill_data.xmax].feat = maxsize;
3386
3387         /* Set the middle square to be an open area. */
3388         cave[y0][x0].feat = 0;
3389
3390         /* Initialize the step sizes */
3391         xstep = xhstep = xsize * 256;
3392         ystep = yhstep = ysize * 256;
3393         xxsize = xsize * 256;
3394         yysize = ysize * 256;
3395
3396         /*
3397          * Fill in the rectangle with fractal height data -
3398          * like the 'plasma fractal' in fractint.
3399          */
3400         while ((xhstep > 256) || (yhstep > 256))
3401         {
3402                 /* Halve the step sizes */
3403                 xstep = xhstep;
3404                 xhstep /= 2;
3405                 ystep = yhstep;
3406                 yhstep /= 2;
3407
3408                 /* cache well used values */
3409                 xstep2 = xstep / 256;
3410                 ystep2 = ystep / 256;
3411
3412                 xhstep2 = xhstep / 256;
3413                 yhstep2 = yhstep / 256;
3414
3415                 /* middle top to bottom. */
3416                 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3417                 {
3418                         for (j = 0; j <= yysize; j += ystep)
3419                         {
3420                                 /* cache often used values */
3421                                 ii = i / 256 + fill_data.xmin;
3422                                 jj = j / 256 + fill_data.ymin;
3423
3424                                 /* Test square */
3425                                 if (cave[jj][ii].feat == -1)
3426                                 {
3427                                         if (xhstep2 > grd)
3428                                         {
3429                                                 /* If greater than 'grid' level then is random */
3430                                                 store_height(ii, jj, randint1(maxsize));
3431                                         }
3432                                         else
3433                                         {
3434                                                 /* Average of left and right points +random bit */
3435                                                 store_height(ii, jj,
3436                                                         (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
3437                                                          + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
3438                                                          + (randint1(xstep2) - xhstep2) * roug / 16);
3439                                         }
3440                                 }
3441                         }
3442                 }
3443
3444
3445                 /* middle left to right. */
3446                 for (j = yhstep; j <= yysize - yhstep; j += ystep)
3447                 {
3448                         for (i = 0; i <= xxsize; i += xstep)
3449                         {
3450                                 /* cache often used values */
3451                                 ii = i / 256 + fill_data.xmin;
3452                                 jj = j / 256 + fill_data.ymin;
3453
3454                                 /* Test square */
3455                                 if (cave[jj][ii].feat == -1)
3456                                 {
3457                                         if (xhstep2 > grd)
3458                                         {
3459                                                 /* If greater than 'grid' level then is random */
3460                                                 store_height(ii, jj, randint1(maxsize));
3461                                         }
3462                                         else
3463                                         {
3464                                                 /* Average of up and down points +random bit */
3465                                                 store_height(ii, jj,
3466                                                         (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
3467                                                         + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
3468                                                         + (randint1(ystep2) - yhstep2) * roug / 16);
3469                                         }
3470                                 }
3471                         }
3472                 }
3473
3474                 /* center. */
3475                 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3476                 {
3477                         for (j = yhstep; j <= yysize - yhstep; j += ystep)
3478                         {
3479                                 /* cache often used values */
3480                                 ii = i / 256 + fill_data.xmin;
3481                                 jj = j / 256 + fill_data.ymin;
3482
3483                                 /* Test square */
3484                                 if (cave[jj][ii].feat == -1)
3485                                 {
3486                                         if (xhstep2 > grd)
3487                                         {
3488                                                 /* If greater than 'grid' level then is random */
3489                                                 store_height(ii, jj, randint1(maxsize));
3490                                         }
3491                                         else
3492                                         {
3493                                                 /* Cache reused values. */
3494                                                 xm = fill_data.xmin + (i - xhstep) / 256;
3495                                                 xp = fill_data.xmin + (i + xhstep) / 256;
3496                                                 ym = fill_data.ymin + (j - yhstep) / 256;
3497                                                 yp = fill_data.ymin + (j + yhstep) / 256;
3498
3499                                                 /* 
3500                                                  * Average over all four corners + scale by diagsize to
3501                                                  * reduce the effect of the square grid on the shape of the fractal
3502                                                  */
3503                                                 store_height(ii, jj,
3504                                                         (cave[ym][xm].feat + cave[yp][xm].feat
3505                                                         + cave[ym][xp].feat + cave[yp][xp].feat) / 4
3506                                                         + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
3507                                         }
3508                                 }
3509                         }
3510                 }
3511         }
3512 }
3513
3514
3515 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)
3516 {
3517         /*
3518          * function used to convert from height-map back to the
3519          *  normal angband cave format
3520          */
3521         if (cave[y][x].info & CAVE_ICKY)
3522         {
3523                 /* already done */
3524                 return FALSE;
3525         }
3526         else
3527         {
3528                 /* Show that have looked at this square */
3529                 cave[y][x].info|= (CAVE_ICKY);
3530
3531                 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
3532                 if (cave[y][x].feat <= c1)
3533                 {
3534                         /* 25% of the time use the other tile : it looks better this way */
3535                         if (randint1(100) < 75)
3536                         {
3537                                 cave[y][x].feat = feat1;
3538                                 cave[y][x].info &= ~(CAVE_MASK);
3539                                 cave[y][x].info |= info1;
3540                                 return TRUE;
3541                         }
3542                         else
3543                         {
3544                                 cave[y][x].feat = feat2;
3545                                 cave[y][x].info &= ~(CAVE_MASK);
3546                                 cave[y][x].info |= info2;
3547                                 return TRUE;
3548                         }
3549                 }
3550                 else if (cave[y][x].feat <= c2)
3551                 {
3552                         /* 25% of the time use the other tile : it looks better this way */
3553                         if (randint1(100) < 75)
3554                         {
3555                                 cave[y][x].feat = feat2;
3556                                 cave[y][x].info &= ~(CAVE_MASK);
3557                                 cave[y][x].info |= info2;
3558                                 return TRUE;
3559                         }
3560                         else
3561                         {
3562                                 cave[y][x].feat = feat1;
3563                                 cave[y][x].info &= ~(CAVE_MASK);
3564                                 cave[y][x].info |= info1;
3565                                 return TRUE;
3566                         }
3567                 }
3568                 else if (cave[y][x].feat <= c3)
3569                 {
3570                         cave[y][x].feat = feat3;
3571                         cave[y][x].info &= ~(CAVE_MASK);
3572                         cave[y][x].info |= info3;
3573                         return TRUE;
3574                 }
3575                 /* if greater than cutoff then is a wall */
3576                 else
3577                 {
3578                         place_outer_bold(y, x);
3579                         return FALSE;
3580                 }
3581         }
3582 }
3583
3584
3585
3586
3587 /*
3588  * Quick and nasty fill routine used to find the connected region
3589  * of floor in the middle of the cave
3590  */
3591 static void cave_fill(byte y, byte x)
3592 {
3593         int i, j, d;
3594         int ty, tx;
3595
3596         int flow_tail = 1;
3597         int flow_head = 0;
3598
3599
3600         /*** Start Grid ***/
3601
3602         /* Enqueue that entry */
3603         temp_y[0] = y;
3604         temp_x[0] = x;
3605
3606
3607         /* Now process the queue */
3608         while (flow_head != flow_tail)
3609         {
3610                 /* Extract the next entry */
3611                 ty = temp_y[flow_head];
3612                 tx = temp_x[flow_head];
3613
3614                 /* Forget that entry */
3615                 if (++flow_head == TEMP_MAX) flow_head = 0;
3616
3617                 /* Add the "children" */
3618                 for (d = 0; d < 8; d++)
3619                 {
3620                         int old_head = flow_tail;
3621
3622                         /* Child location */
3623                         j = ty + ddy_ddd[d];
3624                         i = tx + ddx_ddd[d];
3625
3626                         /* Paranoia Don't leave the cave */
3627                         if (!in_bounds(j, i))
3628                         {
3629                                 /* affect boundary */
3630                                 cave[j][i].info |= CAVE_ICKY;
3631 /*                              return; */
3632                         }
3633
3634                         /* If within bounds */
3635                         else if ((i > fill_data.xmin) && (i < fill_data.xmax)
3636                                 && (j > fill_data.ymin) && (j < fill_data.ymax))
3637                         {
3638                                 /* If not a wall or floor done before */
3639                                 if (hack_isnt_wall(j, i,
3640                                         fill_data.c1, fill_data.c2, fill_data.c3,
3641                                         fill_data.feat1, fill_data.feat2, fill_data.feat3,
3642                                         fill_data.info1, fill_data.info2, fill_data.info3))
3643                                 {
3644                                         /* Enqueue that entry */
3645                                         temp_y[flow_tail] = j;
3646                                         temp_x[flow_tail] = i;
3647
3648                                         /* Advance the queue */
3649                                         if (++flow_tail == TEMP_MAX) flow_tail = 0;
3650
3651                                         /* Hack -- Overflow by forgetting new entry */
3652                                         if (flow_tail == flow_head)
3653                                         {
3654                                                 flow_tail = old_head;
3655                                         }
3656                                         else
3657                                         {
3658                                                 /* keep tally of size of cave system */
3659                                                 (fill_data.amount)++;
3660                                         }
3661                                 }
3662                         }
3663                         else
3664                         {
3665                                 /* affect boundary */
3666                                 cave[j][i].info |= CAVE_ICKY;
3667                         }
3668                 }
3669         }
3670 }
3671
3672
3673 static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
3674 {
3675         int x, y, i, xhsize, yhsize;
3676
3677         /* offsets to middle from corner */
3678         xhsize = xsize / 2;
3679         yhsize = ysize / 2;
3680
3681
3682         /*
3683          * select region connected to center of cave system
3684          * this gets rid of alot of isolated one-sqaures that
3685          * can make teleport traps instadeaths...
3686          */
3687
3688         /* cutoffs */
3689         fill_data.c1 = cutoff;
3690         fill_data.c2 = 0;
3691         fill_data.c3 = 0;
3692
3693         /* features to fill with */
3694         fill_data.feat1 = floor_type[randint0(100)];
3695         fill_data.feat2 = floor_type[randint0(100)];
3696         fill_data.feat3 = floor_type[randint0(100)];
3697
3698         fill_data.info1 = CAVE_FLOOR;
3699         fill_data.info2 = CAVE_FLOOR;
3700         fill_data.info3 = CAVE_FLOOR;
3701
3702         /* number of filled squares */
3703         fill_data.amount = 0;
3704
3705         cave_fill((byte)y0, (byte)x0);
3706
3707         /* if tally too small, try again */
3708         if (fill_data.amount < 10)
3709         {
3710                 /* too small - clear area and try again later */
3711                 for (x = 0; x <= xsize; ++x)
3712                 {
3713                         for (y = 0; y <= ysize; ++y)
3714                         {
3715                                 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3716                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3717                         }
3718                 }
3719                 return FALSE;
3720         }
3721
3722         /*
3723          * Do boundarys-check to see if they are next to a filled region
3724          * If not then they are set to normal granite
3725          * If so then they are marked as room walls.
3726          */
3727         for (i = 0; i <= xsize; ++i)
3728         {
3729                 /* top boundary */
3730                 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3731                 {
3732                         /* Next to a 'filled' region? - set to be room walls */
3733                         place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3734                         if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
3735                         cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
3736                         place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3737                 }
3738                 else
3739                 {
3740                         /* set to be normal granite */
3741                         place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3742                 }
3743
3744                 /* bottom boundary */
3745                 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3746                 {
3747                         /* Next to a 'filled' region? - set to be room walls */
3748                         place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3749                         if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
3750                         cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
3751                         place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3752                 }
3753                 else
3754                 {
3755                         /* set to be normal granite */
3756                         place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3757                 }
3758
3759                 /* clear the icky flag-don't need it any more */
3760                 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3761                 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3762         }
3763
3764         /* Do the left and right boundaries minus the corners (done above) */
3765         for (i = 1; i < ysize; ++i)
3766         {
3767                 /* left boundary */
3768                 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
3769                 {
3770                         /* room boundary */
3771                         place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3772                         if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
3773                         cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
3774                         place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3775                 }
3776                 else
3777                 {
3778                         /* outside room */
3779                         place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3780                 }
3781                 /* right boundary */
3782                 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
3783                 {
3784                         /* room boundary */
3785                         place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3786                         if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
3787                         cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
3788                         place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3789                 }
3790                 else
3791                 {
3792                         /* outside room */
3793                         place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3794                 }
3795
3796                 /* clear icky flag -done with it */
3797                 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3798                 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3799         }
3800
3801
3802         /* Do the rest: convert back to the normal format */
3803         for (x = 1; x < xsize; ++x)
3804         {
3805                 for (y = 1; y < ysize; ++y)
3806                 {
3807                         if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3808                             (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3809                         {
3810                                 /* Clear the icky flag in the filled region */
3811                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
3812
3813                                 /* Set appropriate flags */
3814                                 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3815                                 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3816                         }
3817                         else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3818                                  (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3819                         {
3820                                 /* Walls */
3821                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3822                                 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3823                                 if (room)
3824                                 {
3825                                         cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3826                                 }
3827                                 else
3828                                 {
3829
3830                                         place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3831                                         cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
3832                                 }
3833                         }
3834                         else
3835                         {
3836                                 /* Clear the unconnected regions */
3837                                 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3838                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3839                         }
3840                 }
3841         }
3842
3843         /*
3844          * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
3845          * Extra doors appear inside the system.  (Its not very noticeable though.)
3846          * This can be removed by "filling" from the outside in.  This allows a separation
3847          * from _outer_ with _inner_.  (Internal walls are  _outer_ instead.)
3848          * The extra effort for what seems to be only a minor thing (even non-existant if you
3849          * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
3850          * worth it.
3851          */
3852
3853         return TRUE;
3854 }
3855
3856
3857 /*!
3858  * @brief ¥¿¥¤¥×9¤ÎÉô²°¡Ä¥Õ¥é¥¯¥¿¥ë¥«¡¼¥Ö¤Ë¤è¤ëƶ·¢À¸À® / Type 9 -- Driver routine to create fractal cave system
3859  * @return ¤Ê¤·
3860  */
3861 static bool build_type9(void)
3862 {
3863         int grd, roug, cutoff, xsize, ysize, y0, x0;
3864
3865         bool done, light, room;
3866
3867         /* get size: note 'Evenness'*/
3868         xsize = randint1(22) * 2 + 6;
3869         ysize = randint1(15) * 2 + 6;
3870
3871         /* Find and reserve some space in the dungeon.  Get center of room. */
3872         if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3873         {
3874                 /* Limit to the minimum room size, and retry */
3875                 xsize = 8;
3876                 ysize = 8;
3877
3878                 /* Find and reserve some space in the dungeon.  Get center of room. */
3879                 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3880                 {
3881                         /*
3882                          * Still no space?!
3883                          * Try normal room
3884                          */
3885                         return build_type1();
3886                 }
3887         }
3888
3889         light = done = FALSE;
3890         room = TRUE;
3891
3892         if ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3893
3894         while (!done)
3895         {
3896                 /* Note: size must be even or there are rounding problems
3897                 * This causes the tunnels not to connect properly to the room */
3898
3899                 /* testing values for these parameters feel free to adjust */
3900                 grd = 1 << (randint0(4));
3901
3902                 /* want average of about 16 */
3903                 roug = randint1(8) * randint1(4);
3904
3905                 /* about size/2 */
3906                 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
3907                          randint1(xsize / 4) + randint1(ysize / 4);
3908
3909                 /* make it */
3910                 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
3911
3912                 /* Convert to normal format + clean up */
3913                 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
3914         }
3915
3916         return TRUE;
3917 }
3918
3919 #ifdef ALLOW_CAVERNS_AND_LAKES
3920 /*
3921  * Builds a cave system in the center of the dungeon.
3922  */
3923 void build_cavern(void)
3924 {
3925         int grd, roug, cutoff, xsize, ysize, x0, y0;
3926         bool done, light;
3927
3928         light = done = FALSE;
3929         if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3930
3931         /* Make a cave the size of the dungeon */
3932         xsize = cur_wid - 1;
3933         ysize = cur_hgt - 1;
3934         x0 = xsize / 2;
3935         y0 = ysize / 2;
3936
3937         /* Paranoia: make size even */
3938         xsize = x0 * 2;
3939         ysize = y0 * 2;
3940
3941         while (!done)
3942         {
3943                 /* testing values for these parameters: feel free to adjust */
3944                 grd = randint1(4) + 4;
3945
3946                 /* want average of about 16 */
3947                 roug = randint1(8) * randint1(4);
3948
3949                 /* about size/2 */
3950                 cutoff = xsize / 2;
3951
3952                  /* make it */
3953                 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
3954
3955                 /* Convert to normal format+ clean up */
3956                 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
3957         }
3958 }
3959
3960 static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
3961 {
3962         int x, y, i, xhsize, yhsize;
3963         int feat1, feat2, feat3;
3964
3965         /* offsets to middle from corner */
3966         xhsize = xsize / 2;
3967         yhsize = ysize / 2;
3968
3969         /* Get features based on type */
3970         switch (type)
3971         {
3972         case LAKE_T_LAVA: /* Lava */
3973                 feat1 = feat_deep_lava;
3974                 feat2 = feat_shallow_lava;
3975                 feat3 = floor_type[randint0(100)];
3976                 break;
3977         case LAKE_T_WATER: /* Water */
3978                 feat1 = feat_deep_water;
3979                 feat2 = feat_shallow_water;
3980                 feat3 = floor_type[randint0(100)];
3981                 break;
3982         case LAKE_T_CAVE: /* Collapsed cave */
3983                 feat1 = floor_type[randint0(100)];
3984                 feat2 = floor_type[randint0(100)];
3985                 feat3 = feat_rubble;
3986                 break;
3987         case LAKE_T_EARTH_VAULT: /* Earth vault */
3988                 feat1 = feat_rubble;
3989                 feat2 = floor_type[randint0(100)];
3990                 feat3 = feat_rubble;
3991                 break;
3992         case LAKE_T_AIR_VAULT: /* Air vault */
3993                 feat1 = feat_grass;
3994                 feat2 = feat_tree;
3995                 feat3 = feat_grass;
3996                 break;
3997         case LAKE_T_WATER_VAULT: /* Water vault */
3998                 feat1 = feat_shallow_water;
3999                 feat2 = feat_deep_water;
4000                 feat3 = feat_shallow_water;
4001                 break;
4002         case LAKE_T_FIRE_VAULT: /* Fire Vault */
4003                 feat1 = feat_shallow_lava;
4004                 feat2 = feat_deep_lava;
4005                 feat3 = feat_shallow_lava;
4006                 break;
4007
4008         /* Paranoia */
4009         default: return FALSE;
4010         }
4011
4012         /*
4013          * select region connected to center of cave system
4014          * this gets rid of alot of isolated one-sqaures that
4015          * can make teleport traps instadeaths...
4016          */
4017
4018         /* cutoffs */
4019         fill_data.c1 = c1;
4020         fill_data.c2 = c2;
4021         fill_data.c3 = c3;
4022
4023         /* features to fill with */
4024         fill_data.feat1 = feat1;
4025         fill_data.feat2 = feat2;
4026         fill_data.feat3 = feat3;
4027
4028         fill_data.info1 = 0;
4029         fill_data.info2 = 0;
4030         fill_data.info3 = 0;
4031
4032         /* number of filled squares */
4033         fill_data.amount = 0;
4034
4035         /* select region connected to center of cave system
4036         * this gets rid of alot of isolated one-sqaures that
4037         * can make teleport traps instadeaths... */
4038         cave_fill((byte)y0, (byte)x0);
4039
4040         /* if tally too small, try again */
4041         if (fill_data.amount < 10)
4042         {
4043                 /* too small -clear area and try again later */
4044                 for (x = 0; x <= xsize; ++x)
4045                 {
4046                         for (y = 0; y <= ysize; ++y)
4047                         {
4048                                 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
4049                                 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
4050                         }
4051                 }
4052                 return FALSE;
4053         }
4054
4055         /* Do boundarys- set to normal granite */
4056         for (i = 0; i <= xsize; ++i)
4057         {
4058                 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
4059                 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
4060
4061                 /* clear the icky flag-don't need it any more */
4062                 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
4063                 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
4064         }
4065
4066         /* Do the left and right boundaries minus the corners (done above) */
4067
4068         for (i = 1; i < ysize; ++i)
4069         {
4070                 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
4071                 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
4072
4073                 /* clear icky flag -done with it */
4074                 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
4075                 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
4076         }
4077
4078
4079         /* Do the rest: convert back to the normal format */
4080         for (x = 1; x < xsize; ++x)
4081         {
4082                 for (y = 1; y < ysize; ++y)
4083                 {
4084                         /* Fill unconnected regions with granite */
4085                         if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
4086                                 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
4087                                 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
4088
4089                         /* turn off icky flag (no longer needed.) */
4090                         cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
4091
4092                         /* Light lava */
4093                         if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
4094                         {
4095                                 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
4096                         }
4097                 }
4098         }
4099
4100         return TRUE;
4101 }
4102
4103
4104 /*
4105  * makes a lake/collapsed cave system in the center of the dungeon
4106  */
4107 void build_lake(int type)
4108 {
4109         int grd, roug, xsize, ysize, x0, y0;
4110         bool done = FALSE;
4111         int c1, c2, c3;
4112
4113         /* paranoia - exit if lake type out of range. */
4114         if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
4115         {
4116                 msg_format("Invalid lake type (%d)", type);
4117                 return;
4118         }
4119
4120         /* Make the size of the dungeon */
4121         xsize = cur_wid - 1;
4122         ysize = cur_hgt - 1;
4123         x0 = xsize / 2;
4124         y0 = ysize / 2;
4125
4126         /* Paranoia: make size even */
4127         xsize = x0 * 2;
4128         ysize = y0 * 2;
4129
4130         while (!done)
4131         {
4132                 /* testing values for these parameters: feel free to adjust */
4133                 grd = randint1(3) + 4;
4134
4135                 /* want average of about 16 */
4136                 roug = randint1(8) * randint1(4);
4137
4138                 /* Make up size of various componants */
4139                 /* Floor */
4140                 c3 = 3 * xsize / 4;
4141
4142                 /* Deep water/lava */
4143                 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
4144
4145                 /* Shallow boundary */
4146                 c2 = (c1 + c3) / 2;
4147
4148                 /* make it */
4149                 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
4150
4151                 /* Convert to normal format+ clean up */
4152                 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
4153         }
4154 }
4155 #endif /* ALLOW_CAVERNS_AND_LAKES */
4156
4157
4158 /*
4159  * Routine used by the random vault creators to add a door to a location
4160  * Note that range checking has to be done in the calling routine.
4161  *
4162  * The doors must be INSIDE the allocated region.
4163  */
4164 static void add_door(int x, int y)
4165 {
4166         /* Need to have a wall in the center square */
4167         if (!is_outer_bold(y, x)) return;
4168
4169         /* look at:
4170          *  x#x
4171          *  .#.
4172          *  x#x
4173          *
4174          *  where x=don't care
4175          *  .=floor, #=wall
4176          */
4177
4178         if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
4179             (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
4180         {
4181                 /* secret door */
4182                 place_secret_door(y, x, DOOR_DEFAULT);
4183
4184                 /* set boundarys so don't get wide doors */
4185                 place_solid_bold(y, x - 1);
4186                 place_solid_bold(y, x + 1);
4187         }
4188
4189
4190         /* look at:
4191          *  x#x
4192          *  .#.
4193          *  x#x
4194          *
4195          *  where x = don't care
4196          *  .=floor, #=wall
4197          */
4198         if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
4199             is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
4200         {
4201                 /* secret door */
4202                 place_secret_door(y, x, DOOR_DEFAULT);
4203
4204                 /* set boundarys so don't get wide doors */
4205                 place_solid_bold(y - 1, x);
4206                 place_solid_bold(y + 1, x);
4207         }
4208 }
4209
4210
4211 /*
4212  * Routine that fills the empty areas of a room with treasure and monsters.
4213  */
4214 static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
4215 {
4216         int x, y, cx, cy, size;
4217         s32b value;
4218
4219         /* center of room:*/
4220         cx = (x1 + x2) / 2;
4221         cy = (y1 + y2) / 2;
4222
4223         /* Rough measure of size of vault= sum of lengths of sides */
4224         size = abs(x2 - x1) + abs(y2 - y1);
4225
4226         for (x = x1; x <= x2; x++)
4227         {
4228                 for (y = y1; y <= y2; y++)
4229                 {
4230                         /* Thing added based on distance to center of vault
4231                          * Difficulty is 1-easy to 10-hard */
4232                         value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
4233
4234                         /* hack- empty square part of the time */
4235                         if ((randint1(100) - difficulty * 3) > 50) value = 20;
4236
4237                          /* if floor, shallow water and lava */
4238                         if (is_floor_bold(y, x) ||
4239                             (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
4240                         {
4241                                 /* The smaller 'value' is, the better the stuff */
4242                                 if (value < 0)
4243                                 {
4244                                         /* Meanest monster + treasure */
4245                                         monster_level = base_level + 40;
4246                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4247                                         monster_level = base_level;
4248                                         object_level = base_level + 20;
4249                                         place_object(y, x, AM_GOOD);
4250                                         object_level = base_level;
4251                                 }
4252                                 else if (value < 5)
4253                                 {
4254                                         /* Mean monster +treasure */
4255                                         monster_level = base_level + 20;
4256                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4257                                         monster_level = base_level;
4258                                         object_level = base_level + 10;
4259                                         place_object(y, x, AM_GOOD);
4260                                         object_level = base_level;
4261                                 }
4262                                 else if (value < 10)
4263                                 {
4264                                         /* Monster */
4265                                         monster_level = base_level + 9;
4266                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4267                                         monster_level = base_level;
4268                                 }
4269                                 else if (value < 17)
4270                                 {
4271                                         /* Intentional Blank space */
4272
4273                                         /*
4274                                          * (Want some of the vault to be empty
4275                                          * so have room for group monsters.
4276                                          * This is used in the hack above to lower
4277                                          * the density of stuff in the vault.)
4278                                          */
4279                                 }
4280                                 else if (value < 23)
4281                                 {
4282                                         /* Object or trap */
4283                                         if (randint0(100) < 25)
4284                                         {
4285                                                 place_object(y, x, 0L);
4286                                         }
4287                                         else
4288                                         {
4289                                                 place_trap(y, x);
4290                                         }
4291                                 }
4292                                 else if (value < 30)
4293                                 {
4294                                         /* Monster and trap */
4295                                         monster_level = base_level + 5;
4296                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4297                                         monster_level = base_level;
4298                                         place_trap(y, x);
4299                                 }
4300                                 else if (value < 40)
4301                                 {
4302                                         /* Monster or object */
4303                                         if (randint0(100) < 50)
4304                                         {
4305                                                 monster_level = base_level + 3;
4306                                                 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4307                                                 monster_level = base_level;
4308                                         }
4309                                         if (randint0(100) < 50)
4310                                         {
4311                                                 object_level = base_level + 7;
4312                                                 place_object(y, x, 0L);
4313                                                 object_level = base_level;
4314                                         }
4315                                 }
4316                                 else if (value < 50)
4317                                 {
4318                                         /* Trap */
4319                                         place_trap(y, x);
4320                                 }
4321                                 else
4322                                 {
4323                                         /* Various Stuff */
4324
4325                                         /* 20% monster, 40% trap, 20% object, 20% blank space */
4326                                         if (randint0(100) < 20)
4327                                         {
4328                                                 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4329                                         }
4330                                         else if (randint0(100) < 50)
4331                                         {
4332                                                 place_trap(y, x);
4333                                         }
4334                                         else if (randint0(100) < 50)
4335                                         {
4336                                                 place_object(y, x, 0L);
4337                                         }
4338                                 }
4339
4340                         }
4341                 }
4342         }
4343 }
4344
4345
4346 /*
4347  * This function creates a random vault that looks like a collection of bubbles.
4348  * It works by getting a set of coordinates that represent the center of each
4349  * bubble.  The entire room is made by seeing which bubble center is closest. If
4350  * two centers are equidistant then the square is a wall, otherwise it is a floor.
4351  * The only exception is for squares really near a center, these are always floor.
4352  * (It looks better than without this check.)
4353  *
4354  * Note: If two centers are on the same point then this algorithm will create a
4355  *       blank bubble filled with walls. - This is prevented from happening.
4356  */
4357 static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
4358 {
4359         #define BUBBLENUM 10            /* number of bubbles */
4360
4361         /* array of center points of bubbles */
4362         coord center[BUBBLENUM];
4363
4364         int i, j, x, y;
4365         u16b min1, min2, temp;
4366         bool done;
4367
4368         /* Offset from center to top left hand corner */
4369         int xhsize = xsize / 2;
4370         int yhsize = ysize / 2;
4371
4372
4373         if (cheat_room) msg_print("Bubble Vault");
4374
4375         /* Allocate center of bubbles */
4376         center[0].x = (byte)randint1(xsize - 3) + 1;
4377         center[0].y = (byte)randint1(ysize - 3) + 1;
4378
4379         for (i = 1; i < BUBBLENUM; i++)
4380         {
4381                 done = FALSE;
4382
4383                 /* get center and check to see if it is unique */
4384                 while (!done)
4385                 {
4386                         done = TRUE;
4387
4388                         x = randint1(xsize - 3) + 1;
4389                         y = randint1(ysize - 3) + 1;
4390
4391                         for (j = 0; j < i; j++)
4392                         {
4393                                 /* rough test to see if there is an overlap */
4394                                 if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
4395                         }
4396                 }
4397
4398                 center[i].x = x;
4399                 center[i].y = y;
4400         }
4401
4402
4403         /* Top and bottom boundaries */
4404         for (i = 0; i < xsize; i++)
4405         {
4406                 int x = x0 - xhsize + i;
4407
4408                 place_outer_noperm_bold(y0 - yhsize + 0, x);
4409                 cave[y0 - yhsize + 0][x].info |= (CAVE_ROOM | CAVE_ICKY);
4410                 place_outer_noperm_bold(y0 - yhsize + ysize - 1, x);
4411                 cave[y0 - yhsize + ysize - 1][x].info |= (CAVE_ROOM | CAVE_ICKY);
4412         }
4413
4414         /* Left and right boundaries */
4415         for (i = 1; i < ysize - 1; i++)
4416         {
4417                 int y = y0 - yhsize + i;
4418
4419                 place_outer_noperm_bold(y, x0 - xhsize + 0);
4420                 cave[y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
4421                 place_outer_noperm_bold(y, x0 - xhsize + xsize - 1);
4422                 cave[y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
4423         }
4424
4425         /* Fill in middle with bubbles */
4426         for (x = 1; x < xsize - 1; x++)
4427         {
4428                 for (y = 1; y < ysize - 1; y++)
4429                 {
4430                         /* Get distances to two closest centers */
4431
4432                         /* initialize */
4433                         min1 = distance(x, y, center[0].x, center[0].y);
4434                         min2 = distance(x, y, center[1].x, center[1].y);
4435
4436                         if (min1 > min2)
4437                         {
4438                                 /* swap if in wrong order */
4439                                 temp = min1;
4440                                 min1 = min2;
4441                                 min2 = temp;
4442                         }
4443
4444                         /* Scan the rest */
4445                         for (i = 2; i < BUBBLENUM; i++)
4446                         {
4447                                 temp = distance(x, y, center[i].x, center[i].y);
4448
4449                                 if (temp < min1)
4450                                 {
4451                                         /* smallest */
4452                                         min2 = min1;
4453                                         min1 = temp;
4454                                 }
4455                                 else if (temp < min2)
4456                                 {
4457                                         /* second smallest */
4458                                         min2 = temp;
4459                                 }
4460                         }
4461                         if (((min2 - min1) <= 2) && (!(min1 < 3)))
4462                         {
4463                                 /* Boundary at midpoint+ not at inner region of bubble */
4464                                 place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
4465                         }
4466                         else
4467                         {
4468                                 /* middle of a bubble */
4469                                 place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
4470                         }
4471
4472                         /* clean up rest of flags */
4473                         cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
4474                 }
4475         }
4476
4477         /* Try to add some random doors */
4478         for (i = 0; i < 500; i++)
4479         {
4480                 x = randint1(xsize - 3) - xhsize + x0 + 1;
4481                 y = randint1(ysize - 3) - yhsize + y0 + 1;
4482                 add_door(x, y);
4483         }
4484
4485         /* Fill with monsters and treasure, low difficulty */
4486         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
4487 }
4488
4489
4490 /*
4491  * Overlay a rectangular room given its bounds
4492  * This routine is used by build_room_vault
4493  * The area inside the walls is not touched:
4494  * only granite is removed- normal walls stay
4495  */
4496 static void build_room(int x1, int x2, int y1, int y2)
4497 {
4498         int x, y, i, xsize, ysize, temp;
4499
4500         /* Check if rectangle has no width */
4501         if ((x1 == x2) || (y1 == y2)) return;
4502
4503         /* initialize */
4504         if (x1 > x2)
4505         {
4506                 /* Swap boundaries if in wrong order */
4507                 temp = x1;
4508                 x1 = x2;
4509                 x2 = temp;
4510         }
4511
4512         if (y1 > y2)
4513         {
4514                 /* Swap boundaries if in wrong order */
4515                 temp = y1;
4516                 y1 = y2;
4517                 y2 = temp;
4518         }
4519
4520         /* get total widths */
4521         xsize = x2 - x1;
4522         ysize = y2 - y1;
4523
4524
4525         /* Top and bottom boundaries */
4526         for (i = 0; i <= xsize; i++)
4527         {
4528                 place_outer_noperm_bold(y1, x1 + i);
4529                 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4530                 place_outer_noperm_bold(y2, x1 + i);
4531                 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4532         }
4533
4534         /* Left and right boundaries */
4535         for (i = 1; i < ysize; i++)
4536         {
4537                 place_outer_noperm_bold(y1 + i, x1);
4538                 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
4539                 place_outer_noperm_bold(y1 + i, x2);
4540                 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
4541         }
4542
4543         /* Middle */
4544         for (x = 1; x < xsize; x++)
4545         {
4546                 for (y = 1; y < ysize; y++)
4547                 {
4548                         if (is_extra_bold(y1+y, x1+x))
4549                         {
4550                                 /* clear the untouched region */
4551                                 place_floor_bold(y1 + y, x1 + x);
4552                                 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4553                         }
4554                         else
4555                         {
4556                                 /* make it a room- but don't touch */
4557                                 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4558                         }
4559                 }
4560         }
4561 }
4562
4563
4564 /* Create a random vault that looks like a collection of overlapping rooms */
4565
4566 static void build_room_vault(int x0, int y0, int xsize, int ysize)
4567 {
4568         int i, x1, x2, y1, y2, xhsize, yhsize;
4569
4570         /* get offset from center */
4571         xhsize = xsize / 2;
4572         yhsize = ysize / 2;
4573
4574         if (cheat_room) msg_print("Room Vault");
4575
4576         /* fill area so don't get problems with arena levels */
4577         for (x1 = 0; x1 < xsize; x1++)
4578         {
4579                 int x = x0 - xhsize + x1;
4580
4581                 for (y1 = 0; y1 < ysize; y1++)
4582                 {
4583                         int y = y0 - yhsize + y1;
4584
4585                         place_extra_bold(y, x);
4586                         cave[y][x].info &= (~CAVE_ICKY);
4587                 }
4588         }
4589
4590         /* add ten random rooms */
4591         for (i = 0; i < 10; i++)
4592         {
4593                 x1 = randint1(xhsize) * 2 + x0 - xhsize;
4594                 x2 = randint1(xhsize) * 2 + x0 - xhsize;
4595                 y1 = randint1(yhsize) * 2 + y0 - yhsize;
4596                 y2 = randint1(yhsize) * 2 + y0 - yhsize;
4597                 build_room(x1, x2, y1, y2);
4598         }
4599
4600         /* Add some random doors */
4601         for (i = 0; i < 500; i++)
4602         {
4603                 x1 = randint1(xsize - 3) - xhsize + x0 + 1;
4604                 y1 = randint1(ysize - 3) - yhsize + y0 + 1;
4605                 add_door(x1, y1);
4606         }
4607
4608         /* Fill with monsters and treasure, high difficulty */
4609         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
4610 }
4611
4612
4613 /* Create a random vault out of a fractal cave */
4614 static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
4615 {
4616         int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y;
4617         bool done, light, room;
4618
4619         /* round to make sizes even */
4620         xhsize = xsiz / 2;
4621         yhsize = ysiz / 2;
4622         xsize = xhsize * 2;
4623         ysize = yhsize * 2;
4624
4625         if (cheat_room) msg_print("Cave Vault");
4626
4627         light = done = FALSE;
4628         room = TRUE;
4629
4630         while (!done)
4631         {
4632                 /* testing values for these parameters feel free to adjust */
4633                 grd = 1 << randint0(4);
4634
4635                 /* want average of about 16 */
4636                 roug = randint1(8) * randint1(4);
4637
4638                 /* about size/2 */
4639                 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
4640                          randint1(xsize / 4) + randint1(ysize / 4);
4641
4642                 /* make it */
4643                 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
4644
4645                 /* Convert to normal format+ clean up */
4646                 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
4647         }
4648
4649         /* Set icky flag because is a vault */
4650         for (x = 0; x <= xsize; x++)
4651         {
4652                 for (y = 0; y <= ysize; y++)
4653                 {
4654                         cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
4655                 }
4656         }
4657
4658         /* Fill with monsters and treasure, low difficulty */
4659         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
4660 }
4661
4662 /*
4663  * maze vault -- rectangular labyrinthine rooms
4664  *
4665  * maze vault uses two routines:
4666  *    r_visit - a recursive routine that builds the labyrinth
4667  *    build_maze_vault - a driver routine that calls r_visit and adds
4668  *                   monsters, traps and treasure
4669  *
4670  * The labyrinth is built by creating a spanning tree of a graph.
4671  * The graph vertices are at
4672  *    (x, y) = (2j + x1, 2k + y1)   j = 0,...,m-1    k = 0,...,n-1
4673  * and the edges are the vertical and horizontal nearest neighbors.
4674  *
4675  * The spanning tree is created by performing a suitably randomized
4676  * depth-first traversal of the graph. The only adjustable parameter
4677  * is the randint0(3) below; it governs the relative density of
4678  * twists and turns in the labyrinth: smaller number, more twists.
4679  */
4680 static void r_visit(int y1, int x1, int y2, int x2,
4681                     int node, int dir, int *visited)
4682 {
4683         int i, j, m, n, temp, x, y, adj[4];
4684
4685         /* dimensions of vertex array */
4686         m = (x2 - x1) / 2 + 1;
4687         n = (y2 - y1) / 2 + 1;
4688
4689         /* mark node visited and set it to a floor */
4690         visited[node] = 1;
4691         x = 2 * (node % m) + x1;
4692         y = 2 * (node / m) + y1;
4693         place_floor_bold(y, x);
4694
4695         /* setup order of adjacent node visits */
4696         if (one_in_(3))
4697         {
4698                 /* pick a random ordering */
4699                 for (i = 0; i < 4; i++)
4700                         adj[i] = i;
4701                 for (i = 0; i < 4; i++)
4702                 {
4703                         j = randint0(4);
4704                         temp = adj[i];
4705                         adj[i] = adj[j];
4706                         adj[j] = temp;
4707                 }
4708                 dir = adj[0];
4709         }
4710         else
4711         {
4712                 /* pick a random ordering with dir first */
4713                 adj[0] = dir;
4714                 for (i = 1; i < 4; i++)
4715                         adj[i] = i;
4716                 for (i = 1; i < 4; i++)
4717                 {
4718                         j = 1 + randint0(3);
4719                         temp = adj[i];
4720                         adj[i] = adj[j];
4721                         adj[j] = temp;
4722                 }
4723         }
4724
4725         for (i = 0; i < 4; i++)
4726         {
4727                 switch (adj[i])
4728                 {
4729                         case 0:
4730                                 /* (0,+) - check for bottom boundary */
4731                                 if ((node / m < n - 1) && (visited[node + m] == 0))
4732                                 {
4733                                         place_floor_bold(y + 1, x);
4734                                         r_visit(y1, x1, y2, x2, node + m, dir, visited);
4735                                 }
4736                                 break;
4737                         case 1:
4738                                 /* (0,-) - check for top boundary */
4739                                 if ((node / m > 0) && (visited[node - m] == 0))
4740                                 {
4741                                         place_floor_bold(y - 1, x);
4742                                         r_visit(y1, x1, y2, x2, node - m, dir, visited);
4743                                 }
4744                                 break;
4745                         case 2:
4746                                 /* (+,0) - check for right boundary */
4747                                 if ((node % m < m - 1) && (visited[node + 1] == 0))
4748                                 {
4749                                         place_floor_bold(y, x + 1);
4750                                         r_visit(y1, x1, y2, x2, node + 1, dir, visited);
4751                                 }
4752                                 break;
4753                         case 3:
4754                                 /* (-,0) - check for left boundary */
4755                                 if ((node % m > 0) && (visited[node - 1] == 0))
4756                                 {
4757                                         place_floor_bold(y, x - 1);
4758                                         r_visit(y1, x1, y2, x2, node - 1, dir, visited);
4759                                 }
4760                 } /* end switch */
4761         }
4762 }
4763
4764
4765 void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
4766 {
4767         int y, x, dy, dx;
4768         int y1, x1, y2, x2;
4769         int m, n, num_vertices, *visited;
4770         bool light;
4771         cave_type *c_ptr;
4772
4773
4774         if (cheat_room && is_vault) msg_print("Maze Vault");
4775
4776         /* Choose lite or dark */
4777         light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
4778
4779         /* Pick a random room size - randomized by calling routine */
4780         dy = ysize / 2 - 1;
4781         dx = xsize / 2 - 1;
4782
4783         y1 = y0 - dy;
4784         x1 = x0 - dx;
4785         y2 = y0 + dy;
4786         x2 = x0 + dx;
4787
4788         /* generate the room */
4789         for (y = y1 - 1; y <= y2 + 1; y++)
4790         {
4791                 for (x = x1 - 1; x <= x2 + 1; x++)
4792                 {
4793                         c_ptr = &cave[y][x];
4794                         c_ptr->info |= CAVE_ROOM;
4795                         if (is_vault) c_ptr->info |= CAVE_ICKY;
4796                         if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
4797                         {
4798                                 place_outer_grid(c_ptr);
4799                         }
4800                         else if (!is_vault)
4801                         {
4802                                 place_extra_grid(c_ptr);
4803                         }
4804                         else
4805                         {
4806                                 place_inner_grid(c_ptr);
4807                         }
4808                         if (light) c_ptr->info |= (CAVE_GLOW);
4809                 }
4810         }
4811
4812         /* dimensions of vertex array */
4813         m = dx + 1;
4814         n = dy + 1;
4815         num_vertices = m * n;
4816
4817         /* initialize array of visited vertices */
4818         C_MAKE(visited, num_vertices, int);
4819
4820         /* traverse the graph to create a spaning tree, pick a random root */
4821         r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4822
4823         /* Fill with monsters and treasure, low difficulty */
4824         if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
4825
4826         C_KILL(visited, num_vertices, int);
4827 }
4828
4829
4830 /* Build a "mini" checkerboard vault
4831  *
4832  * This is done by making a permanent wall maze and setting
4833  * the diagonal sqaures of the checker board to be granite.
4834  * The vault has two entrances on opposite sides to guarantee
4835  * a way to get in even if the vault abuts a side of the dungeon.
4836  */
4837 static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
4838 {
4839         int dy, dx;
4840         int y1, x1, y2, x2, y, x, total;
4841         int m, n, num_vertices;
4842         int *visited;
4843
4844         if (cheat_room) msg_print("Mini Checker Board Vault");
4845
4846         /* Pick a random room size */
4847         dy = ysize / 2 - 1;
4848         dx = xsize / 2 - 1;
4849
4850         y1 = y0 - dy;
4851         x1 = x0 - dx;
4852         y2 = y0 + dy;
4853         x2 = x0 + dx;
4854
4855
4856         /* generate the room */
4857         for (x = x1 - 2; x <= x2 + 2; x++)
4858         {
4859                 if (!in_bounds(y1-2,x)) break;
4860
4861                 cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4862
4863                 place_outer_noperm_bold(y1-2, x);
4864         }
4865
4866         for (x = x1 - 2; x <= x2 + 2; x++)
4867         {
4868                 if (!in_bounds(y2+2,x)) break;
4869
4870                 cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4871
4872                 place_outer_noperm_bold(y2+2, x);
4873         }
4874
4875         for (y = y1 - 2; y <= y2 + 2; y++)
4876         {
4877                 if (!in_bounds(y,x1-2)) break;
4878
4879                 cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY);
4880
4881                 place_outer_noperm_bold(y, x1-2);
4882         }
4883
4884         for (y = y1 - 2; y <= y2 + 2; y++)
4885         {
4886                 if (!in_bounds(y,x2+2)) break;
4887
4888                 cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY);
4889
4890                 place_outer_noperm_bold(y, x2+2);
4891         }
4892
4893         for (y = y1 - 1; y <= y2 + 1; y++)
4894         {
4895                 for (x = x1 - 1; x <= x2 + 1; x++)
4896                 {
4897                         cave_type *c_ptr = &cave[y][x];
4898
4899                         c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
4900
4901                         /* Permanent walls */
4902                         place_inner_perm_grid(c_ptr);
4903                 }
4904         }
4905
4906
4907         /* dimensions of vertex array */
4908         m = dx + 1;
4909         n = dy + 1;
4910         num_vertices = m * n;
4911
4912         /* initialize array of visited vertices */
4913         C_MAKE(visited, num_vertices, int);
4914
4915         /* traverse the graph to create a spannng tree, pick a random root */
4916         r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4917
4918         /* Make it look like a checker board vault */
4919         for (x = x1; x <= x2; x++)
4920         {
4921                 for (y = y1; y <= y2; y++)
4922                 {
4923                         total = x - x1 + y - y1;
4924                         /* If total is odd- and is a floor then make a wall */
4925                         if ((total % 2 == 1) && is_floor_bold(y, x))
4926                         {
4927                                 place_inner_bold(y, x);
4928                         }
4929                 }
4930         }
4931
4932         /* Make a couple of entrances */
4933         if (one_in_(2))
4934         {
4935                 /* left and right */
4936                 y = randint1(dy) + dy / 2;
4937                 place_inner_bold(y1 + y, x1 - 1);
4938                 place_inner_bold(y1 + y, x2 + 1);
4939         }
4940         else
4941         {
4942                 /* top and bottom */
4943                 x = randint1(dx) + dx / 2;
4944                 place_inner_bold(y1 - 1, x1 + x);
4945                 place_inner_bold(y2 + 1, x1 + x);
4946         }
4947
4948         /* Fill with monsters and treasure, highest difficulty */
4949         fill_treasure(x1, x2, y1, y2, 10);
4950
4951         C_KILL(visited, num_vertices, int);
4952 }
4953
4954
4955 /* Build a town/ castle by using a recursive algorithm.
4956  * Basically divide each region in a probalistic way to create
4957  * smaller regions.  When the regions get too small stop.
4958  *
4959  * The power variable is a measure of how well defended a region is.
4960  * This alters the possible choices.
4961  */
4962 static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
4963 {
4964         int xsize, ysize;
4965         int x, y;
4966         int choice;
4967
4968         /* Temp variables */
4969         int t1, t2, t3, t4;
4970
4971         xsize = x2 - x1;
4972         ysize = y2 - y1;
4973
4974         if ((power < 3) && (xsize > 12) && (ysize > 12))
4975         {
4976                 /* Need outside wall +keep */
4977                 choice = 1;
4978         }
4979         else
4980         {
4981                 if (power < 10)
4982                 {
4983                         /* Make rooms + subdivide */
4984                         if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
4985                         {
4986                                 choice = 4;
4987                         }
4988                         else
4989                         {
4990                                 choice = randint1(2) + 1;
4991                         }
4992                 }
4993                 else
4994                 {
4995                         /* Mostly subdivide */
4996                         choice = randint1(3) + 1;
4997                 }
4998         }
4999
5000         /* Based on the choice made above, do something */
5001
5002         switch (choice)
5003         {
5004                 case 1:
5005                 {
5006                         /* Outer walls */
5007
5008                         /* top and bottom */
5009                         for (x = x1; x <= x2; x++)
5010                         {
5011                                 place_outer_bold(y1, x);
5012                                 place_outer_bold(y2, x);
5013                         }
5014
5015                         /* left and right */
5016                         for (y = y1 + 1; y < y2; y++)
5017                         {
5018                                 place_outer_bold(y, x1);
5019                                 place_outer_bold(y, x2);
5020                         }
5021
5022                         /* Make a couple of entrances */
5023                         if (one_in_(2))
5024                         {
5025                                 /* left and right */
5026                                 y = randint1(ysize) + y1;
5027                                 place_floor_bold(y, x1);
5028                                 place_floor_bold(y, x2);
5029                         }
5030                         else
5031                         {
5032                                 /* top and bottom */
5033                                 x = randint1(xsize) + x1;
5034                                 place_floor_bold(y1, x);
5035                                 place_floor_bold(y2, x);
5036                         }
5037
5038                         /* Select size of keep */
5039                         t1 = randint1(ysize / 3) + y1;
5040                         t2 = y2 - randint1(ysize / 3);
5041                         t3 = randint1(xsize / 3) + x1;
5042                         t4 = x2 - randint1(xsize / 3);
5043
5044                         /* Do outside areas */
5045
5046                         /* Above and below keep */
5047                         build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
5048                         build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
5049
5050                         /* Left and right of keep */
5051                         build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
5052                         build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
5053
5054                         /* Make the keep itself: */
5055                         x1 = t3;
5056                         x2 = t4;
5057                         y1 = t1;
5058                         y2 = t2;
5059                         xsize = x2 - x1;
5060                         ysize = y2 - y1;
5061                         power += 2;
5062
5063                         /* Fall through */
5064                 }
5065                 case 4:
5066                 {
5067                         /* Try to build a room */
5068                         if ((xsize < 3) || (ysize < 3))
5069                         {
5070                                 for (y = y1; y < y2; y++)
5071                                 {
5072                                         for (x = x1; x < x2; x++)
5073                                         {
5074                                                 place_inner_bold(y, x);
5075                                         }
5076                                 }
5077
5078                                 /* Too small */
5079                                 return;
5080                         }
5081
5082                         /* Make outside walls */
5083                         /* top and bottom */
5084                         for (x = x1 + 1; x <= x2 - 1; x++)
5085                         {
5086                                 place_inner_bold(y1 + 1, x);
5087                                 place_inner_bold(y2 - 1, x);
5088                         }
5089
5090                         /* left and right */
5091                         for (y = y1 + 1; y <= y2 - 1; y++)
5092                         {
5093                                 place_inner_bold(y, x1 + 1);
5094                                 place_inner_bold(y, x2 - 1);
5095                         }
5096
5097                         /* Make a door */
5098                         y = randint1(ysize - 3) + y1 + 1;
5099
5100                         if (one_in_(2))
5101                         {
5102                                 /* left */
5103                                 place_floor_bold(y, x1 + 1);
5104                         }
5105                         else
5106                         {
5107                                 /* right */
5108                                 place_floor_bold(y, x2 - 1);
5109                         }
5110
5111                         /* Build the room */
5112                         build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
5113                         break;
5114                 }
5115                 case 2:
5116                 {
5117                         /* Try and divide vertically */
5118                         if (xsize < 3)
5119                         {
5120                                 /* Too small */
5121                                 for (y = y1; y < y2; y++)
5122                                 {
5123                                         for (x = x1; x < x2; x++)
5124                                         {
5125                                                 place_inner_bold(y, x);
5126                                         }
5127                                 }
5128                                 return;
5129                         }
5130
5131                         t1 = randint1(xsize - 2) + x1 + 1;
5132                         build_recursive_room(x1, y1, t1, y2, power - 2);
5133                         build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
5134                         break;
5135                 }
5136                 case 3:
5137                 {
5138                         /* Try and divide horizontally */
5139                         if (ysize < 3)
5140                         {
5141                                 /* Too small */
5142                                 for (y = y1; y < y2; y++)
5143                                 {
5144                                         for (x = x1; x < x2; x++)
5145                                         {
5146                                                 place_inner_bold(y, x);
5147                                         }
5148                                 }
5149                                 return;
5150                         }
5151
5152                         t1 = randint1(ysize - 2) + y1 + 1;
5153                         build_recursive_room(x1, y1, x2, t1, power - 2);
5154                         build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
5155                         break;
5156                 }
5157         }
5158 }
5159
5160
5161 /* Build a castle */
5162
5163 /* Driver routine: clear the region and call the recursive
5164 * room routine.
5165 *
5166 *This makes a vault that looks like a castle/ city in the dungeon.
5167 */
5168 static void build_castle_vault(int x0, int y0, int xsize, int ysize)
5169 {
5170         int dy, dx;
5171         int y1, x1, y2, x2;
5172         int y, x;
5173
5174         /* Pick a random room size */
5175         dy = ysize / 2 - 1;
5176         dx = xsize / 2 - 1;
5177
5178         y1 = y0 - dy;
5179         x1 = x0 - dx;
5180         y2 = y0 + dy;
5181         x2 = x0 + dx;
5182
5183         if (cheat_room) msg_print("Castle Vault");
5184
5185         /* generate the room */
5186         for (y = y1 - 1; y <= y2 + 1; y++)
5187         {
5188                 for (x = x1 - 1; x <= x2 + 1; x++)
5189                 {
5190                         cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
5191                         /* Make everything a floor */
5192                         place_floor_bold(y, x);
5193                 }
5194         }
5195
5196         /* Make the castle */
5197         build_recursive_room(x1, y1, x2, y2, randint1(5));
5198
5199         /* Fill with monsters and treasure, low difficulty */
5200         fill_treasure(x1, x2, y1, y2, randint1(3));
5201 }
5202
5203
5204 /*
5205  * Add outer wall to a floored region
5206  * Note: no range checking is done so must be inside dungeon
5207  * This routine also stomps on doors
5208  */
5209 static void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
5210 {
5211         cave_type *c_ptr;
5212         feature_type *f_ptr;
5213         int i, j;
5214
5215         if (!in_bounds(y, x)) return;
5216
5217         c_ptr = &cave[y][x];
5218
5219         /* hack- check to see if square has been visited before
5220         * if so, then exit (use room flag to do this) */
5221         if (c_ptr->info & CAVE_ROOM) return;
5222
5223         /* set room flag */
5224         c_ptr->info |= CAVE_ROOM;
5225
5226         f_ptr = &f_info[c_ptr->feat];
5227
5228         if (is_floor_bold(y, x))
5229         {
5230                 for (i = -1; i <= 1; i++)
5231                 {
5232                         for (j = -1; j <= 1; j++)
5233                         {
5234                                 if ((x + i >= x1) && (x + i <= x2) &&
5235                                          (y + j >= y1) && (y + j <= y2))
5236                                 {
5237                                         add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
5238                                         if (light) c_ptr->info |= CAVE_GLOW;
5239                                 }
5240                         }
5241                 }
5242         }
5243         else if (is_extra_bold(y, x))
5244         {
5245                 /* Set bounding walls */
5246                 place_outer_bold(y, x);
5247                 if (light) c_ptr->info |= CAVE_GLOW;
5248         }
5249         else if (permanent_wall(f_ptr))
5250         {
5251                 /* Set bounding walls */
5252                 if (light) c_ptr->info |= CAVE_GLOW;
5253         }
5254 }
5255
5256
5257 /*
5258  * Hacked distance formula - gives the 'wrong' answer.
5259  * Used to build crypts
5260  */
5261 static int dist2(int x1, int y1, int x2, int y2,
5262                  int h1, int h2, int h3, int h4)
5263 {
5264         int dx, dy;
5265         dx = abs(x2 - x1);
5266         dy = abs(y2 - y1);
5267
5268         /* Basically this works by taking the normal pythagorean formula
5269          * and using an expansion to express this in a way without the
5270          * square root.  This approximate formula is then perturbed to give
5271          * the distorted results.  (I found this by making a mistake when I was
5272          * trying to fix the circular rooms.)
5273          */
5274
5275         /* h1-h4 are constants that describe the metric */
5276         if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
5277         if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
5278         return (((dx + dy) * 128) / 181 +
5279                 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
5280         /* 128/181 is approx. 1/sqrt(2) */
5281 }
5282
5283
5284 /*
5285  * Build target vault.
5286  * This is made by two concentric "crypts" with perpendicular
5287  * walls creating the cross-hairs.
5288  */
5289 static void build_target_vault(int x0, int y0, int xsize, int ysize)
5290 {
5291         int rad, x, y;
5292
5293         /* Make a random metric */
5294         int h1, h2, h3, h4;
5295         h1 = randint1(32) - 16;
5296         h2 = randint1(16);
5297         h3 = randint1(32);
5298         h4 = randint1(32) - 16;
5299
5300         if (cheat_room) msg_print("Target Vault");
5301
5302         /* work out outer radius */
5303         if (xsize > ysize)
5304         {
5305                 rad = ysize / 2;
5306         }
5307         else
5308         {
5309                 rad = xsize / 2;
5310         }
5311
5312         /* Make floor */
5313         for (x = x0 - rad; x <= x0 + rad; x++)
5314         {
5315                 for (y = y0 - rad; y <= y0 + rad; y++)
5316                 {
5317                         /* clear room flag */
5318                         cave[y][x].info &= ~(CAVE_ROOM);
5319
5320                         /* Vault - so is "icky" */
5321                         cave[y][x].info |= CAVE_ICKY;
5322
5323                         if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5324                         {
5325                                 /* inside- so is floor */
5326                                 place_floor_bold(y, x);
5327                         }
5328                         else
5329                         {
5330                                 /* make granite outside so arena works */
5331                                 place_extra_bold(y, x);
5332                         }
5333
5334                         /* proper boundary for arena */
5335                         if (((y + rad) == y0) || ((y - rad) == y0) ||
5336                             ((x + rad) == x0) || ((x - rad) == x0))
5337                         {
5338                                 place_extra_bold(y, x);
5339                         }
5340                 }
5341         }
5342
5343         /* Find visible outer walls and set to be FEAT_OUTER */
5344         add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
5345                        x0 + rad + 1, y0 + rad + 1);
5346
5347         /* Add inner wall */
5348         for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
5349         {
5350                 for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
5351                 {
5352                         if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
5353                         {
5354                                 /* Make an internal wall */
5355                                 place_inner_bold(y, x);
5356                         }
5357                 }
5358         }
5359
5360         /* Add perpendicular walls */
5361         for (x = x0 - rad; x <= x0 + rad; x++)
5362         {
5363                 place_inner_bold(y0, x);
5364         }
5365
5366         for (y = y0 - rad; y <= y0 + rad; y++)
5367         {
5368                 place_inner_bold(y, x0);
5369         }
5370
5371         /* Make inner vault */
5372         for (y = y0 - 1; y <= y0 + 1; y++)
5373         {
5374                 place_inner_bold(y, x0 - 1);
5375                 place_inner_bold(y, x0 + 1);
5376         }
5377         for (x = x0 - 1; x <= x0 + 1; x++)
5378         {
5379                 place_inner_bold(y0 - 1, x);
5380                 place_inner_bold(y0 + 1, x);
5381         }
5382
5383         place_floor_bold(y0, x0);
5384
5385
5386         /* Add doors to vault */
5387         /* get two distances so can place doors relative to centre */
5388         x = (rad - 2) / 4 + 1;
5389         y = rad / 2 + x;
5390
5391         add_door(x0 + x, y0);
5392         add_door(x0 + y, y0);
5393         add_door(x0 - x, y0);
5394         add_door(x0 - y, y0);
5395         add_door(x0, y0 + x);
5396         add_door(x0, y0 + y);
5397         add_door(x0, y0 - x);
5398         add_door(x0, y0 - y);
5399
5400         /* Fill with stuff - medium difficulty */
5401         fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
5402 }
5403
5404
5405 #ifdef ALLOW_CAVERNS_AND_LAKES
5406 /*
5407  * This routine uses a modified version of the lake code to make a
5408  * distribution of some terrain type over the vault.  This type
5409  * depends on the dungeon depth.
5410  *
5411  * Miniture rooms are then scattered across the vault.
5412  */
5413 static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
5414 {
5415         int grd, roug;
5416         int c1, c2, c3;
5417         bool done = FALSE;
5418         int xsize, ysize, xhsize, yhsize, x, y, i;
5419         int type;
5420
5421
5422         if (cheat_room) msg_print("Elemental Vault");
5423
5424         /* round to make sizes even */
5425         xhsize = xsiz / 2;
5426         yhsize = ysiz / 2;
5427         xsize = xhsize * 2;
5428         ysize = yhsize * 2;
5429
5430         if (dun_level < 25)
5431         {
5432                 /* Earth vault  (Rubble) */
5433                 type = LAKE_T_EARTH_VAULT;
5434         }
5435         else if (dun_level < 50)
5436         {
5437                 /* Air vault (Trees) */
5438                 type = LAKE_T_AIR_VAULT;
5439         }
5440         else if (dun_level < 75)
5441         {
5442                 /* Water vault (shallow water) */
5443                 type = LAKE_T_WATER_VAULT;
5444         }
5445         else
5446         {
5447                 /* Fire vault (shallow lava) */
5448                 type = LAKE_T_FIRE_VAULT;
5449         }
5450
5451         while (!done)
5452         {
5453                 /* testing values for these parameters: feel free to adjust */
5454                 grd = 1 << (randint0(3));
5455
5456                 /* want average of about 16 */
5457                 roug = randint1(8) * randint1(4);
5458
5459                 /* Make up size of various componants */
5460                 /* Floor */
5461                 c3 = 2 * xsize / 3;
5462
5463                 /* Deep water/lava */
5464                 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
5465
5466                 /* Shallow boundary */
5467                 c2 = (c1 + c3) / 2;
5468
5469                 /* make it */
5470                 generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
5471
5472                 /* Convert to normal format+ clean up */
5473                 done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
5474         }
5475
5476         /* Set icky flag because is a vault */
5477         for (x = 0; x <= xsize; x++)
5478         {
5479                 for (y = 0; y <= ysize; y++)
5480                 {
5481                         cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
5482                 }
5483         }
5484
5485         /* make a few rooms in the vault */
5486         for (i = 1; i <= (xsize * ysize) / 50; i++)
5487         {
5488                 build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
5489                                  y0 + randint0(ysize - 4) - ysize / 2 + 2);
5490         }
5491
5492         /* Fill with monsters and treasure, low difficulty */
5493         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
5494                       y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
5495 }
5496 #endif /* ALLOW_CAVERNS_AND_LAKES */
5497
5498
5499 /*!
5500  * @brief ¥¿¥¤¥×10¤ÎÉô²°¡Ä¥é¥ó¥À¥àÀ¸À®vault / Type 10 -- Random vaults
5501  * @return ¤Ê¤·
5502  */
5503 static bool build_type10(void)
5504 {
5505         int y0, x0, xsize, ysize, vtype;
5506
5507         /* Get size */
5508         /* big enough to look good, small enough to be fairly common. */
5509         xsize = randint1(22) + 22;
5510         ysize = randint1(11) + 11;
5511
5512         /* Find and reserve some space in the dungeon.  Get center of room. */
5513         if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
5514
5515         /* Select type of vault */
5516 #ifdef ALLOW_CAVERNS_AND_LAKES
5517         do
5518         {
5519                 vtype = randint1(15);
5520         }
5521         while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
5522                 ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11)));
5523 #else /* ALLOW_CAVERNS_AND_LAKES */
5524         do
5525         {
5526                 vtype = randint1(7);
5527         }
5528         while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
5529                 ((vtype == 1) || (vtype == 3)));
5530 #endif /* ALLOW_CAVERNS_AND_LAKES */
5531
5532         switch (vtype)
5533         {
5534                 /* Build an appropriate room */
5535                 case 1: case  9: build_bubble_vault(x0, y0, xsize, ysize); break;
5536                 case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
5537                 case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
5538                 case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
5539                 case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
5540                 case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
5541                 case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
5542 #ifdef ALLOW_CAVERNS_AND_LAKES
5543                 case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
5544 #endif /* ALLOW_CAVERNS_AND_LAKES */
5545                 /* I know how to add a few more... give me some time. */
5546
5547                 /* Paranoia */
5548                 default: return FALSE;
5549         }
5550
5551         return TRUE;
5552 }
5553
5554
5555 /*!
5556  * @brief ¥¿¥¤¥×11¤ÎÉô²°¡Ä±ß·ÁÉô²°¤ÎÀ¸À® / Type 11 -- Build an vertical oval room.
5557  * @return ¤Ê¤·
5558  * @details
5559  * For every grid in the possible square, check the distance.\n
5560  * If it's less than the radius, make it a room square.\n
5561  *\n
5562  * When done fill from the inside to find the walls,\n
5563  */
5564 static bool build_type11(void)
5565 {
5566         int rad, x, y, x0, y0;
5567         int light = FALSE;
5568
5569         /* Occasional light */
5570         if ((randint1(dun_level) <= 15) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5571
5572         rad = randint0(9);
5573
5574         /* Find and reserve some space in the dungeon.  Get center of room. */
5575         if (!find_space(&y0, &x0, rad * 2 + 1, rad * 2 + 1)) return FALSE;
5576
5577         /* Make circular floor */
5578         for (x = x0 - rad; x <= x0 + rad; x++)
5579         {
5580                 for (y = y0 - rad; y <= y0 + rad; y++)
5581                 {
5582                         if (distance(y0, x0, y, x) <= rad - 1)
5583                         {
5584                                 /* inside- so is floor */
5585                                 place_floor_bold(y, x);
5586                         }
5587                         else if (distance(y0, x0, y, x) <= rad + 1)
5588                         {
5589                                 /* make granite outside so arena works */
5590                                 place_extra_bold(y, x);
5591                         }
5592                 }
5593         }
5594
5595         /* Find visible outer walls and set to be FEAT_OUTER */
5596         add_outer_wall(x0, y0, light, x0 - rad, y0 - rad, x0 + rad, y0 + rad);
5597
5598         return TRUE;
5599 }
5600
5601
5602 /*!
5603  * @brief ¥¿¥¤¥×12¤ÎÉô²°¡Ä¥É¡¼¥à·¿Éô²°¤ÎÀ¸À® / Type 12 -- Build crypt room.
5604  * @return ¤Ê¤·
5605  * @details
5606  * For every grid in the possible square, check the (fake) distance.\n
5607  * If it's less than the radius, make it a room square.\n
5608  *\n
5609  * When done fill from the inside to find the walls,\n
5610  */
5611 static bool build_type12(void)
5612 {
5613         int rad, x, y, x0, y0;
5614         int light = FALSE;
5615         bool emptyflag = TRUE;
5616
5617         /* Make a random metric */
5618         int h1, h2, h3, h4;
5619         h1 = randint1(32) - 16;
5620         h2 = randint1(16);
5621         h3 = randint1(32);
5622         h4 = randint1(32) - 16;
5623
5624         /* Occasional light */
5625         if ((randint1(dun_level) <= 5) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5626
5627         rad = randint1(9);
5628
5629         /* Find and reserve some space in the dungeon.  Get center of room. */
5630         if (!find_space(&y0, &x0, rad * 2 + 3, rad * 2 + 3)) return FALSE;
5631
5632         /* Make floor */
5633         for (x = x0 - rad; x <= x0 + rad; x++)
5634         {
5635                 for (y = y0 - rad; y <= y0 + rad; y++)
5636                 {
5637                         /* clear room flag */
5638                         cave[y][x].info &= ~(CAVE_ROOM);
5639
5640                         if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5641                         {
5642                                 /* inside - so is floor */
5643                                 place_floor_bold(y, x);
5644                         }
5645                         else if (distance(y0, x0, y, x) < 3)
5646                         {
5647                                 place_floor_bold(y, x);
5648                         }
5649                         else
5650                         {
5651                                 /* make granite outside so arena works */
5652                                 place_extra_bold(y, x);
5653                         }
5654
5655                         /* proper boundary for arena */
5656                         if (((y + rad) == y0) || ((y - rad) == y0) ||
5657                             ((x + rad) == x0) || ((x - rad) == x0))
5658                         {
5659                                 place_extra_bold(y, x);
5660                         }
5661                 }
5662         }
5663
5664         /* Find visible outer walls and set to be FEAT_OUTER */
5665         add_outer_wall(x0, y0, light, x0 - rad - 1, y0 - rad - 1,
5666                        x0 + rad + 1, y0 + rad + 1);
5667
5668         /* Check to see if there is room for an inner vault */
5669         for (x = x0 - 2; x <= x0 + 2; x++)
5670         {
5671                 for (y = y0 - 2; y <= y0 + 2; y++)
5672                 {
5673                         if (!is_floor_bold(y, x))
5674                         {
5675                                 /* Wall in the way */
5676                                 emptyflag = FALSE;
5677                         }
5678                 }
5679         }
5680
5681         if (emptyflag && one_in_(2))
5682         {
5683                 /* Build the vault */
5684                 build_small_room(x0, y0);
5685
5686                 /* Place a treasure in the vault */
5687                 place_object(y0, x0, 0L);
5688
5689                 /* Let's guard the treasure well */
5690                 vault_monsters(y0, x0, randint0(2) + 3);
5691
5692                 /* Traps naturally */
5693                 vault_traps(y0, x0, 4, 4, randint0(3) + 2);
5694         }
5695
5696         return TRUE;
5697 }
5698
5699
5700 /*
5701  * Helper function for "trapped monster pit"
5702  */
5703 static bool vault_aux_trapped_pit(int r_idx)
5704 {
5705         monster_race *r_ptr = &r_info[r_idx];
5706
5707         /* Validate the monster */
5708         if (!vault_monster_okay(r_idx)) return (FALSE);
5709
5710         /* No wall passing monster */
5711         if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return (FALSE);
5712
5713         /* Okay */
5714         return (TRUE);
5715 }
5716
5717
5718 /*!
5719  * @brief ¥¿¥¤¥×13¤ÎÉô²°¡Ä¥È¥é¥Ã¥×pit¤ÎÀ¸À® / Type 13 -- Trapped monster pits
5720  * @return ¤Ê¤·
5721  * @details
5722  * A trapped monster pit is a "big" room with a straight corridor in\n
5723  * which wall opening traps are placed, and with two "inner" rooms\n
5724  * containing a "collection" of monsters of a given type organized in\n
5725  * the room.\n
5726  *\n
5727  * The trapped monster pit appears as shown below, where the actual\n
5728  * monsters in each location depend on the type of the pit\n
5729  *\n
5730  *  XXXXXXXXXXXXXXXXXXXXXXXXX\n
5731  *  X                       X\n
5732  *  XXXXXXXXXXXXXXXXXXXXXXX X\n
5733  *  XXXXX001123454321100XXX X\n
5734  *  XXX0012234567654322100X X\n
5735  *  XXXXXXXXXXXXXXXXXXXXXXX X\n
5736  *  X           ^           X\n
5737  *  X XXXXXXXXXXXXXXXXXXXXXXX\n
5738  *  X X0012234567654322100XXX\n
5739  *  X XXX001123454321100XXXXX\n
5740  *  X XXXXXXXXXXXXXXXXXXXXXXX\n
5741  *  X                       X\n
5742  *  XXXXXXXXXXXXXXXXXXXXXXXXX\n
5743  *\n
5744  * Note that the monsters in the pit are now chosen by using "get_mon_num()"\n
5745  * to request 16 "appropriate" monsters, sorting them by level, and using\n
5746  * the "even" entries in this sorted list for the contents of the pit.\n
5747  *\n
5748  * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",\n
5749  * which is handled by requiring a specific "breath" attack for all of the\n
5750  * dragons.  This may include "multi-hued" breath.  Note that "wyrms" may\n
5751  * be present in many of the dragon pits, if they have the proper breath.\n
5752  *\n
5753  * Note the use of the "get_mon_num_prep()" function, and the special\n
5754  * "get_mon_num_hook()" restriction function, to prepare the "monster\n
5755  * allocation table" in such a way as to optimize the selection of\n
5756  * "appropriate" non-unique monsters for the pit.\n
5757  *\n
5758  * Note that the "get_mon_num()" function may (rarely) fail, in which case\n
5759  * the pit will be empty.\n
5760  *\n
5761  * Note that "monster pits" will never contain "unique" monsters.\n
5762  */
5763 static bool build_type13(void)
5764 {
5765         static int placing[][3] = {
5766                 {-2, -9, 0}, {-2, -8, 0}, {-3, -7, 0}, {-3, -6, 0},
5767                 {+2, -9, 0}, {+2, -8, 0}, {+3, -7, 0}, {+3, -6, 0},
5768                 {-2, +9, 0}, {-2, +8, 0}, {-3, +7, 0}, {-3, +6, 0},
5769                 {+2, +9, 0}, {+2, +8, 0}, {+3, +7, 0}, {+3, +6, 0},
5770                 {-2, -7, 1}, {-3, -5, 1}, {-3, -4, 1}, 
5771                 {+2, -7, 1}, {+3, -5, 1}, {+3, -4, 1}, 
5772                 {-2, +7, 1}, {-3, +5, 1}, {-3, +4, 1}, 
5773                 {+2, +7, 1}, {+3, +5, 1}, {+3, +4, 1},
5774                 {-2, -6, 2}, {-2, -5, 2}, {-3, -3, 2},
5775                 {+2, -6, 2}, {+2, -5, 2}, {+3, -3, 2},
5776                 {-2, +6, 2}, {-2, +5, 2}, {-3, +3, 2},
5777                 {+2, +6, 2}, {+2, +5, 2}, {+3, +3, 2},
5778                 {-2, -4, 3}, {-3, -2, 3},
5779                 {+2, -4, 3}, {+3, -2, 3},
5780                 {-2, +4, 3}, {-3, +2, 3},
5781                 {+2, +4, 3}, {+3, +2, 3},
5782                 {-2, -3, 4}, {-3, -1, 4},
5783                 {+2, -3, 4}, {+3, -1, 4},
5784                 {-2, +3, 4}, {-3, +1, 4},
5785                 {+2, +3, 4}, {+3, +1, 4},
5786                 {-2, -2, 5}, {-3, 0, 5}, {-2, +2, 5},
5787                 {+2, -2, 5}, {+3, 0, 5}, {+2, +2, 5},
5788                 {-2, -1, 6}, {-2, +1, 6},
5789                 {+2, -1, 6}, {+2, +1, 6},
5790                 {-2, 0, 7}, {+2, 0, 7},
5791                 {0, 0, -1}
5792         };
5793
5794         int y, x, y1, x1, y2, x2, xval, yval;
5795         int i, j;
5796
5797         int what[16];
5798
5799         monster_type align;
5800
5801         cave_type *c_ptr;
5802
5803         int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
5804         vault_aux_type *n_ptr;
5805
5806         /* Only in Angband */
5807         if (dungeon_type != DUNGEON_ANGBAND) return FALSE;
5808
5809         /* No type available */
5810         if (cur_pit_type < 0) return FALSE;
5811
5812         n_ptr = &pit_types[cur_pit_type];
5813
5814         /* Process a preparation function if necessary */
5815         if (n_ptr->prep_func) (*(n_ptr->prep_func))();
5816
5817         /* Prepare allocation table */
5818         get_mon_num_prep(n_ptr->hook_func, vault_aux_trapped_pit);
5819
5820         align.sub_align = SUB_ALIGN_NEUTRAL;
5821
5822         /* Pick some monster types */
5823         for (i = 0; i < 16; i++)
5824         {
5825                 int r_idx = 0, attempts = 100;
5826                 monster_race *r_ptr = NULL;
5827
5828                 while (attempts--)
5829                 {
5830                         /* Get a (hard) monster type */
5831                         r_idx = get_mon_num(dun_level + 0);
5832                         r_ptr = &r_info[r_idx];
5833
5834                         /* Decline incorrect alignment */
5835                         if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
5836
5837                         /* Accept this monster */
5838                         break;
5839                 }
5840
5841                 /* Notice failure */
5842                 if (!r_idx || !attempts) return FALSE;
5843
5844                 /* Note the alignment */
5845                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
5846                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
5847
5848                 what[i] = r_idx;
5849         }
5850
5851         /* Find and reserve some space in the dungeon.  Get center of room. */
5852         if (!find_space(&yval, &xval, 13, 25)) return FALSE;
5853
5854         /* Large room */
5855         y1 = yval - 5;
5856         y2 = yval + 5;
5857         x1 = xval - 11;
5858         x2 = xval + 11;
5859
5860         /* Fill with inner walls */
5861         for (y = y1 - 1; y <= y2 + 1; y++)
5862         {
5863                 for (x = x1 - 1; x <= x2 + 1; x++)
5864                 {
5865                         c_ptr = &cave[y][x];
5866                         place_inner_grid(c_ptr);
5867                         c_ptr->info |= (CAVE_ROOM);
5868                 }
5869         }
5870
5871         /* Place the floor area 1 */
5872         for (x = x1 + 3; x <= x2 - 3; x++)
5873         {
5874                 c_ptr = &cave[yval-2][x];
5875                 place_floor_grid(c_ptr);
5876                 add_cave_info(yval-2, x, CAVE_ICKY);
5877
5878                 c_ptr = &cave[yval+2][x];
5879                 place_floor_grid(c_ptr);
5880                 add_cave_info(yval+2, x, CAVE_ICKY);
5881         }
5882
5883         /* Place the floor area 2 */
5884         for (x = x1 + 5; x <= x2 - 5; x++)
5885         {
5886                 c_ptr = &cave[yval-3][x];
5887                 place_floor_grid(c_ptr);
5888                 add_cave_info(yval-3, x, CAVE_ICKY);
5889
5890                 c_ptr = &cave[yval+3][x];
5891                 place_floor_grid(c_ptr);
5892                 add_cave_info(yval+3, x, CAVE_ICKY);
5893         }
5894
5895         /* Corridor */
5896         for (x = x1; x <= x2; x++)
5897         {
5898                 c_ptr = &cave[yval][x];
5899                 place_floor_grid(c_ptr);
5900                 c_ptr = &cave[y1][x];
5901                 place_floor_grid(c_ptr);
5902                 c_ptr = &cave[y2][x];
5903                 place_floor_grid(c_ptr);
5904         }
5905
5906         /* Place the outer walls */
5907         for (y = y1 - 1; y <= y2 + 1; y++)
5908         {
5909                 c_ptr = &cave[y][x1 - 1];
5910                 place_outer_grid(c_ptr);
5911                 c_ptr = &cave[y][x2 + 1];
5912                 place_outer_grid(c_ptr);
5913         }
5914         for (x = x1 - 1; x <= x2 + 1; x++)
5915         {
5916                 c_ptr = &cave[y1 - 1][x];
5917                 place_outer_grid(c_ptr);
5918                 c_ptr = &cave[y2 + 1][x];
5919                 place_outer_grid(c_ptr);
5920         }
5921
5922         /* Random corridor */
5923         if (one_in_(2))
5924         {
5925                 for (y = y1; y <= yval; y++)
5926                 {
5927                         place_floor_bold(y, x2);
5928                         place_solid_bold(y, x1-1);
5929                 }
5930                 for (y = yval; y <= y2 + 1; y++)
5931                 {
5932                         place_floor_bold(y, x1);
5933                         place_solid_bold(y, x2+1);
5934                 }
5935         }
5936         else
5937         {
5938                 for (y = yval; y <= y2 + 1; y++)
5939                 {
5940                         place_floor_bold(y, x1);
5941                         place_solid_bold(y, x2+1);
5942                 }
5943                 for (y = y1; y <= yval; y++)
5944                 {
5945                         place_floor_bold(y, x2);
5946                         place_solid_bold(y, x1-1);
5947                 }
5948         }
5949
5950         /* Place the wall open trap */
5951         cave[yval][xval].mimic = cave[yval][xval].feat;
5952         cave[yval][xval].feat = feat_trap_open;
5953
5954         /* Sort the entries */
5955         for (i = 0; i < 16 - 1; i++)
5956         {
5957                 /* Sort the entries */
5958                 for (j = 0; j < 16 - 1; j++)
5959                 {
5960                         int i1 = j;
5961                         int i2 = j + 1;
5962
5963                         int p1 = r_info[what[i1]].level;
5964                         int p2 = r_info[what[i2]].level;
5965
5966                         /* Bubble */
5967                         if (p1 > p2)
5968                         {
5969                                 int tmp = what[i1];
5970                                 what[i1] = what[i2];
5971                                 what[i2] = tmp;
5972                         }
5973                 }
5974         }
5975
5976         /* Message */
5977         if (cheat_room)
5978         {
5979                 /* Room type */
5980 #ifdef JP
5981                 msg_format("%s%s¤Î櫥ԥåÈ", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5982 #else
5983                 msg_format("Trapped monster pit (%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5984 #endif
5985         }
5986
5987         /* Select the entries */
5988         for (i = 0; i < 8; i++)
5989         {
5990                 /* Every other entry */
5991                 what[i] = what[i * 2];
5992
5993                 if (cheat_hear)
5994                 {
5995                         /* Message */
5996                         msg_print(r_name + r_info[what[i]].name);
5997                 }
5998         }
5999
6000         for (i = 0; placing[i][2] >= 0; i++)
6001         {
6002                 y = yval + placing[i][0];
6003                 x = xval + placing[i][1];
6004                 place_monster_aux(0, y, x, what[placing[i][2]], PM_NO_KAGE);
6005         }
6006
6007         return TRUE;
6008 }
6009
6010
6011 /*!
6012  * @brief ¥¿¥¤¥×14¤ÎÉô²°¡ÄÆüì¥È¥é¥Ã¥×Éô²°¤ÎÀ¸À® / Type 14 -- trapped rooms
6013  * @return ¤Ê¤·
6014  * @details
6015  * A special trap is placed at center of the room
6016  */
6017 static bool build_type14(void)
6018 {
6019         int y, x, y2, x2, yval, xval;
6020         int y1, x1, xsize, ysize;
6021
6022         bool light;
6023
6024         cave_type *c_ptr;
6025         s16b trap;
6026
6027         /* Pick a room size */
6028         y1 = randint1(4);
6029         x1 = randint1(11);
6030         y2 = randint1(3);
6031         x2 = randint1(11);
6032
6033         xsize = x1 + x2 + 1;
6034         ysize = y1 + y2 + 1;
6035
6036         /* Find and reserve some space in the dungeon.  Get center of room. */
6037         if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
6038
6039         /* Choose lite or dark */
6040         light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
6041
6042
6043         /* Get corner values */
6044         y1 = yval - ysize / 2;
6045         x1 = xval - xsize / 2;
6046         y2 = yval + (ysize - 1) / 2;
6047         x2 = xval + (xsize - 1) / 2;
6048
6049
6050         /* Place a full floor under the room */
6051         for (y = y1 - 1; y <= y2 + 1; y++)
6052         {
6053                 for (x = x1 - 1; x <= x2 + 1; x++)
6054                 {
6055                         c_ptr = &cave[y][x];
6056                         place_floor_grid(c_ptr);
6057                         c_ptr->info |= (CAVE_ROOM);
6058                         if (light) c_ptr->info |= (CAVE_GLOW);
6059                 }
6060         }
6061
6062         /* Walls around the room */
6063         for (y = y1 - 1; y <= y2 + 1; y++)
6064         {
6065                 c_ptr = &cave[y][x1 - 1];
6066                 place_outer_grid(c_ptr);
6067                 c_ptr = &cave[y][x2 + 1];
6068                 place_outer_grid(c_ptr);
6069         }
6070         for (x = x1 - 1; x <= x2 + 1; x++)
6071         {
6072                 c_ptr = &cave[y1 - 1][x];
6073                 place_outer_grid(c_ptr);
6074                 c_ptr = &cave[y2 + 1][x];
6075                 place_outer_grid(c_ptr);
6076         }
6077
6078         if (dun_level < 30 + randint1(30))
6079                 trap = feat_trap_piranha;
6080         else
6081                 trap = feat_trap_armageddon;
6082
6083         /* Place a special trap */
6084         c_ptr = &cave[rand_spread(yval, ysize/4)][rand_spread(xval, xsize/4)];
6085         c_ptr->mimic = c_ptr->feat;
6086         c_ptr->feat = trap;
6087
6088         /* Message */
6089         if (cheat_room)
6090         {
6091 #ifdef JP
6092                 msg_format("%s¤ÎÉô²°", f_name + f_info[trap].name);
6093 #else
6094                 msg_format("Room of %s", f_name + f_info[trap].name);
6095 #endif
6096         }
6097
6098         return TRUE;
6099 }
6100
6101
6102 /*
6103  * Helper function for "glass room"
6104  */
6105 static bool vault_aux_lite(int r_idx)
6106 {
6107         monster_race *r_ptr = &r_info[r_idx];
6108
6109         /* Validate the monster */
6110         if (!vault_monster_okay(r_idx)) return FALSE;
6111
6112         /* Require lite attack */
6113         if (!(r_ptr->flags4 & RF4_BR_LITE) && !(r_ptr->flags5 & RF5_BA_LITE)) return FALSE;
6114
6115         /* No wall passing monsters */
6116         if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return FALSE;
6117
6118         /* No disintegrating monsters */
6119         if (r_ptr->flags4 & RF4_BR_DISI) return FALSE;
6120
6121         return TRUE;
6122 }
6123
6124 /*
6125  * Helper function for "glass room"
6126  */
6127 static bool vault_aux_shards(int r_idx)
6128 {
6129         monster_race *r_ptr = &r_info[r_idx];
6130
6131         /* Validate the monster */
6132         if (!vault_monster_okay(r_idx)) return FALSE;
6133
6134         /* Require shards breath attack */
6135         if (!(r_ptr->flags4 & RF4_BR_SHAR)) return FALSE;
6136
6137         return TRUE;
6138 }
6139
6140 /*
6141  * Hack -- determine if a template is potion
6142  */
6143 static bool kind_is_potion(int k_idx)
6144 {
6145         return k_info[k_idx].tval == TV_POTION;
6146 }
6147
6148 /*!
6149  * @brief ¥¿¥¤¥×15¤ÎÉô²°¡Ä¥¬¥é¥¹Éô²°¤ÎÀ¸À® / Type 15 -- glass rooms
6150  * @return ¤Ê¤·
6151  */
6152 static bool build_type15(void)
6153 {
6154         int y, x, y2, x2, yval, xval;
6155         int y1, x1, xsize, ysize;
6156         bool light;
6157
6158         cave_type *c_ptr;
6159
6160         /* Pick a room size */
6161         xsize = rand_range(9, 13);
6162         ysize = rand_range(9, 13);
6163
6164         /* Find and reserve some space in the dungeon.  Get center of room. */
6165         if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
6166
6167         /* Choose lite or dark */
6168         light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
6169
6170         /* Get corner values */
6171         y1 = yval - ysize / 2;
6172         x1 = xval - xsize / 2;
6173         y2 = yval + (ysize - 1) / 2;
6174         x2 = xval + (xsize - 1) / 2;
6175
6176         /* Place a full floor under the room */
6177         for (y = y1 - 1; y <= y2 + 1; y++)
6178         {
6179                 for (x = x1 - 1; x <= x2 + 1; x++)
6180                 {
6181                         c_ptr = &cave[y][x];
6182                         place_floor_grid(c_ptr);
6183                         c_ptr->feat = feat_glass_floor;
6184                         c_ptr->info |= (CAVE_ROOM);
6185                         if (light) c_ptr->info |= (CAVE_GLOW);
6186                 }
6187         }
6188
6189         /* Walls around the room */
6190         for (y = y1 - 1; y <= y2 + 1; y++)
6191         {
6192                 c_ptr = &cave[y][x1 - 1];
6193                 place_outer_grid(c_ptr);
6194                 c_ptr->feat = feat_glass_wall;
6195                 c_ptr = &cave[y][x2 + 1];
6196                 place_outer_grid(c_ptr);
6197                 c_ptr->feat = feat_glass_wall;
6198         }
6199         for (x = x1 - 1; x <= x2 + 1; x++)
6200         {
6201                 c_ptr = &cave[y1 - 1][x];
6202                 place_outer_grid(c_ptr);
6203                 c_ptr->feat = feat_glass_wall;
6204                 c_ptr = &cave[y2 + 1][x];
6205                 place_outer_grid(c_ptr);
6206                 c_ptr->feat = feat_glass_wall;
6207         }
6208
6209         switch (randint1(3))
6210         {
6211         case 1: /* 4 lite breathers + potion */
6212                 {
6213                         int dir1, dir2;
6214
6215                         /* Prepare allocation table */
6216                         get_mon_num_prep(vault_aux_lite, NULL);
6217
6218                         /* Place fixed lite berathers */
6219                         for (dir1 = 4; dir1 < 8; dir1++)
6220                         {
6221                                 int r_idx = get_mon_num(dun_level);
6222
6223                                 y = yval + 2 * ddy_ddd[dir1];
6224                                 x = xval + 2 * ddx_ddd[dir1];
6225                                 if (r_idx) place_monster_aux(0, y, x, r_idx, PM_ALLOW_SLEEP);
6226
6227                                 /* Walls around the breather */
6228                                 for (dir2 = 0; dir2 < 8; dir2++)
6229                                 {
6230                                         c_ptr = &cave[y + ddy_ddd[dir2]][x + ddx_ddd[dir2]];
6231                                         place_inner_grid(c_ptr);
6232                                         c_ptr->feat = feat_glass_wall;
6233                                 }
6234                         }
6235
6236                         /* Walls around the potion */
6237                         for (dir1 = 0; dir1 < 4; dir1++)
6238                         {
6239                                 y = yval + 2 * ddy_ddd[dir1];
6240                                 x = xval + 2 * ddx_ddd[dir1];
6241                                 c_ptr = &cave[y][x];
6242                                 place_inner_perm_grid(c_ptr);
6243                                 c_ptr->feat = feat_permanent_glass_wall;
6244                                 cave[yval + ddy_ddd[dir1]][xval + ddx_ddd[dir1]].info |= (CAVE_ICKY);
6245                         }
6246
6247                         /* Glass door */
6248                         dir1 = randint0(4);
6249                         y = yval + 2 * ddy_ddd[dir1];
6250                         x = xval + 2 * ddx_ddd[dir1];
6251                         place_secret_door(y, x, DOOR_GLASS_DOOR);
6252                         c_ptr = &cave[y][x];
6253                         if (is_closed_door(c_ptr->feat)) c_ptr->mimic = feat_glass_wall;
6254
6255                         /* Place a potion */
6256                         get_obj_num_hook = kind_is_potion;
6257                         place_object(yval, xval, AM_NO_FIXED_ART);
6258                         cave[yval][xval].info |= (CAVE_ICKY);
6259                 }
6260                 break;
6261
6262         case 2: /* 1 lite breather + random object */
6263                 {
6264                         int r_idx, dir1;
6265
6266                         /* Pillars */
6267                         c_ptr = &cave[y1 + 1][x1 + 1];
6268                         place_inner_grid(c_ptr);
6269                         c_ptr->feat = feat_glass_wall;
6270
6271                         c_ptr = &cave[y1 + 1][x2 - 1];
6272                         place_inner_grid(c_ptr);
6273                         c_ptr->feat = feat_glass_wall;
6274
6275                         c_ptr = &cave[y2 - 1][x1 + 1];
6276                         place_inner_grid(c_ptr);
6277                         c_ptr->feat = feat_glass_wall;
6278
6279                         c_ptr = &cave[y2 - 1][x2 - 1];
6280                         place_inner_grid(c_ptr);
6281                         c_ptr->feat = feat_glass_wall;
6282
6283                         /* Prepare allocation table */
6284                         get_mon_num_prep(vault_aux_lite, NULL);
6285
6286                         r_idx = get_mon_num(dun_level);
6287                         if (r_idx) place_monster_aux(0, yval, xval, r_idx, 0L);
6288
6289                         /* Walls around the breather */
6290                         for (dir1 = 0; dir1 < 8; dir1++)
6291                         {
6292                                 c_ptr = &cave[yval + ddy_ddd[dir1]][xval + ddx_ddd[dir1]];
6293                                 place_inner_grid(c_ptr);
6294                                 c_ptr->feat = feat_glass_wall;
6295                         }
6296
6297                         /* Curtains around the breather */
6298                         for (y = yval - 1; y <= yval + 1; y++)
6299                         {
6300                                 place_closed_door(y, xval - 2, DOOR_CURTAIN);
6301                                 place_closed_door(y, xval + 2, DOOR_CURTAIN);
6302                         }
6303                         for (x = xval - 1; x <= xval + 1; x++)
6304                         {
6305                                 place_closed_door(yval - 2, x, DOOR_CURTAIN);
6306                                 place_closed_door(yval + 2, x, DOOR_CURTAIN);
6307                         }
6308
6309                         /* Place an object */
6310                         place_object(yval, xval, AM_NO_FIXED_ART);
6311                         cave[yval][xval].info |= (CAVE_ICKY);
6312                 }
6313                 break;
6314
6315         case 3: /* 4 shards breathers + 2 potions */
6316                 {
6317                         int dir1;
6318
6319                         /* Walls around the potion */
6320                         for (y = yval - 2; y <= yval + 2; y++)
6321                         {
6322                                 c_ptr = &cave[y][xval - 3];
6323                                 place_inner_grid(c_ptr);
6324                                 c_ptr->feat = feat_glass_wall;
6325                                 c_ptr = &cave[y][xval + 3];
6326                                 place_inner_grid(c_ptr);
6327                                 c_ptr->feat = feat_glass_wall;
6328                         }
6329                         for (x = xval - 2; x <= xval + 2; x++)
6330                         {
6331                                 c_ptr = &cave[yval - 3][x];
6332                                 place_inner_grid(c_ptr);
6333                                 c_ptr->feat = feat_glass_wall;
6334                                 c_ptr = &cave[yval + 3][x];
6335                                 place_inner_grid(c_ptr);
6336                                 c_ptr->feat = feat_glass_wall;
6337                         }
6338                         for (dir1 = 4; dir1 < 8; dir1++)
6339                         {
6340                                 c_ptr = &cave[yval + 2 * ddy_ddd[dir1]][xval + 2 * ddx_ddd[dir1]];
6341                                 place_inner_grid(c_ptr);
6342                                 c_ptr->feat = feat_glass_wall;
6343                         }
6344
6345                         /* Prepare allocation table */
6346                         get_mon_num_prep(vault_aux_shards, NULL);
6347
6348                         /* Place shard berathers */
6349                         for (dir1 = 4; dir1 < 8; dir1++)
6350                         {
6351                                 int r_idx = get_mon_num(dun_level);
6352
6353                                 y = yval + ddy_ddd[dir1];
6354                                 x = xval + ddx_ddd[dir1];
6355                                 if (r_idx) place_monster_aux(0, y, x, r_idx, 0L);
6356                         }
6357
6358                         /* Place two potions */
6359                         if (one_in_(2))
6360                         {
6361                                 get_obj_num_hook = kind_is_potion;
6362                                 place_object(yval, xval - 1, AM_NO_FIXED_ART);
6363                                 get_obj_num_hook = kind_is_potion;
6364                                 place_object(yval, xval + 1, AM_NO_FIXED_ART);
6365                         }
6366                         else
6367                         {
6368                                 get_obj_num_hook = kind_is_potion;
6369                                 place_object(yval - 1, xval, AM_NO_FIXED_ART);
6370                                 get_obj_num_hook = kind_is_potion;
6371                                 place_object(yval + 1, xval, AM_NO_FIXED_ART);
6372                         }
6373
6374                         for (y = yval - 2; y <= yval + 2; y++)
6375                                 for (x = xval - 2; x <= xval + 2; x++)
6376                                         cave[y][x].info |= (CAVE_ICKY);
6377
6378                 }
6379                 break;
6380         }
6381
6382         /* Message */
6383         if (cheat_room)
6384         {
6385 #ifdef JP
6386                 msg_print("¥¬¥é¥¹¤ÎÉô²°");
6387 #else
6388                 msg_print("Glass room");
6389 #endif
6390         }
6391
6392         return TRUE;
6393 }
6394
6395
6396 /* Create a new floor room with optional light */
6397 void generate_room_floor(int y1, int x1, int y2, int x2, int light)
6398 {
6399         int y, x;
6400         
6401         cave_type *c_ptr;
6402
6403         for (y = y1; y <= y2; y++)
6404         {
6405                 for (x = x1; x <= x2; x++)
6406                 {
6407                         /* Point to grid */
6408                         c_ptr = &cave[y][x];
6409                         place_floor_grid(c_ptr);
6410                         c_ptr->info |= (CAVE_ROOM);
6411                         if (light) c_ptr->info |= (CAVE_GLOW);
6412                 }
6413         }
6414 }
6415
6416 void generate_fill_perm_bold(int y1, int x1, int y2, int x2)
6417 {
6418         int y, x;
6419
6420         for (y = y1; y <= y2; y++)
6421         {
6422                 for (x = x1; x <= x2; x++)
6423                 {
6424                         /* Point to grid */
6425                         place_inner_perm_bold(y, x);
6426                 }
6427         }
6428 }
6429
6430 /* Minimum & maximum town size */
6431 #define MIN_TOWN_WID ((MAX_WID / 3) / 2)
6432 #define MIN_TOWN_HGT ((MAX_HGT / 3) / 2)
6433 #define MAX_TOWN_WID ((MAX_WID / 3) * 2 / 3)
6434 #define MAX_TOWN_HGT ((MAX_HGT / 3) * 2 / 3)
6435
6436 /* Struct for build underground buildings */
6437 typedef struct
6438 {
6439         int y0, x0; /* North-west corner (relative) */
6440         int y1, x1; /* South-east corner (relative) */
6441 }
6442 ugbldg_type;
6443
6444 ugbldg_type *ugbldg;
6445
6446 /*
6447  * Precalculate buildings' location of underground arcade
6448  */
6449 static bool precalc_ugarcade(int town_hgt, int town_wid, int n)
6450 {
6451         int i, y, x, center_y, center_x, tmp, attempt = 10000;
6452         int max_bldg_hgt = 3 * town_hgt / MAX_TOWN_HGT;
6453         int max_bldg_wid = 5 * town_wid / MAX_TOWN_WID;
6454         ugbldg_type *cur_ugbldg;
6455         bool **ugarcade_used, abort;
6456
6457         /* Allocate "ugarcade_used" array (2-dimension) */
6458         C_MAKE(ugarcade_used, town_hgt, bool *);
6459         C_MAKE(*ugarcade_used, town_hgt * town_wid, bool);
6460         for (y = 1; y < town_hgt; y++) ugarcade_used[y] = *ugarcade_used + y * town_wid;
6461
6462         /* Calculate building locations */
6463         for (i = 0; i < n; i++)
6464         {
6465                 cur_ugbldg = &ugbldg[i];
6466                 (void)WIPE(cur_ugbldg, ugbldg_type);
6467
6468                 do
6469                 {
6470                         /* Find the "center" of the store */
6471                         center_y = rand_range(2, town_hgt - 3);
6472                         center_x = rand_range(2, town_wid - 3);
6473
6474                         /* Determine the store boundaries */
6475                         tmp = center_y - randint1(max_bldg_hgt);
6476                         cur_ugbldg->y0 = MAX(tmp, 1);
6477                         tmp = center_x - randint1(max_bldg_wid);
6478                         cur_ugbldg->x0 = MAX(tmp, 1);
6479                         tmp = center_y + randint1(max_bldg_hgt);
6480                         cur_ugbldg->y1 = MIN(tmp, town_hgt - 2);
6481                         tmp = center_x + randint1(max_bldg_wid);
6482                         cur_ugbldg->x1 = MIN(tmp, town_wid - 2);
6483
6484                         /* Scan this building's area */
6485                         for (abort = FALSE, y = cur_ugbldg->y0; (y <= cur_ugbldg->y1) && !abort; y++)
6486                         {
6487                                 for (x = cur_ugbldg->x0; x <= cur_ugbldg->x1; x++)
6488                                 {
6489                                         if (ugarcade_used[y][x])
6490                                         {
6491                                                 abort = TRUE;
6492                                                 break;
6493                                         }
6494                                 }
6495                         }
6496
6497                         attempt--;
6498                 }
6499                 while (abort && attempt); /* Accept this building if no overlapping */
6500
6501                 /* Failed to generate underground arcade */
6502                 if (!attempt) break;
6503
6504                 /*
6505                  * Mark to ugarcade_used[][] as "used"
6506                  * Note: Building-adjacent grids are included for preventing
6507                  * connected bulidings.
6508                  */
6509                 for (y = cur_ugbldg->y0 - 1; y <= cur_ugbldg->y1 + 1; y++)
6510                 {
6511                         for (x = cur_ugbldg->x0 - 1; x <= cur_ugbldg->x1 + 1; x++)
6512                         {
6513                                 ugarcade_used[y][x] = TRUE;
6514                         }
6515                 }
6516         }
6517
6518         /* Free "ugarcade_used" array (2-dimension) */
6519         C_KILL(*ugarcade_used, town_hgt * town_wid, bool);
6520         C_KILL(ugarcade_used, town_hgt, bool *);
6521
6522         /* If i < n, generation is not allowed */
6523         return i == n;
6524 }
6525
6526 /*
6527  * Actually create buildings
6528  * Note: ltcy and ltcx indicate "left top corner".
6529  */
6530 static void build_stores(int ltcy, int ltcx, int stores[], int n)
6531 {
6532         int i, j, y, x;
6533         ugbldg_type *cur_ugbldg;
6534
6535         for (i = 0; i < n; i++)
6536         {
6537                 cur_ugbldg = &ugbldg[i];
6538
6539                 /* Generate new room */
6540                 generate_room_floor(
6541                         ltcy + cur_ugbldg->y0 - 2, ltcx + cur_ugbldg->x0 - 2,
6542                         ltcy + cur_ugbldg->y1 + 2, ltcx + cur_ugbldg->x1 + 2,
6543                         FALSE);
6544         }
6545
6546         for (i = 0; i < n; i++)
6547         {
6548                 cur_ugbldg = &ugbldg[i];
6549
6550                 /* Build an invulnerable rectangular building */
6551                 generate_fill_perm_bold(
6552                         ltcy + cur_ugbldg->y0, ltcx + cur_ugbldg->x0,
6553                         ltcy + cur_ugbldg->y1, ltcx + cur_ugbldg->x1);
6554
6555                 /* Pick a door direction (S,N,E,W) */
6556                 switch (randint0(4))
6557                 {
6558                 /* Bottom side */
6559                 case 0:
6560                         y = cur_ugbldg->y1;
6561                         x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
6562                         break;
6563
6564                 /* Top side */
6565                 case 1:
6566                         y = cur_ugbldg->y0;
6567                         x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
6568                         break;
6569
6570                 /* Right side */
6571                 case 2:
6572                         y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
6573                         x = cur_ugbldg->x1;
6574                         break;
6575
6576                 /* Left side */
6577                 default:
6578                         y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
6579                         x = cur_ugbldg->x0;
6580                         break;
6581                 }
6582
6583                 for (j = 0; j < max_f_idx; j++)
6584                 {
6585                         if (have_flag(f_info[j].flags, FF_STORE))
6586                         {
6587                                 if (f_info[j].subtype == stores[i]) break;
6588                         }
6589                 }
6590
6591                 /* Clear previous contents, add a store door */
6592                 if (j < max_f_idx)
6593                 {
6594                         cave_set_feat(ltcy + y, ltcx + x, j);
6595
6596                         /* Init store */
6597                         store_init(NO_TOWN, stores[i]);
6598                 }
6599         }
6600 }
6601
6602
6603 /*!
6604  * @brief ¥¿¥¤¥×16¤ÎÉô²°¡ÄÃϲ¼ÅÔ»Ô¤ÎÀ¸À® / Type 16 -- Underground Arcade
6605  * @return ¤Ê¤·
6606  * @details
6607  * Town logic flow for generation of new town\n
6608  * Originally from Vanilla 3.0.3\n
6609  *\n
6610  * We start with a fully wiped cave of normal floors.\n
6611  *\n
6612  * Note that town_gen_hack() plays games with the R.N.G.\n
6613  *\n
6614  * This function does NOT do anything about the owners of the stores,\n
6615  * nor the contents thereof.  It only handles the physical layout.\n
6616  */
6617 static bool build_type16(void)
6618 {
6619         int stores[] =
6620         {
6621                 STORE_GENERAL, STORE_ARMOURY, STORE_WEAPON, STORE_TEMPLE,
6622                 STORE_ALCHEMIST, STORE_MAGIC, STORE_BLACK, STORE_BOOK,
6623         };
6624         int n = sizeof stores / sizeof (int);
6625         int i, y, x, y1, x1, yval, xval;
6626         int town_hgt = rand_range(MIN_TOWN_HGT, MAX_TOWN_HGT);
6627         int town_wid = rand_range(MIN_TOWN_WID, MAX_TOWN_WID);
6628         bool prevent_bm = FALSE;
6629
6630         /* Hack -- If already exist black market, prevent building */
6631         for (y = 0; (y < cur_hgt) && !prevent_bm; y++)
6632         {
6633                 for (x = 0; x < cur_wid; x++)
6634                 {
6635                         if (cave[y][x].feat == FF_STORE)
6636                         {
6637                                 prevent_bm = (f_info[cave[y][x].feat].subtype == STORE_BLACK);
6638                                 break;
6639                         }
6640                 }
6641         }
6642         for (i = 0; i < n; i++)
6643         {
6644                 if ((stores[i] == STORE_BLACK) && prevent_bm) stores[i] = stores[--n];
6645         }
6646         if (!n) return FALSE;
6647
6648         /* Allocate buildings array */
6649         C_MAKE(ugbldg, n, ugbldg_type);
6650
6651         /* If cannot build stores, abort */
6652         if (!precalc_ugarcade(town_hgt, town_wid, n))
6653         {
6654                 /* Free buildings array */
6655                 C_KILL(ugbldg, n, ugbldg_type);
6656                 return FALSE;
6657         }
6658
6659         /* Find and reserve some space in the dungeon.  Get center of room. */
6660         if (!find_space(&yval, &xval, town_hgt + 4, town_wid + 4))
6661         {
6662                 /* Free buildings array */
6663                 C_KILL(ugbldg, n, ugbldg_type);
6664                 return FALSE;
6665         }
6666
6667         /* Get top left corner */
6668         y1 = yval - (town_hgt / 2);
6669         x1 = xval - (town_wid / 2);
6670
6671         /* Generate new room */
6672         generate_room_floor(
6673                 y1 + town_hgt / 3, x1 + town_wid / 3,
6674                 y1 + town_hgt * 2 / 3, x1 + town_wid * 2 / 3, FALSE);
6675
6676         /* Build stores */
6677         build_stores(y1, x1, stores, n);
6678
6679 #ifdef JP
6680         if (cheat_room) msg_print("Ãϲ¼³¹");
6681 #else
6682         if (cheat_room) msg_print("Underground Arcade");
6683 #endif
6684
6685         /* Free buildings array */
6686         C_KILL(ugbldg, n, ugbldg_type);
6687
6688         return TRUE;
6689 }
6690
6691
6692 /*
6693  * Attempt to build a room of the given type at the given block
6694  *
6695  * Note that we restrict the number of "crowded" rooms to reduce
6696  * the chance of overflowing the monster list during level creation.
6697  */
6698 static bool room_build(int typ)
6699 {
6700         /* Build a room */
6701         switch (typ)
6702         {
6703         /* Build an appropriate room */
6704         case ROOM_T_NORMAL:        return build_type1();
6705         case ROOM_T_OVERLAP:       return build_type2();
6706         case ROOM_T_CROSS:         return build_type3();
6707         case ROOM_T_INNER_FEAT:    return build_type4();
6708         case ROOM_T_NEST:          return build_type5();
6709         case ROOM_T_PIT:           return build_type6();
6710         case ROOM_T_LESSER_VAULT:  return build_type7();
6711         case ROOM_T_GREATER_VAULT: return build_type8();
6712         case ROOM_T_FRACAVE:       return build_type9();
6713         case ROOM_T_RANDOM_VAULT:  return build_type10();
6714         case ROOM_T_OVAL:          return build_type11();
6715         case ROOM_T_CRYPT:         return build_type12();
6716         case ROOM_T_TRAP_PIT:      return build_type13();
6717         case ROOM_T_TRAP:          return build_type14();
6718         case ROOM_T_GLASS:         return build_type15();
6719         case ROOM_T_ARCADE:        return build_type16();
6720         }
6721
6722         /* Paranoia */
6723         return FALSE;
6724 }
6725
6726
6727 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
6728
6729 /*
6730  * [from SAngband (originally from OAngband)]
6731  * 
6732  * Generate rooms in dungeon.  Build bigger rooms at first.
6733  */
6734 bool generate_rooms(void)
6735 {
6736         int i;
6737         bool remain;
6738         int crowded = 0;
6739         int total_prob;
6740         int prob_list[ROOM_T_MAX];
6741         int rooms_built = 0;
6742         int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
6743         int level_index = MIN(10, div_round(dun_level, 10));
6744
6745         /* Number of each type of room on this level */
6746         s16b room_num[ROOM_T_MAX];
6747
6748         /* Limit number of rooms */
6749         int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
6750
6751         /* Assume normal cave */
6752         room_info_type *room_info_ptr = room_info_normal;
6753
6754         /*
6755          * Initialize probability list.
6756          */
6757         for (i = 0; i < ROOM_T_MAX; i++)
6758         {
6759                 /* No rooms allowed above their minimum depth. */
6760                 if (dun_level < room_info_ptr[i].min_level)
6761                 {
6762                         prob_list[i] = 0;
6763                 }
6764                 else
6765                 {
6766                         prob_list[i] = room_info_ptr[i].prob[level_index];
6767                 }
6768         }
6769
6770         /*
6771          * XXX -- Various dungeon types and options.
6772          */
6773
6774         /* Ironman sees only Greater Vaults */
6775         if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
6776         {
6777                 for (i = 0; i < ROOM_T_MAX; i++)
6778                 {
6779                         if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
6780                         else prob_list[i] = 0;
6781                 }
6782         }
6783
6784         /* Forbidden vaults */
6785         else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
6786         {
6787                 prob_list[ROOM_T_LESSER_VAULT] = 0;
6788                 prob_list[ROOM_T_GREATER_VAULT] = 0;
6789                 prob_list[ROOM_T_RANDOM_VAULT] = 0;
6790         }
6791
6792
6793         /* NO_CAVE dungeon (Castle)*/
6794         if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
6795         {
6796                 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
6797                 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
6798                 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
6799         }
6800
6801         /* CAVE dungeon (Orc cave etc.) */
6802         else if (d_info[dungeon_type].flags1 & DF1_CAVE)
6803         {
6804                 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
6805         }
6806
6807         /* No caves when a (random) cavern exists: they look bad */
6808         else if (dun->cavern || dun->empty_level)
6809         {
6810                 prob_list[ROOM_T_FRACAVE] = 0;
6811         }
6812
6813         /* Forbidden glass rooms */
6814         if (!(d_info[dungeon_type].flags1 & DF1_GLASS_ROOM))
6815         {
6816                 prob_list[ROOM_T_GLASS] = 0;
6817         }
6818
6819         if (!(d_info[dungeon_type].flags1 & DF1_ARCADE))
6820         {
6821                 prob_list[ROOM_T_ARCADE] = 0;
6822         }
6823
6824         /*
6825          * Initialize number of rooms,
6826          * And calcurate total probability.
6827          */
6828         for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
6829         {
6830                 room_num[i] = 0;
6831                 total_prob += prob_list[i];
6832         }
6833
6834         /*
6835          * Prepare the number of rooms, of all types, we should build
6836          * on this level.
6837          */
6838         for (i = dun_rooms; i > 0; i--)
6839         {
6840                 int room_type;
6841                 int rand = randint0(total_prob);
6842
6843                 /* Get room_type randomly */
6844                 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
6845                 {
6846                         if (rand < prob_list[room_type]) break;
6847                         else rand -= prob_list[room_type];
6848                 }
6849
6850                 /* Paranoia */
6851                 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
6852
6853                 /* Increase the number of rooms of that type we should build. */
6854                 room_num[room_type]++;
6855
6856                 switch (room_type)
6857                 {
6858                 case ROOM_T_NEST:
6859                 case ROOM_T_PIT:
6860                 case ROOM_T_LESSER_VAULT:
6861                 case ROOM_T_TRAP_PIT:
6862                 case ROOM_T_GLASS:
6863                 case ROOM_T_ARCADE:
6864
6865                         /* Large room */
6866                         i -= 2;
6867                         break;
6868
6869                 case ROOM_T_GREATER_VAULT:
6870                 case ROOM_T_RANDOM_VAULT:
6871
6872                         /* Largest room */
6873                         i -= 3;
6874                         break;
6875                 }
6876         }
6877
6878         /*
6879          * Build each type of room one by one until we cannot build any more.
6880          * [from SAngband (originally from OAngband)]
6881          */
6882         while (TRUE)
6883         {
6884                 /* Assume no remaining rooms */
6885                 remain = FALSE;
6886
6887                 for (i = 0; i < ROOM_T_MAX; i++)
6888                 {
6889                         /* What type of room are we building now? */
6890                         int room_type = room_build_order[i];
6891
6892                         /* Go next if none available */
6893                         if (!room_num[room_type]) continue;
6894
6895                         /* Use up one unit */
6896                         room_num[room_type]--;
6897
6898                         /* Build the room. */
6899                         if (room_build(room_type))
6900                         {
6901                                 /* Increase the room built count. */
6902                                 rooms_built++;
6903
6904                                 /* Mark as there was some remaining rooms */
6905                                 remain = TRUE;
6906
6907                                 switch (room_type)
6908                                 {
6909                                 case ROOM_T_PIT:
6910                                 case ROOM_T_NEST:
6911                                 case ROOM_T_TRAP_PIT:
6912
6913                                         /* Avoid too many monsters */
6914                                         if (++crowded >= 2)
6915                                         {
6916                                                 room_num[ROOM_T_PIT] = 0;
6917                                                 room_num[ROOM_T_NEST] = 0;
6918                                                 room_num[ROOM_T_TRAP_PIT] = 0;
6919                                         }
6920                                         break;
6921
6922                                 case ROOM_T_ARCADE:
6923
6924                                         /* Avoid double-town */
6925                                         room_num[ROOM_T_ARCADE] = 0;
6926                                         break;
6927                                 }
6928                         }
6929                 }
6930
6931                 /* End loop if no room remain */
6932                 if (!remain) break;
6933         }
6934
6935         if (rooms_built < 2) return FALSE;
6936
6937         if (cheat_room)
6938         {
6939 #ifdef JP
6940                 msg_format("Éô²°¿ô: %d", rooms_built);
6941 #else
6942                 msg_format("Number of Rooms: %d", rooms_built);
6943 #endif
6944         }
6945
6946         return TRUE;
6947 }