OSDN Git Service

v3.0.0 Alpha5 OSDN最終版
[hengband/hengband.git] / src / rooms-vault.c
1 #include "angband.h"
2 #include "generate.h"
3 #include "grid.h"
4 #include "rooms.h"
5 #include "store.h"
6 #include "trap.h"
7 #include "monster.h"
8
9 /*
10 * This function creates a random vault that looks like a collection of bubbles.
11 * It works by getting a set of coordinates that represent the center of each
12 * bubble.  The entire room is made by seeing which bubble center is closest. If
13 * two centers are equidistant then the square is a wall, otherwise it is a floor.
14 * The only exception is for squares really near a center, these are always floor.
15 * (It looks better than without this check.)
16 *
17 * Note: If two centers are on the same point then this algorithm will create a
18 *       blank bubble filled with walls. - This is prevented from happening.
19 */
20 static void build_bubble_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize)
21 {
22 #define BUBBLENUM 10            /* number of bubbles */
23
24         /* array of center points of bubbles */
25         coord center[BUBBLENUM];
26
27         int i, j;
28         POSITION x = 0, y = 0;
29         u16b min1, min2, temp;
30         bool done;
31
32         /* Offset from center to top left hand corner */
33         POSITION xhsize = xsize / 2;
34         POSITION yhsize = ysize / 2;
35
36         msg_print_wizard(CHEAT_DUNGEON, _("泡型ランダムVaultを生成しました。", "Room Vault."));
37
38         /* Allocate center of bubbles */
39         center[0].x = (byte)randint1(xsize - 3) + 1;
40         center[0].y = (byte)randint1(ysize - 3) + 1;
41
42         for (i = 1; i < BUBBLENUM; i++)
43         {
44                 done = FALSE;
45
46                 /* get center and check to see if it is unique */
47                 while (!done)
48                 {
49                         done = TRUE;
50
51                         x = randint1(xsize - 3) + 1;
52                         y = randint1(ysize - 3) + 1;
53
54                         for (j = 0; j < i; j++)
55                         {
56                                 /* rough test to see if there is an overlap */
57                                 if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
58                         }
59                 }
60
61                 center[i].x = x;
62                 center[i].y = y;
63         }
64
65
66         /* Top and bottom boundaries */
67         for (i = 0; i < xsize; i++)
68         {
69                 int side_x = x0 - xhsize + i;
70
71                 place_outer_noperm_bold(y0 - yhsize + 0, side_x);
72                 cave[y0 - yhsize + 0][side_x].info |= (CAVE_ROOM | CAVE_ICKY);
73                 place_outer_noperm_bold(y0 - yhsize + ysize - 1, side_x);
74                 cave[y0 - yhsize + ysize - 1][side_x].info |= (CAVE_ROOM | CAVE_ICKY);
75         }
76
77         /* Left and right boundaries */
78         for (i = 1; i < ysize - 1; i++)
79         {
80                 int side_y = y0 - yhsize + i;
81
82                 place_outer_noperm_bold(side_y, x0 - xhsize + 0);
83                 cave[side_y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
84                 place_outer_noperm_bold(side_y, x0 - xhsize + xsize - 1);
85                 cave[side_y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
86         }
87
88         /* Fill in middle with bubbles */
89         for (x = 1; x < xsize - 1; x++)
90         {
91                 for (y = 1; y < ysize - 1; y++)
92                 {
93                         /* Get distances to two closest centers */
94
95                         min1 = (u16b)distance(x, y, center[0].x, center[0].y);
96                         min2 = (u16b)distance(x, y, center[1].x, center[1].y);
97
98                         if (min1 > min2)
99                         {
100                                 /* swap if in wrong order */
101                                 temp = min1;
102                                 min1 = min2;
103                                 min2 = temp;
104                         }
105
106                         /* Scan the rest */
107                         for (i = 2; i < BUBBLENUM; i++)
108                         {
109                                 temp = (u16b)distance(x, y, center[i].x, center[i].y);
110
111                                 if (temp < min1)
112                                 {
113                                         /* smallest */
114                                         min2 = min1;
115                                         min1 = temp;
116                                 }
117                                 else if (temp < min2)
118                                 {
119                                         /* second smallest */
120                                         min2 = temp;
121                                 }
122                         }
123                         if (((min2 - min1) <= 2) && (!(min1 < 3)))
124                         {
125                                 /* Boundary at midpoint+ not at inner region of bubble */
126                                 place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
127                         }
128                         else
129                         {
130                                 /* middle of a bubble */
131                                 place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
132                         }
133
134                         /* clean up rest of flags */
135                         cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
136                 }
137         }
138
139         /* Try to add some random doors */
140         for (i = 0; i < 500; i++)
141         {
142                 x = randint1(xsize - 3) - xhsize + x0 + 1;
143                 y = randint1(ysize - 3) - yhsize + y0 + 1;
144                 add_door(x, y);
145         }
146
147         /* Fill with monsters and treasure, low difficulty */
148         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
149 }
150
151 /* Create a random vault that looks like a collection of overlapping rooms */
152 static void build_room_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize)
153 {
154         POSITION x1, x2, y1, y2, xhsize, yhsize;
155         int i;
156
157         /* get offset from center */
158         xhsize = xsize / 2;
159         yhsize = ysize / 2;
160
161         msg_print_wizard(CHEAT_DUNGEON, _("部屋型ランダムVaultを生成しました。", "Room Vault."));
162
163         /* fill area so don't get problems with arena levels */
164         for (x1 = 0; x1 < xsize; x1++)
165         {
166                 POSITION x = x0 - xhsize + x1;
167
168                 for (y1 = 0; y1 < ysize; y1++)
169                 {
170                         POSITION y = y0 - yhsize + y1;
171
172                         place_extra_bold(y, x);
173                         cave[y][x].info &= (~CAVE_ICKY);
174                 }
175         }
176
177         /* add ten random rooms */
178         for (i = 0; i < 10; i++)
179         {
180                 x1 = randint1(xhsize) * 2 + x0 - xhsize;
181                 x2 = randint1(xhsize) * 2 + x0 - xhsize;
182                 y1 = randint1(yhsize) * 2 + y0 - yhsize;
183                 y2 = randint1(yhsize) * 2 + y0 - yhsize;
184                 build_room(x1, x2, y1, y2);
185         }
186
187         /* Add some random doors */
188         for (i = 0; i < 500; i++)
189         {
190                 x1 = randint1(xsize - 3) - xhsize + x0 + 1;
191                 y1 = randint1(ysize - 3) - yhsize + y0 + 1;
192                 add_door(x1, y1);
193         }
194
195         /* Fill with monsters and treasure, high difficulty */
196         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
197 }
198
199
200 /* Create a random vault out of a fractal cave */
201 static void build_cave_vault(POSITION x0, POSITION y0, POSITION xsiz, POSITION ysiz)
202 {
203         int grd, roug, cutoff;
204         bool done, light, room;
205         POSITION xhsize, yhsize, xsize, ysize, x, y;
206
207         /* round to make sizes even */
208         xhsize = xsiz / 2;
209         yhsize = ysiz / 2;
210         xsize = xhsize * 2;
211         ysize = yhsize * 2;
212
213         msg_print_wizard(CHEAT_DUNGEON, _("洞穴ランダムVaultを生成しました。", "Cave Vault."));
214
215         light = done = FALSE;
216         room = TRUE;
217
218         while (!done)
219         {
220                 /* testing values for these parameters feel free to adjust */
221                 grd = 1 << randint0(4);
222
223                 /* want average of about 16 */
224                 roug = randint1(8) * randint1(4);
225
226                 /* about size/2 */
227                 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
228                         randint1(xsize / 4) + randint1(ysize / 4);
229
230                 /* make it */
231                 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
232
233                 /* Convert to normal format+ clean up */
234                 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
235         }
236
237         /* Set icky flag because is a vault */
238         for (x = 0; x <= xsize; x++)
239         {
240                 for (y = 0; y <= ysize; y++)
241                 {
242                         cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
243                 }
244         }
245
246         /* Fill with monsters and treasure, low difficulty */
247         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
248 }
249
250
251
252 /*!
253 * @brief Vault地形を回転、上下左右反転するための座標変換を返す / coordinate translation code
254 * @param x 変換したい点のX座標参照ポインタ
255 * @param y 変換したい点のY座標参照ポインタ
256 * @param xoffset Vault生成時の基準X座標
257 * @param yoffset Vault生成時の基準Y座標
258 * @param transno 処理ID
259 * @return なし
260 */
261 static void coord_trans(POSITION *x, POSITION *y, POSITION xoffset, POSITION yoffset, int transno)
262 {
263         int i;
264         int temp;
265
266         /*
267         * transno specifies what transformation is required. (0-7)
268         * The lower two bits indicate by how much the vault is rotated,
269         * and the upper bit indicates a reflection.
270         * This is done by using rotation matrices... however since
271         * these are mostly zeros for rotations by 90 degrees this can
272         * be expressed simply in terms of swapping and inverting the
273         * x and y coordinates.
274         */
275         for (i = 0; i < transno % 4; i++)
276         {
277                 /* rotate by 90 degrees */
278                 temp = *x;
279                 *x = -(*y);
280                 *y = temp;
281         }
282
283         if (transno / 4)
284         {
285                 /* Reflect depending on status of 3rd bit. */
286                 *x = -(*x);
287         }
288
289         /* Add offsets so vault stays in the first quadrant */
290         *x += xoffset;
291         *y += yoffset;
292 }
293
294
295 /*!
296 * @brief Vaultをフロアに配置する / Hack -- fill in "vault" rooms
297 * @param yval 生成基準Y座標
298 * @param xval 生成基準X座標
299 * @param ymax VaultのYサイズ
300 * @param xmax VaultのXサイズ
301 * @param data Vaultのデータ文字列
302 * @param xoffset 変換基準X座標
303 * @param yoffset 変換基準Y座標
304 * @param transno 変換ID
305 * @return なし
306 */
307 static void build_vault(POSITION yval, POSITION xval, POSITION ymax, POSITION xmax, concptr data,
308         POSITION xoffset, POSITION yoffset, int transno)
309 {
310         POSITION dx, dy, x, y, i, j;
311         concptr t;
312         cave_type *c_ptr;
313
314         /* Place dungeon features and objects */
315         for (t = data, dy = 0; dy < ymax; dy++)
316         {
317                 for (dx = 0; dx < xmax; dx++, t++)
318                 {
319                         /* prevent loop counter from being overwritten */
320                         i = dx;
321                         j = dy;
322
323                         /* Flip / rotate */
324                         coord_trans(&i, &j, xoffset, yoffset, transno);
325
326                         /* Extract the location */
327                         if (transno % 2 == 0)
328                         {
329                                 /* no swap of x/y */
330                                 x = xval - (xmax / 2) + i;
331                                 y = yval - (ymax / 2) + j;
332                         }
333                         else
334                         {
335                                 /* swap of x/y */
336                                 x = xval - (ymax / 2) + i;
337                                 y = yval - (xmax / 2) + j;
338                         }
339
340                         /* Hack -- skip "non-grids" */
341                         if (*t == ' ') continue;
342                         c_ptr = &cave[y][x];
343
344                         /* Lay down a floor */
345                         place_floor_grid(c_ptr);
346
347                         /* Remove any mimic */
348                         c_ptr->mimic = 0;
349
350                         /* Part of a vault */
351                         c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
352
353                         /* Analyze the grid */
354                         switch (*t)
355                         {
356                                 /* Granite wall (outer) */
357                         case '%':
358                                 place_outer_noperm_grid(c_ptr);
359                                 break;
360
361                                 /* Granite wall (inner) */
362                         case '#':
363                                 place_inner_grid(c_ptr);
364                                 break;
365
366                                 /* Glass wall (inner) */
367                         case '$':
368                                 place_inner_grid(c_ptr);
369                                 c_ptr->feat = feat_glass_wall;
370                                 break;
371
372                                 /* Permanent wall (inner) */
373                         case 'X':
374                                 place_inner_perm_grid(c_ptr);
375                                 break;
376
377                                 /* Permanent glass wall (inner) */
378                         case 'Y':
379                                 place_inner_perm_grid(c_ptr);
380                                 c_ptr->feat = feat_permanent_glass_wall;
381                                 break;
382
383                                 /* Treasure/trap */
384                         case '*':
385                                 if (randint0(100) < 75)
386                                 {
387                                         place_object(y, x, 0L);
388                                 }
389                                 else
390                                 {
391                                         place_trap(y, x);
392                                 }
393                                 break;
394
395                                 /* Treasure */
396                         case '[':
397                                 place_object(y, x, 0L);
398                                 break;
399
400                                 /* Tree */
401                         case ':':
402                                 c_ptr->feat = feat_tree;
403                                 break;
404
405                                 /* Secret doors */
406                         case '+':
407                                 place_secret_door(y, x, DOOR_DEFAULT);
408                                 break;
409
410                                 /* Secret glass doors */
411                         case '-':
412                                 place_secret_door(y, x, DOOR_GLASS_DOOR);
413                                 if (is_closed_door(c_ptr->feat)) c_ptr->mimic = feat_glass_wall;
414                                 break;
415
416                                 /* Curtains */
417                         case '\'':
418                                 place_secret_door(y, x, DOOR_CURTAIN);
419                                 break;
420
421                                 /* Trap */
422                         case '^':
423                                 place_trap(y, x);
424                                 break;
425
426                                 /* Black market in a dungeon */
427                         case 'S':
428                                 set_cave_feat(y, x, feat_black_market);
429                                 store_init(NO_TOWN, STORE_BLACK);
430                                 break;
431
432                                 /* The Pattern */
433                         case 'p':
434                                 set_cave_feat(y, x, feat_pattern_start);
435                                 break;
436
437                         case 'a':
438                                 set_cave_feat(y, x, feat_pattern_1);
439                                 break;
440
441                         case 'b':
442                                 set_cave_feat(y, x, feat_pattern_2);
443                                 break;
444
445                         case 'c':
446                                 set_cave_feat(y, x, feat_pattern_3);
447                                 break;
448
449                         case 'd':
450                                 set_cave_feat(y, x, feat_pattern_4);
451                                 break;
452
453                         case 'P':
454                                 set_cave_feat(y, x, feat_pattern_end);
455                                 break;
456
457                         case 'B':
458                                 set_cave_feat(y, x, feat_pattern_exit);
459                                 break;
460
461                         case 'A':
462                                 /* Reward for Pattern walk */
463                                 object_level = base_level + 12;
464                                 place_object(y, x, AM_GOOD | AM_GREAT);
465                                 object_level = base_level;
466                                 break;
467
468                         case '~':
469                                 set_cave_feat(y, x, feat_shallow_water);
470                                 break;
471
472                         case '=':
473                                 set_cave_feat(y, x, feat_deep_water);
474                                 break;
475
476                         case 'v':
477                                 set_cave_feat(y, x, feat_shallow_lava);
478                                 break;
479
480                         case 'w':
481                                 set_cave_feat(y, x, feat_deep_lava);
482                                 break;
483
484                         case 'f':
485                                 set_cave_feat(y, x, feat_shallow_acid_puddle);
486                                 break;
487
488                         case 'F':
489                                 set_cave_feat(y, x, feat_deep_acid_puddle);
490                                 break;
491
492                         case 'g':
493                                 set_cave_feat(y, x, feat_shallow_poisonous_puddle);
494                                 break;
495
496                         case 'G':
497                                 set_cave_feat(y, x, feat_deep_poisonous_puddle);
498                                 break;
499
500                         case 'h':
501                                 set_cave_feat(y, x, feat_cold_zone);
502                                 break;
503
504                         case 'H':
505                                 set_cave_feat(y, x, feat_heavy_cold_zone);
506                                 break;
507
508                         case 'i':
509                                 set_cave_feat(y, x, feat_electrical_zone);
510                                 break;
511
512                         case 'I':
513                                 set_cave_feat(y, x, feat_heavy_electrical_zone);
514                                 break;
515
516                         }
517                 }
518         }
519
520
521         /* Place dungeon monsters and objects */
522         for (t = data, dy = 0; dy < ymax; dy++)
523         {
524                 for (dx = 0; dx < xmax; dx++, t++)
525                 {
526                         /* prevent loop counter from being overwritten */
527                         i = dx;
528                         j = dy;
529
530                         /* Flip / rotate */
531                         coord_trans(&i, &j, xoffset, yoffset, transno);
532
533                         /* Extract the location */
534                         if (transno % 2 == 0)
535                         {
536                                 /* no swap of x/y */
537                                 x = xval - (xmax / 2) + i;
538                                 y = yval - (ymax / 2) + j;
539                         }
540                         else
541                         {
542                                 /* swap of x/y */
543                                 x = xval - (ymax / 2) + i;
544                                 y = yval - (xmax / 2) + j;
545                         }
546
547                         /* Hack -- skip "non-grids" */
548                         if (*t == ' ') continue;
549
550                         /* Analyze the symbol */
551                         switch (*t)
552                         {
553                                 /* Monster */
554                         case '&':
555                         {
556                                 monster_level = base_level + 5;
557                                 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
558                                 monster_level = base_level;
559                                 break;
560                         }
561
562                         /* Meaner monster */
563                         case '@':
564                         {
565                                 monster_level = base_level + 11;
566                                 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
567                                 monster_level = base_level;
568                                 break;
569                         }
570
571                         /* Meaner monster, plus treasure */
572                         case '9':
573                         {
574                                 monster_level = base_level + 9;
575                                 place_monster(y, x, PM_ALLOW_SLEEP);
576                                 monster_level = base_level;
577                                 object_level = base_level + 7;
578                                 place_object(y, x, AM_GOOD);
579                                 object_level = base_level;
580                                 break;
581                         }
582
583                         /* Nasty monster and treasure */
584                         case '8':
585                         {
586                                 monster_level = base_level + 40;
587                                 place_monster(y, x, PM_ALLOW_SLEEP);
588                                 monster_level = base_level;
589                                 object_level = base_level + 20;
590                                 place_object(y, x, AM_GOOD | AM_GREAT);
591                                 object_level = base_level;
592                                 break;
593                         }
594
595                         /* Monster and/or object */
596                         case ',':
597                         {
598                                 if (randint0(100) < 50)
599                                 {
600                                         monster_level = base_level + 3;
601                                         place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
602                                         monster_level = base_level;
603                                 }
604                                 if (randint0(100) < 50)
605                                 {
606                                         object_level = base_level + 7;
607                                         place_object(y, x, 0L);
608                                         object_level = base_level;
609                                 }
610                                 break;
611                         }
612
613                         }
614                 }
615         }
616 }
617
618
619
620 /*!
621 * @brief タイプ7の部屋…v_info.txtより小型vaultを生成する / Type 7 -- simple vaults (see "v_info.txt")
622 * @return なし
623 */
624 bool build_type7(void)
625 {
626         vault_type *v_ptr = NULL;
627         int dummy;
628         POSITION x, y;
629         POSITION xval, yval;
630         POSITION xoffset, yoffset;
631         int transno;
632
633         /* Pick a lesser vault */
634         for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
635         {
636                 /* Access a random vault record */
637                 v_ptr = &v_info[randint0(max_v_idx)];
638
639                 /* Accept the first lesser vault */
640                 if (v_ptr->typ == 7) break;
641         }
642
643         /* No lesser vault found */
644         if (dummy >= SAFE_MAX_ATTEMPTS)
645         {
646                 msg_print_wizard(CHEAT_DUNGEON, _("小型固定Vaultを配置できませんでした。", "Could not place lesser vault."));
647                 return FALSE;
648         }
649
650         /* pick type of transformation (0-7) */
651         transno = randint0(8);
652
653         /* calculate offsets */
654         x = v_ptr->wid;
655         y = v_ptr->hgt;
656
657         /* Some huge vault cannot be ratated to fit in the dungeon */
658         if (x + 2 > cur_hgt - 2)
659         {
660                 /* Forbid 90 or 270 degree ratation */
661                 transno &= ~1;
662         }
663
664         coord_trans(&x, &y, 0, 0, transno);
665
666         if (x < 0)
667         {
668                 xoffset = -x - 1;
669         }
670         else
671         {
672                 xoffset = 0;
673         }
674
675         if (y < 0)
676         {
677                 yoffset = -y - 1;
678         }
679         else
680         {
681                 yoffset = 0;
682         }
683
684         /* Find and reserve some space in the dungeon.  Get center of room. */
685         if (!find_space(&yval, &xval, abs(y), abs(x))) return FALSE;
686
687 #ifdef FORCE_V_IDX
688         v_ptr = &v_info[2];
689 #endif
690
691         msg_format_wizard(CHEAT_DUNGEON, _("小型Vault(%s)を生成しました。", "Lesser vault (%s)."), v_name + v_ptr->name);
692
693         /* Hack -- Build the vault */
694         build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
695                 v_text + v_ptr->text, xoffset, yoffset, transno);
696
697         return TRUE;
698 }
699
700 /*!
701 * @brief タイプ8の部屋…v_info.txtより大型vaultを生成する / Type 8 -- greater vaults (see "v_info.txt")
702 * @return なし
703 */
704 bool build_type8(void)
705 {
706         vault_type *v_ptr;
707         int dummy;
708         POSITION xval, yval;
709         POSITION x, y;
710         int transno;
711         POSITION xoffset, yoffset;
712
713         /* Pick a greater vault */
714         for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
715         {
716                 /* Access a random vault record */
717                 v_ptr = &v_info[randint0(max_v_idx)];
718
719                 /* Accept the first greater vault */
720                 if (v_ptr->typ == 8) break;
721         }
722
723         /* No greater vault found */
724         if (dummy >= SAFE_MAX_ATTEMPTS)
725         {
726                 msg_print_wizard(CHEAT_DUNGEON, _("大型固定Vaultを配置できませんでした。", "Could not place greater vault."));
727                 return FALSE;
728         }
729
730         /* pick type of transformation (0-7) */
731         transno = randint0(8);
732
733         /* calculate offsets */
734         x = v_ptr->wid;
735         y = v_ptr->hgt;
736
737         /* Some huge vault cannot be ratated to fit in the dungeon */
738         if (x + 2 > cur_hgt - 2)
739         {
740                 /* Forbid 90 or 270 degree ratation */
741                 transno &= ~1;
742         }
743
744         coord_trans(&x, &y, 0, 0, transno);
745
746         if (x < 0)
747         {
748                 xoffset = -x - 1;
749         }
750         else
751         {
752                 xoffset = 0;
753         }
754
755         if (y < 0)
756         {
757                 yoffset = -y - 1;
758         }
759         else
760         {
761                 yoffset = 0;
762         }
763
764         /*
765         * Try to allocate space for room.  If fails, exit
766         *
767         * Hack -- Prepare a bit larger space (+2, +2) to
768         * prevent generation of vaults with no-entrance.
769         */
770         /* Find and reserve some space in the dungeon.  Get center of room. */
771         if (!find_space(&yval, &xval, (POSITION)(abs(y) + 2), (POSITION)(abs(x) + 2))) return FALSE;
772
773 #ifdef FORCE_V_IDX
774         v_ptr = &v_info[76 + randint1(3)];
775 #endif
776
777         msg_format_wizard(CHEAT_DUNGEON, _("大型固定Vault(%s)を生成しました。", "Greater vault (%s)."), v_name + v_ptr->name);
778
779         /* Hack -- Build the vault */
780         build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
781                 v_text + v_ptr->text, xoffset, yoffset, transno);
782
783         return TRUE;
784 }
785
786
787 /*
788 * Build target vault.
789 * This is made by two concentric "crypts" with perpendicular
790 * walls creating the cross-hairs.
791 */
792 static void build_target_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize)
793 {
794         POSITION rad, x, y;
795
796         /* Make a random metric */
797         POSITION h1, h2, h3, h4;
798         h1 = randint1(32) - 16;
799         h2 = randint1(16);
800         h3 = randint1(32);
801         h4 = randint1(32) - 16;
802
803         msg_print_wizard(CHEAT_DUNGEON, _("対称形ランダムVaultを生成しました。", "Elemental Vault"));
804
805         /* work out outer radius */
806         if (xsize > ysize)
807         {
808                 rad = ysize / 2;
809         }
810         else
811         {
812                 rad = xsize / 2;
813         }
814
815         /* Make floor */
816         for (x = x0 - rad; x <= x0 + rad; x++)
817         {
818                 for (y = y0 - rad; y <= y0 + rad; y++)
819                 {
820                         /* clear room flag */
821                         cave[y][x].info &= ~(CAVE_ROOM);
822
823                         /* Vault - so is "icky" */
824                         cave[y][x].info |= CAVE_ICKY;
825
826                         if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
827                         {
828                                 /* inside- so is floor */
829                                 place_floor_bold(y, x);
830                         }
831                         else
832                         {
833                                 /* make granite outside so arena works */
834                                 place_extra_bold(y, x);
835                         }
836
837                         /* proper boundary for arena */
838                         if (((y + rad) == y0) || ((y - rad) == y0) ||
839                                 ((x + rad) == x0) || ((x - rad) == x0))
840                         {
841                                 place_extra_bold(y, x);
842                         }
843                 }
844         }
845
846         /* Find visible outer walls and set to be FEAT_OUTER */
847         add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
848                 x0 + rad + 1, y0 + rad + 1);
849
850         /* Add inner wall */
851         for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
852         {
853                 for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
854                 {
855                         if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
856                         {
857                                 /* Make an internal wall */
858                                 place_inner_bold(y, x);
859                         }
860                 }
861         }
862
863         /* Add perpendicular walls */
864         for (x = x0 - rad; x <= x0 + rad; x++)
865         {
866                 place_inner_bold(y0, x);
867         }
868
869         for (y = y0 - rad; y <= y0 + rad; y++)
870         {
871                 place_inner_bold(y, x0);
872         }
873
874         /* Make inner vault */
875         for (y = y0 - 1; y <= y0 + 1; y++)
876         {
877                 place_inner_bold(y, x0 - 1);
878                 place_inner_bold(y, x0 + 1);
879         }
880         for (x = x0 - 1; x <= x0 + 1; x++)
881         {
882                 place_inner_bold(y0 - 1, x);
883                 place_inner_bold(y0 + 1, x);
884         }
885
886         place_floor_bold(y0, x0);
887
888
889         /* Add doors to vault */
890         /* get two distances so can place doors relative to centre */
891         x = (rad - 2) / 4 + 1;
892         y = rad / 2 + x;
893
894         add_door(x0 + x, y0);
895         add_door(x0 + y, y0);
896         add_door(x0 - x, y0);
897         add_door(x0 - y, y0);
898         add_door(x0, y0 + x);
899         add_door(x0, y0 + y);
900         add_door(x0, y0 - x);
901         add_door(x0, y0 - y);
902
903         /* Fill with stuff - medium difficulty */
904         fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
905 }
906
907
908 #ifdef ALLOW_CAVERNS_AND_LAKES
909 /*
910 * This routine uses a modified version of the lake code to make a
911 * distribution of some terrain type over the vault.  This type
912 * depends on the dungeon depth.
913 *
914 * Miniture rooms are then scattered across the vault.
915 */
916 static void build_elemental_vault(POSITION x0, POSITION y0, POSITION xsiz, POSITION ysiz)
917 {
918         int grd, roug;
919         int c1, c2, c3;
920         bool done = FALSE;
921         POSITION xsize, ysize, xhsize, yhsize, x, y;
922         int i;
923         int type;
924
925         msg_print_wizard(CHEAT_DUNGEON, _("精霊界ランダムVaultを生成しました。", "Elemental Vault"));
926
927         /* round to make sizes even */
928         xhsize = xsiz / 2;
929         yhsize = ysiz / 2;
930         xsize = xhsize * 2;
931         ysize = yhsize * 2;
932
933         if (dun_level < 25)
934         {
935                 /* Earth vault  (Rubble) */
936                 type = LAKE_T_EARTH_VAULT;
937         }
938         else if (dun_level < 50)
939         {
940                 /* Air vault (Trees) */
941                 type = LAKE_T_AIR_VAULT;
942         }
943         else if (dun_level < 75)
944         {
945                 /* Water vault (shallow water) */
946                 type = LAKE_T_WATER_VAULT;
947         }
948         else
949         {
950                 /* Fire vault (shallow lava) */
951                 type = LAKE_T_FIRE_VAULT;
952         }
953
954         while (!done)
955         {
956                 /* testing values for these parameters: feel free to adjust */
957                 grd = 1 << (randint0(3));
958
959                 /* want average of about 16 */
960                 roug = randint1(8) * randint1(4);
961
962                 /* Make up size of various componants */
963                 /* Floor */
964                 c3 = 2 * xsize / 3;
965
966                 /* Deep water/lava */
967                 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
968
969                 /* Shallow boundary */
970                 c2 = (c1 + c3) / 2;
971
972                 /* make it */
973                 generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
974
975                 /* Convert to normal format+ clean up */
976                 done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
977         }
978
979         /* Set icky flag because is a vault */
980         for (x = 0; x <= xsize; x++)
981         {
982                 for (y = 0; y <= ysize; y++)
983                 {
984                         cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
985                 }
986         }
987
988         /* make a few rooms in the vault */
989         for (i = 1; i <= (xsize * ysize) / 50; i++)
990         {
991                 build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
992                         y0 + randint0(ysize - 4) - ysize / 2 + 2);
993         }
994
995         /* Fill with monsters and treasure, low difficulty */
996         fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
997                 y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
998 }
999 #endif /* ALLOW_CAVERNS_AND_LAKES */
1000
1001
1002 /* Build a "mini" checkerboard vault
1003 *
1004 * This is done by making a permanent wall maze and setting
1005 * the diagonal sqaures of the checker board to be granite.
1006 * The vault has two entrances on opposite sides to guarantee
1007 * a way to get in even if the vault abuts a side of the dungeon.
1008 */
1009 static void build_mini_c_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize)
1010 {
1011         POSITION dy, dx;
1012         POSITION y1, x1, y2, x2, y, x, total;
1013         int m, n, num_vertices;
1014         int *visited;
1015
1016         msg_print_wizard(CHEAT_DUNGEON, _("小型チェッカーランダムVaultを生成しました。", "Mini Checker Board Vault."));
1017
1018         /* Pick a random room size */
1019         dy = ysize / 2 - 1;
1020         dx = xsize / 2 - 1;
1021
1022         y1 = y0 - dy;
1023         x1 = x0 - dx;
1024         y2 = y0 + dy;
1025         x2 = x0 + dx;
1026
1027
1028         /* generate the room */
1029         for (x = x1 - 2; x <= x2 + 2; x++)
1030         {
1031                 if (!in_bounds(y1 - 2, x)) break;
1032
1033                 cave[y1 - 2][x].info |= (CAVE_ROOM | CAVE_ICKY);
1034
1035                 place_outer_noperm_bold(y1 - 2, x);
1036         }
1037
1038         for (x = x1 - 2; x <= x2 + 2; x++)
1039         {
1040                 if (!in_bounds(y2 + 2, x)) break;
1041
1042                 cave[y2 + 2][x].info |= (CAVE_ROOM | CAVE_ICKY);
1043
1044                 place_outer_noperm_bold(y2 + 2, x);
1045         }
1046
1047         for (y = y1 - 2; y <= y2 + 2; y++)
1048         {
1049                 if (!in_bounds(y, x1 - 2)) break;
1050
1051                 cave[y][x1 - 2].info |= (CAVE_ROOM | CAVE_ICKY);
1052
1053                 place_outer_noperm_bold(y, x1 - 2);
1054         }
1055
1056         for (y = y1 - 2; y <= y2 + 2; y++)
1057         {
1058                 if (!in_bounds(y, x2 + 2)) break;
1059
1060                 cave[y][x2 + 2].info |= (CAVE_ROOM | CAVE_ICKY);
1061
1062                 place_outer_noperm_bold(y, x2 + 2);
1063         }
1064
1065         for (y = y1 - 1; y <= y2 + 1; y++)
1066         {
1067                 for (x = x1 - 1; x <= x2 + 1; x++)
1068                 {
1069                         cave_type *c_ptr = &cave[y][x];
1070
1071                         c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
1072
1073                         /* Permanent walls */
1074                         place_inner_perm_grid(c_ptr);
1075                 }
1076         }
1077
1078
1079         /* dimensions of vertex array */
1080         m = dx + 1;
1081         n = dy + 1;
1082         num_vertices = m * n;
1083
1084         /* initialize array of visited vertices */
1085         C_MAKE(visited, num_vertices, int);
1086
1087         /* traverse the graph to create a spannng tree, pick a random root */
1088         r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
1089
1090         /* Make it look like a checker board vault */
1091         for (x = x1; x <= x2; x++)
1092         {
1093                 for (y = y1; y <= y2; y++)
1094                 {
1095                         total = x - x1 + y - y1;
1096                         /* If total is odd- and is a floor then make a wall */
1097                         if ((total % 2 == 1) && is_floor_bold(y, x))
1098                         {
1099                                 place_inner_bold(y, x);
1100                         }
1101                 }
1102         }
1103
1104         /* Make a couple of entrances */
1105         if (one_in_(2))
1106         {
1107                 /* left and right */
1108                 y = randint1(dy) + dy / 2;
1109                 place_inner_bold(y1 + y, x1 - 1);
1110                 place_inner_bold(y1 + y, x2 + 1);
1111         }
1112         else
1113         {
1114                 /* top and bottom */
1115                 x = randint1(dx) + dx / 2;
1116                 place_inner_bold(y1 - 1, x1 + x);
1117                 place_inner_bold(y2 + 1, x1 + x);
1118         }
1119
1120         /* Fill with monsters and treasure, highest difficulty */
1121         fill_treasure(x1, x2, y1, y2, 10);
1122
1123         C_KILL(visited, num_vertices, int);
1124 }
1125
1126 /* Build a castle */
1127 /* Driver routine: clear the region and call the recursive
1128 * room routine.
1129 *
1130 *This makes a vault that looks like a castle/ city in the dungeon.
1131 */
1132 static void build_castle_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize)
1133 {
1134         POSITION dy, dx;
1135         POSITION y1, x1, y2, x2;
1136         POSITION y, x;
1137
1138         /* Pick a random room size */
1139         dy = ysize / 2 - 1;
1140         dx = xsize / 2 - 1;
1141
1142         y1 = y0 - dy;
1143         x1 = x0 - dx;
1144         y2 = y0 + dy;
1145         x2 = x0 + dx;
1146
1147         msg_print_wizard(CHEAT_DUNGEON, _("城型ランダムVaultを生成しました。", "Castle Vault"));
1148
1149         /* generate the room */
1150         for (y = y1 - 1; y <= y2 + 1; y++)
1151         {
1152                 for (x = x1 - 1; x <= x2 + 1; x++)
1153                 {
1154                         cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
1155                         /* Make everything a floor */
1156                         place_floor_bold(y, x);
1157                 }
1158         }
1159
1160         /* Make the castle */
1161         build_recursive_room(x1, y1, x2, y2, randint1(5));
1162
1163         /* Fill with monsters and treasure, low difficulty */
1164         fill_treasure(x1, x2, y1, y2, randint1(3));
1165 }
1166
1167
1168
1169 /*!
1170 * @brief タイプ10の部屋…ランダム生成vault / Type 10 -- Random vaults
1171 * @return なし
1172 */
1173 bool build_type10(void)
1174 {
1175         POSITION y0, x0, xsize, ysize, vtype;
1176
1177         /* big enough to look good, small enough to be fairly common. */
1178         xsize = randint1(22) + 22;
1179         ysize = randint1(11) + 11;
1180
1181         /* Find and reserve some space in the dungeon.  Get center of room. */
1182         if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
1183
1184         /* Select type of vault */
1185 #ifdef ALLOW_CAVERNS_AND_LAKES
1186         do
1187         {
1188                 vtype = randint1(15);
1189         } while ((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) &&
1190                 ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11)));
1191 #else /* ALLOW_CAVERNS_AND_LAKES */
1192         do
1193         {
1194                 vtype = randint1(7);
1195         } while ((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) &&
1196                 ((vtype == 1) || (vtype == 3)));
1197 #endif /* ALLOW_CAVERNS_AND_LAKES */
1198
1199         switch (vtype)
1200         {
1201                 /* Build an appropriate room */
1202         case 1: case  9: build_bubble_vault(x0, y0, xsize, ysize); break;
1203         case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
1204         case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
1205         case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
1206         case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
1207         case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
1208         case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
1209 #ifdef ALLOW_CAVERNS_AND_LAKES
1210         case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
1211 #endif /* ALLOW_CAVERNS_AND_LAKES */
1212                 /* I know how to add a few more... give me some time. */
1213
1214                 /* Paranoia */
1215         default: return FALSE;
1216         }
1217
1218         return TRUE;
1219 }
1220
1221
1222 /*!
1223 * @brief タイプ17の部屋…v_info.txtより固定特殊部屋を生成する / Type 17 -- fixed special room (see "v_info.txt")
1224 * @return なし
1225 */
1226 bool build_type17(void)
1227 {
1228         vault_type *v_ptr = NULL;
1229         int dummy;
1230         POSITION x, y;
1231         POSITION xval, yval;
1232         POSITION xoffset, yoffset;
1233         int transno;
1234
1235         /* Pick a lesser vault */
1236         for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
1237         {
1238                 /* Access a random vault record */
1239                 v_ptr = &v_info[randint0(max_v_idx)];
1240
1241                 /* Accept the special fix room. */
1242                 if (v_ptr->typ == 17) break;
1243         }
1244
1245         /* No lesser vault found */
1246         if (dummy >= SAFE_MAX_ATTEMPTS)
1247         {
1248                 msg_print_wizard(CHEAT_DUNGEON, _("固定特殊部屋を配置できませんでした。", "Could not place fixed special room."));
1249                 return FALSE;
1250         }
1251
1252         /* pick type of transformation (0-7) */
1253         transno = randint0(8);
1254
1255         /* calculate offsets */
1256         x = v_ptr->wid;
1257         y = v_ptr->hgt;
1258
1259         /* Some huge vault cannot be ratated to fit in the dungeon */
1260         if (x + 2 > cur_hgt - 2)
1261         {
1262                 /* Forbid 90 or 270 degree ratation */
1263                 transno &= ~1;
1264         }
1265
1266         coord_trans(&x, &y, 0, 0, transno);
1267
1268         if (x < 0)
1269         {
1270                 xoffset = -x - 1;
1271         }
1272         else
1273         {
1274                 xoffset = 0;
1275         }
1276
1277         if (y < 0)
1278         {
1279                 yoffset = -y - 1;
1280         }
1281         else
1282         {
1283                 yoffset = 0;
1284         }
1285
1286         /* Find and reserve some space in the dungeon.  Get center of room. */
1287         if (!find_space(&yval, &xval, abs(y), abs(x))) return FALSE;
1288
1289 #ifdef FORCE_V_IDX
1290         v_ptr = &v_info[2];
1291 #endif
1292
1293         msg_format_wizard(CHEAT_DUNGEON, _("特殊固定部屋(%s)を生成しました。", "Special Fix room (%s)."), v_name + v_ptr->name);
1294
1295         /* Hack -- Build the vault */
1296         build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
1297                 v_text + v_ptr->text, xoffset, yoffset, transno);
1298
1299         return TRUE;
1300 }
1301