OSDN Git Service

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