OSDN Git Service

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