OSDN Git Service

[Add] @return を不要に書き込んだことによる警告をひとまず置換で修正.
[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 "dungeon/dungeon.h"
10 #include "floor/cave.h"
11 #include "floor/floor-generator-util.h"
12 #include "floor/floor-generator.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/lake-types.h"
26 #include "room/rooms-builder.h"
27 #include "room/rooms-maze-vault.h"
28 #include "room/space-finder.h"
29 #include "room/treasure-deployment.h"
30 #include "store/store-util.h"
31 #include "store/store.h"
32 #include "system/dungeon-data-definition.h"
33 #include "system/floor-type-definition.h"
34 #include "system/player-type-definition.h"
35 #include "wizard/wizard-messages.h"
36
37 /*
38  * The vault generation arrays
39  */
40 std::vector<vault_type> v_info;
41
42 /*
43  * Maximum number of vaults in v_info.txt
44  */
45 VAULT_IDX max_v_idx;
46
47 /*
48  * This function creates a random vault that looks like a collection of bubbles.
49  * It works by getting a set of coordinates that represent the center of each
50  * bubble.  The entire room is made by seeing which bubble center is closest. If
51  * two centers are equidistant then the square is a wall, otherwise it is a floor.
52  * The only exception is for squares really near a center, these are always floor.
53  * (It looks better than without this check.)
54  *
55  * Note: If two centers are on the same point then this algorithm will create a
56  *       blank bubble filled with walls. - This is prevented from happening.
57  */
58 static void build_bubble_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize)
59 {
60 #define BUBBLENUM 10 /* number of bubbles */
61
62     /* array of center points of bubbles */
63     coord center[BUBBLENUM];
64
65     int i, j;
66     POSITION x = 0, y = 0;
67     u16b min1, min2, temp;
68     bool done;
69
70     /* Offset from center to top left hand corner */
71     POSITION xhsize = xsize / 2;
72     POSITION yhsize = ysize / 2;
73
74     msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("泡型ランダムVaultを生成しました。", "Bubble-shaped Vault."));
75
76     /* Allocate center of bubbles */
77     center[0].x = (byte)randint1(xsize - 3) + 1;
78     center[0].y = (byte)randint1(ysize - 3) + 1;
79
80     for (i = 1; i < BUBBLENUM; i++) {
81         done = FALSE;
82
83         /* get center and check to see if it is unique */
84         while (!done) {
85             done = TRUE;
86
87             x = randint1(xsize - 3) + 1;
88             y = randint1(ysize - 3) + 1;
89
90             for (j = 0; j < i; j++) {
91                 /* rough test to see if there is an overlap */
92                 if ((x == center[j].x) && (y == center[j].y))
93                     done = FALSE;
94             }
95         }
96
97         center[i].x = x;
98         center[i].y = y;
99     }
100
101     /* Top and bottom boundaries */
102     floor_type *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 = (u16b)distance(x, y, center[0].x, center[0].y);
128             min2 = (u16b)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 = (u16b)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(player_type *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     floor_type *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(player_type *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     floor_type *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     player_type *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     floor_type *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             g_ptr = &floor_ptr->grid_array[y][x];
349
350             /* Lay down a floor */
351             place_grid(player_ptr, g_ptr, GB_FLOOR);
352
353             /* Remove any mimic */
354             g_ptr->mimic = 0;
355
356             /* Part of a vault */
357             g_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
358
359             /* Analyze the grid */
360             switch (*t) {
361                 /* Granite wall (outer) */
362             case '%':
363                 place_grid(player_ptr, g_ptr, GB_OUTER_NOPERM);
364                 break;
365
366                 /* Granite wall (inner) */
367             case '#':
368                 place_grid(player_ptr, g_ptr, GB_INNER);
369                 break;
370
371                 /* Glass wall (inner) */
372             case '$':
373                 place_grid(player_ptr, g_ptr, GB_INNER);
374                 g_ptr->feat = feat_glass_wall;
375                 break;
376
377                 /* Permanent wall (inner) */
378             case 'X':
379                 place_grid(player_ptr, g_ptr, GB_INNER_PERM);
380                 break;
381
382                 /* Permanent glass wall (inner) */
383             case 'Y':
384                 place_grid(player_ptr, g_ptr, GB_INNER_PERM);
385                 g_ptr->feat = feat_permanent_glass_wall;
386                 break;
387
388                 /* Treasure/trap */
389             case '*':
390                 if (randint0(100) < 75) {
391                     place_object(player_ptr, y, x, 0L);
392                 } else {
393                     place_trap(player_ptr, y, x);
394                 }
395                 break;
396
397                 /* Treasure */
398             case '[':
399                 place_object(player_ptr, y, x, 0L);
400                 break;
401
402                 /* Tree */
403             case ':':
404                 g_ptr->feat = feat_tree;
405                 break;
406
407                 /* Secret doors */
408             case '+':
409                 place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
410                 break;
411
412                 /* Secret glass doors */
413             case '-':
414                 place_secret_door(player_ptr, y, x, DOOR_GLASS_DOOR);
415                 if (is_closed_door(player_ptr, g_ptr->feat))
416                     g_ptr->mimic = feat_glass_wall;
417                 break;
418
419                 /* Curtains */
420             case '\'':
421                 place_secret_door(player_ptr, y, x, DOOR_CURTAIN);
422                 break;
423
424                 /* Trap */
425             case '^':
426                 place_trap(player_ptr, y, x);
427                 break;
428
429                 /* Black market in a dungeon */
430             case 'S':
431                 set_cave_feat(floor_ptr, y, x, feat_black_market);
432                 store_init(NO_TOWN, STORE_BLACK);
433                 break;
434
435                 /* The Pattern */
436             case 'p':
437                 set_cave_feat(floor_ptr, y, x, feat_pattern_start);
438                 break;
439
440             case 'a':
441                 set_cave_feat(floor_ptr, y, x, feat_pattern_1);
442                 break;
443
444             case 'b':
445                 set_cave_feat(floor_ptr, y, x, feat_pattern_2);
446                 break;
447
448             case 'c':
449                 set_cave_feat(floor_ptr, y, x, feat_pattern_3);
450                 break;
451
452             case 'd':
453                 set_cave_feat(floor_ptr, y, x, feat_pattern_4);
454                 break;
455
456             case 'P':
457                 set_cave_feat(floor_ptr, y, x, feat_pattern_end);
458                 break;
459
460             case 'B':
461                 set_cave_feat(floor_ptr, y, x, feat_pattern_exit);
462                 break;
463
464             case 'A':
465                 /* Reward for Pattern walk */
466                 floor_ptr->object_level = floor_ptr->base_level + 12;
467                 place_object(player_ptr, y, x, AM_GOOD | AM_GREAT);
468                 floor_ptr->object_level = floor_ptr->base_level;
469                 break;
470
471             case '~':
472                 set_cave_feat(floor_ptr, y, x, feat_shallow_water);
473                 break;
474
475             case '=':
476                 set_cave_feat(floor_ptr, y, x, feat_deep_water);
477                 break;
478
479             case 'v':
480                 set_cave_feat(floor_ptr, y, x, feat_shallow_lava);
481                 break;
482
483             case 'w':
484                 set_cave_feat(floor_ptr, y, x, feat_deep_lava);
485                 break;
486
487             case 'f':
488                 set_cave_feat(floor_ptr, y, x, feat_shallow_acid_puddle);
489                 break;
490
491             case 'F':
492                 set_cave_feat(floor_ptr, y, x, feat_deep_acid_puddle);
493                 break;
494
495             case 'g':
496                 set_cave_feat(floor_ptr, y, x, feat_shallow_poisonous_puddle);
497                 break;
498
499             case 'G':
500                 set_cave_feat(floor_ptr, y, x, feat_deep_poisonous_puddle);
501                 break;
502
503             case 'h':
504                 set_cave_feat(floor_ptr, y, x, feat_cold_zone);
505                 break;
506
507             case 'H':
508                 set_cave_feat(floor_ptr, y, x, feat_heavy_cold_zone);
509                 break;
510
511             case 'i':
512                 set_cave_feat(floor_ptr, y, x, feat_electrical_zone);
513                 break;
514
515             case 'I':
516                 set_cave_feat(floor_ptr, y, x, feat_heavy_electrical_zone);
517                 break;
518             }
519         }
520     }
521
522     /* Place dungeon monsters and objects */
523     for (t = data, dy = 0; dy < ymax; dy++) {
524         for (dx = 0; dx < xmax; dx++, t++) {
525             /* prevent loop counter from being overwritten */
526             i = dx;
527             j = dy;
528
529             /* Flip / rotate */
530             coord_trans(&i, &j, xoffset, yoffset, transno);
531
532             if (transno % 2 == 0) {
533                 /* no swap of x/y */
534                 x = xval - (xmax / 2) + i;
535                 y = yval - (ymax / 2) + j;
536             } else {
537                 /* swap of x/y */
538                 x = xval - (ymax / 2) + i;
539                 y = yval - (xmax / 2) + j;
540             }
541
542             /* Hack -- skip "non-grids" */
543             if (*t == ' ')
544                 continue;
545
546             /* Analyze the symbol */
547             switch (*t) {
548             case '&': {
549                 floor_ptr->monster_level = floor_ptr->base_level + 5;
550                 place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
551                 floor_ptr->monster_level = floor_ptr->base_level;
552                 break;
553             }
554
555             /* Meaner monster */
556             case '@': {
557                 floor_ptr->monster_level = floor_ptr->base_level + 11;
558                 place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
559                 floor_ptr->monster_level = floor_ptr->base_level;
560                 break;
561             }
562
563             /* Meaner monster, plus treasure */
564             case '9': {
565                 floor_ptr->monster_level = floor_ptr->base_level + 9;
566                 place_monster(player_ptr, y, x, PM_ALLOW_SLEEP);
567                 floor_ptr->monster_level = floor_ptr->base_level;
568                 floor_ptr->object_level = floor_ptr->base_level + 7;
569                 place_object(player_ptr, y, x, AM_GOOD);
570                 floor_ptr->object_level = floor_ptr->base_level;
571                 break;
572             }
573
574             /* Nasty monster and treasure */
575             case '8': {
576                 floor_ptr->monster_level = floor_ptr->base_level + 40;
577                 place_monster(player_ptr, y, x, PM_ALLOW_SLEEP);
578                 floor_ptr->monster_level = floor_ptr->base_level;
579                 floor_ptr->object_level = floor_ptr->base_level + 20;
580                 place_object(player_ptr, y, x, AM_GOOD | AM_GREAT);
581                 floor_ptr->object_level = floor_ptr->base_level;
582                 break;
583             }
584
585             /* Monster and/or object */
586             case ',': {
587                 if (randint0(100) < 50) {
588                     floor_ptr->monster_level = floor_ptr->base_level + 3;
589                     place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
590                     floor_ptr->monster_level = floor_ptr->base_level;
591                 }
592                 if (randint0(100) < 50) {
593                     floor_ptr->object_level = floor_ptr->base_level + 7;
594                     place_object(player_ptr, y, x, 0L);
595                     floor_ptr->object_level = floor_ptr->base_level;
596                 }
597                 break;
598             }
599             }
600         }
601     }
602 }
603
604 /*!
605  * @brief タイプ7の部屋…v_info.txtより小型vaultを生成する / Type 7 -- simple vaults (see "v_info.txt")
606  */
607 bool build_type7(player_type *player_ptr, dun_data_type *dd_ptr)
608 {
609     vault_type *v_ptr = NULL;
610     int dummy;
611     POSITION x, y;
612     POSITION xval, yval;
613     POSITION xoffset, yoffset;
614     int transno;
615
616     /* Pick a lesser vault */
617     for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++) {
618         /* Access a random vault record */
619         v_ptr = &v_info[randint0(max_v_idx)];
620
621         /* Accept the first lesser vault */
622         if (v_ptr->typ == 7)
623             break;
624     }
625
626     /* No lesser vault found */
627     if (dummy >= SAFE_MAX_ATTEMPTS) {
628         msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("小型固定Vaultを配置できませんでした。", "Could not place lesser vault."));
629         return FALSE;
630     }
631
632     /* pick type of transformation (0-7) */
633     transno = randint0(8);
634
635     /* calculate offsets */
636     x = v_ptr->wid;
637     y = v_ptr->hgt;
638
639     /* Some huge vault cannot be ratated to fit in the dungeon */
640     floor_type *floor_ptr = player_ptr->current_floor_ptr;
641     if (x + 2 > floor_ptr->height - 2) {
642         /* Forbid 90 or 270 degree ratation */
643         transno &= ~1;
644     }
645
646     coord_trans(&x, &y, 0, 0, transno);
647
648     if (x < 0) {
649         xoffset = -x - 1;
650     } else {
651         xoffset = 0;
652     }
653
654     if (y < 0) {
655         yoffset = -y - 1;
656     } else {
657         yoffset = 0;
658     }
659
660     /* Find and reserve some space in the dungeon.  Get center of room. */
661     if (!find_space(player_ptr, dd_ptr, &yval, &xval, abs(y), abs(x)))
662         return FALSE;
663
664     msg_format_wizard(player_ptr, CHEAT_DUNGEON, _("小型Vault(%s)を生成しました。", "Lesser vault (%s)."), v_ptr->name.c_str());
665
666     /* Hack -- Build the vault */
667     build_vault(player_ptr, yval, xval, v_ptr->hgt, v_ptr->wid, v_ptr->text.c_str(), xoffset, yoffset, transno);
668
669     return TRUE;
670 }
671
672 /*!
673  * @brief タイプ8の部屋…v_info.txtより大型vaultを生成する / Type 8 -- greater vaults (see "v_info.txt")
674  */
675 bool build_type8(player_type *player_ptr, dun_data_type *dd_ptr)
676 {
677     vault_type *v_ptr;
678     int dummy;
679     POSITION xval, yval;
680     POSITION x, y;
681     int transno;
682     POSITION xoffset, yoffset;
683
684     /* Pick a greater vault */
685     for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++) {
686         /* Access a random vault record */
687         v_ptr = &v_info[randint0(max_v_idx)];
688
689         /* Accept the first greater vault */
690         if (v_ptr->typ == 8)
691             break;
692     }
693
694     /* No greater vault found */
695     if (dummy >= SAFE_MAX_ATTEMPTS) {
696         msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("大型固定Vaultを配置できませんでした。", "Could not place greater vault."));
697         return FALSE;
698     }
699
700     /* pick type of transformation (0-7) */
701     transno = randint0(8);
702
703     /* calculate offsets */
704     x = v_ptr->wid;
705     y = v_ptr->hgt;
706
707     /* Some huge vault cannot be ratated to fit in the dungeon */
708     floor_type *floor_ptr = player_ptr->current_floor_ptr;
709     if (x + 2 > floor_ptr->height - 2) {
710         /* Forbid 90 or 270 degree ratation */
711         transno &= ~1;
712     }
713
714     coord_trans(&x, &y, 0, 0, transno);
715
716     if (x < 0) {
717         xoffset = -x - 1;
718     } else {
719         xoffset = 0;
720     }
721
722     if (y < 0) {
723         yoffset = -y - 1;
724     } else {
725         yoffset = 0;
726     }
727
728     /*
729      * Try to allocate space for room.  If fails, exit
730      *
731      * Hack -- Prepare a bit larger space (+2, +2) to
732      * prevent generation of vaults with no-entrance.
733      */
734     /* Find and reserve some space in the dungeon.  Get center of room. */
735     if (!find_space(player_ptr, dd_ptr, &yval, &xval, (POSITION)(abs(y) + 2), (POSITION)(abs(x) + 2)))
736         return FALSE;
737
738     msg_format_wizard(player_ptr, CHEAT_DUNGEON, _("大型固定Vault(%s)を生成しました。", "Greater vault (%s)."), v_ptr->name.c_str());
739
740     /* Hack -- Build the vault */
741     build_vault(player_ptr, yval, xval, v_ptr->hgt, v_ptr->wid, v_ptr->text.c_str(), xoffset, yoffset, transno);
742
743     return TRUE;
744 }
745
746 /*
747  * Build target vault.
748  * This is made by two concentric "crypts" with perpendicular
749  * walls creating the cross-hairs.
750  */
751 static void build_target_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize)
752 {
753     POSITION rad, x, y;
754
755     /* Make a random metric */
756     POSITION h1, h2, h3, h4;
757     h1 = randint1(32) - 16;
758     h2 = randint1(16);
759     h3 = randint1(32);
760     h4 = randint1(32) - 16;
761
762     msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("対称形ランダムVaultを生成しました。", "Target Vault"));
763
764     /* work out outer radius */
765     if (xsize > ysize) {
766         rad = ysize / 2;
767     } else {
768         rad = xsize / 2;
769     }
770
771     /* Make floor */
772     floor_type *floor_ptr = player_ptr->current_floor_ptr;
773     for (x = x0 - rad; x <= x0 + rad; x++) {
774         for (y = y0 - rad; y <= y0 + rad; y++) {
775             /* clear room flag */
776             floor_ptr->grid_array[y][x].info &= ~(CAVE_ROOM);
777
778             /* Vault - so is "icky" */
779             floor_ptr->grid_array[y][x].info |= CAVE_ICKY;
780
781             if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1) {
782                 /* inside- so is floor */
783                 place_bold(player_ptr, y, x, GB_FLOOR);
784             } else {
785                 /* make granite outside so on_defeat_arena_monster works */
786                 place_bold(player_ptr, y, x, GB_EXTRA);
787             }
788
789             /* proper boundary for on_defeat_arena_monster */
790             if (((y + rad) == y0) || ((y - rad) == y0) || ((x + rad) == x0) || ((x - rad) == x0)) {
791                 place_bold(player_ptr, y, x, GB_EXTRA);
792             }
793         }
794     }
795
796     /* Find visible outer walls and set to be FEAT_OUTER */
797     add_outer_wall(player_ptr, x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1, x0 + rad + 1, y0 + rad + 1);
798
799     /* Add inner wall */
800     for (x = x0 - rad / 2; x <= x0 + rad / 2; x++) {
801         for (y = y0 - rad / 2; y <= y0 + rad / 2; y++) {
802             if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2) {
803                 /* Make an internal wall */
804                 place_bold(player_ptr, y, x, GB_INNER);
805             }
806         }
807     }
808
809     /* Add perpendicular walls */
810     for (x = x0 - rad; x <= x0 + rad; x++) {
811         place_bold(player_ptr, y0, x, GB_INNER);
812     }
813
814     for (y = y0 - rad; y <= y0 + rad; y++) {
815         place_bold(player_ptr, y, x0, GB_INNER);
816     }
817
818     /* Make inner vault */
819     for (y = y0 - 1; y <= y0 + 1; y++) {
820         place_bold(player_ptr, y, x0 - 1, GB_INNER);
821         place_bold(player_ptr, y, x0 + 1, GB_INNER);
822     }
823     for (x = x0 - 1; x <= x0 + 1; x++) {
824         place_bold(player_ptr, y0 - 1, x, GB_INNER);
825         place_bold(player_ptr, y0 + 1, x, GB_INNER);
826     }
827
828     place_bold(player_ptr, y0, x0, GB_FLOOR);
829
830     /* Add doors to vault */
831     /* get two distances so can place doors relative to centre */
832     x = (rad - 2) / 4 + 1;
833     y = rad / 2 + x;
834
835     add_door(player_ptr, x0 + x, y0);
836     add_door(player_ptr, x0 + y, y0);
837     add_door(player_ptr, x0 - x, y0);
838     add_door(player_ptr, x0 - y, y0);
839     add_door(player_ptr, x0, y0 + x);
840     add_door(player_ptr, x0, y0 + y);
841     add_door(player_ptr, x0, y0 - x);
842     add_door(player_ptr, x0, y0 - y);
843
844     /* Fill with stuff - medium difficulty */
845     fill_treasure(player_ptr, x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
846 }
847
848 /*
849  * This routine uses a modified version of the lake code to make a
850  * distribution of some terrain type over the vault.  This type
851  * depends on the dungeon depth.
852  *
853  * Miniture rooms are then scattered across the vault.
854  */
855 static void build_elemental_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsiz, POSITION ysiz)
856 {
857     int grd, roug;
858     int c1, c2, c3;
859     bool done = FALSE;
860     POSITION xsize, ysize, xhsize, yhsize, x, y;
861     int i;
862     int type;
863
864     msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("精霊界ランダムVaultを生成しました。", "Elemental Vault"));
865
866     /* round to make sizes even */
867     xhsize = xsiz / 2;
868     yhsize = ysiz / 2;
869     xsize = xhsize * 2;
870     ysize = yhsize * 2;
871
872     floor_type *floor_ptr = player_ptr->current_floor_ptr;
873     if (floor_ptr->dun_level < 25) {
874         /* Earth vault  (Rubble) */
875         type = LAKE_T_EARTH_VAULT;
876     } else if (floor_ptr->dun_level < 50) {
877         /* Air vault (Trees) */
878         type = LAKE_T_AIR_VAULT;
879     } else if (floor_ptr->dun_level < 75) {
880         /* Water vault (shallow water) */
881         type = LAKE_T_WATER_VAULT;
882     } else {
883         /* Fire vault (shallow lava) */
884         type = LAKE_T_FIRE_VAULT;
885     }
886
887     while (!done) {
888         /* testing values for these parameters: feel free to adjust */
889         grd = 1 << (randint0(3));
890
891         /* want average of about 16 */
892         roug = randint1(8) * randint1(4);
893
894         /* Make up size of various componants */
895         /* Floor */
896         c3 = 2 * xsize / 3;
897
898         /* Deep water/lava */
899         c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
900
901         /* Shallow boundary */
902         c2 = (c1 + c3) / 2;
903
904         /* make it */
905         generate_hmap(floor_ptr, y0, x0, xsize, ysize, grd, roug, c3);
906
907         /* Convert to normal format+ clean up */
908         done = generate_lake(player_ptr, y0, x0, xsize, ysize, c1, c2, c3, type);
909     }
910
911     /* Set icky flag because is a vault */
912     for (x = 0; x <= xsize; x++) {
913         for (y = 0; y <= ysize; y++) {
914             floor_ptr->grid_array[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
915         }
916     }
917
918     /* make a few rooms in the vault */
919     for (i = 1; i <= (xsize * ysize) / 50; i++) {
920         build_small_room(player_ptr, x0 + randint0(xsize - 4) - xsize / 2 + 2, y0 + randint0(ysize - 4) - ysize / 2 + 2);
921     }
922
923     /* Fill with monsters and treasure, low difficulty */
924     fill_treasure(player_ptr, x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
925 }
926
927 /* Build a "mini" checkerboard vault
928  *
929  * This is done by making a permanent wall maze and setting
930  * the diagonal sqaures of the checker board to be granite.
931  * The vault has two entrances on opposite sides to guarantee
932  * a way to get in even if the vault abuts a side of the dungeon.
933  */
934 static void build_mini_c_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize)
935 {
936     POSITION dy, dx;
937     POSITION y1, x1, y2, x2, y, x, total;
938     int m, n, num_vertices;
939     int *visited;
940
941     msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("小型チェッカーランダムVaultを生成しました。", "Mini Checker Board Vault."));
942
943     /* Pick a random room size */
944     dy = ysize / 2 - 1;
945     dx = xsize / 2 - 1;
946
947     y1 = y0 - dy;
948     x1 = x0 - dx;
949     y2 = y0 + dy;
950     x2 = x0 + dx;
951
952     /* generate the room */
953     floor_type *floor_ptr = player_ptr->current_floor_ptr;
954     for (x = x1 - 2; x <= x2 + 2; x++) {
955         if (!in_bounds(floor_ptr, y1 - 2, x))
956             break;
957
958         floor_ptr->grid_array[y1 - 2][x].info |= (CAVE_ROOM | CAVE_ICKY);
959
960         place_bold(player_ptr, y1 - 2, x, GB_OUTER_NOPERM);
961     }
962
963     for (x = x1 - 2; x <= x2 + 2; x++) {
964         if (!in_bounds(floor_ptr, y2 + 2, x))
965             break;
966
967         floor_ptr->grid_array[y2 + 2][x].info |= (CAVE_ROOM | CAVE_ICKY);
968
969         place_bold(player_ptr, y2 + 2, x, GB_OUTER_NOPERM);
970     }
971
972     for (y = y1 - 2; y <= y2 + 2; y++) {
973         if (!in_bounds(floor_ptr, y, x1 - 2))
974             break;
975
976         floor_ptr->grid_array[y][x1 - 2].info |= (CAVE_ROOM | CAVE_ICKY);
977
978         place_bold(player_ptr, y, x1 - 2, GB_OUTER_NOPERM);
979     }
980
981     for (y = y1 - 2; y <= y2 + 2; y++) {
982         if (!in_bounds(floor_ptr, y, x2 + 2))
983             break;
984
985         floor_ptr->grid_array[y][x2 + 2].info |= (CAVE_ROOM | CAVE_ICKY);
986
987         place_bold(player_ptr, y, x2 + 2, GB_OUTER_NOPERM);
988     }
989
990     for (y = y1 - 1; y <= y2 + 1; y++) {
991         for (x = x1 - 1; x <= x2 + 1; x++) {
992             grid_type *g_ptr = &floor_ptr->grid_array[y][x];
993
994             g_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
995
996             /* Permanent walls */
997             place_grid(player_ptr, g_ptr, GB_INNER_PERM);
998         }
999     }
1000
1001     /* dimensions of vertex array */
1002     m = dx + 1;
1003     n = dy + 1;
1004     num_vertices = m * n;
1005
1006     /* initialize array of visited vertices */
1007     C_MAKE(visited, num_vertices, int);
1008
1009     /* traverse the graph to create a spannng tree, pick a random root */
1010     r_visit(player_ptr, y1, x1, y2, x2, randint0(num_vertices), 0, visited);
1011
1012     /* Make it look like a checker board vault */
1013     for (x = x1; x <= x2; x++) {
1014         for (y = y1; y <= y2; y++) {
1015             total = x - x1 + y - y1;
1016             /* If total is odd- and is a floor then make a wall */
1017             if ((total % 2 == 1) && is_floor_bold(floor_ptr, y, x)) {
1018                 place_bold(player_ptr, y, x, GB_INNER);
1019             }
1020         }
1021     }
1022
1023     /* Make a couple of entrances */
1024     if (one_in_(2)) {
1025         /* left and right */
1026         y = randint1(dy) + dy / 2;
1027         place_bold(player_ptr, y1 + y, x1 - 1, GB_INNER);
1028         place_bold(player_ptr, y1 + y, x2 + 1, GB_INNER);
1029     } else {
1030         /* top and bottom */
1031         x = randint1(dx) + dx / 2;
1032         place_bold(player_ptr, y1 - 1, x1 + x, GB_INNER);
1033         place_bold(player_ptr, y2 + 1, x1 + x, GB_INNER);
1034     }
1035
1036     /* Fill with monsters and treasure, highest difficulty */
1037     fill_treasure(player_ptr, x1, x2, y1, y2, 10);
1038
1039     C_KILL(visited, num_vertices, int);
1040 }
1041
1042 /* Build a castle */
1043 /* Driver routine: clear the region and call the recursive
1044  * room routine.
1045  *
1046  *This makes a vault that looks like a castle/ city in the dungeon.
1047  */
1048 static void build_castle_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize)
1049 {
1050     POSITION dy, dx;
1051     POSITION y1, x1, y2, x2;
1052     POSITION y, x;
1053
1054     /* Pick a random room size */
1055     dy = ysize / 2 - 1;
1056     dx = xsize / 2 - 1;
1057
1058     y1 = y0 - dy;
1059     x1 = x0 - dx;
1060     y2 = y0 + dy;
1061     x2 = x0 + dx;
1062
1063     msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("城型ランダムVaultを生成しました。", "Castle Vault"));
1064
1065     /* generate the room */
1066     floor_type *floor_ptr = player_ptr->current_floor_ptr;
1067     for (y = y1 - 1; y <= y2 + 1; y++) {
1068         for (x = x1 - 1; x <= x2 + 1; x++) {
1069             floor_ptr->grid_array[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
1070             /* Make everything a floor */
1071             place_bold(player_ptr, y, x, GB_FLOOR);
1072         }
1073     }
1074
1075     /* Make the castle */
1076     build_recursive_room(player_ptr, x1, y1, x2, y2, randint1(5));
1077
1078     /* Fill with monsters and treasure, low difficulty */
1079     fill_treasure(player_ptr, x1, x2, y1, y2, randint1(3));
1080 }
1081
1082 /*!
1083  * @brief タイプ10の部屋…ランダム生成vault / Type 10 -- Random vaults
1084  * @param player_ptr プレーヤーへの参照ポインタ
1085  */
1086 bool build_type10(player_type *player_ptr, dun_data_type *dd_ptr)
1087 {
1088     POSITION y0, x0, xsize, ysize, vtype;
1089
1090     /* big enough to look good, small enough to be fairly common. */
1091     xsize = randint1(22) + 22;
1092     ysize = randint1(11) + 11;
1093
1094     /* Find and reserve some space in the dungeon.  Get center of room. */
1095     floor_type *floor_ptr = player_ptr->current_floor_ptr;
1096     if (!find_space(player_ptr, dd_ptr, &y0, &x0, ysize + 1, xsize + 1))
1097         return FALSE;
1098
1099     /* Select type of vault */
1100     do {
1101         vtype = randint1(15);
1102     } while ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) && ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11)));
1103
1104     switch (vtype) {
1105         /* Build an appropriate room */
1106     case 1:
1107     case 9:
1108         build_bubble_vault(player_ptr, x0, y0, xsize, ysize);
1109         break;
1110     case 2:
1111     case 10:
1112         build_room_vault(player_ptr, x0, y0, xsize, ysize);
1113         break;
1114     case 3:
1115     case 11:
1116         build_cave_vault(player_ptr, x0, y0, xsize, ysize);
1117         break;
1118     case 4:
1119     case 12:
1120         build_maze_vault(player_ptr, x0, y0, xsize, ysize, TRUE);
1121         break;
1122     case 5:
1123     case 13:
1124         build_mini_c_vault(player_ptr, x0, y0, xsize, ysize);
1125         break;
1126     case 6:
1127     case 14:
1128         build_castle_vault(player_ptr, x0, y0, xsize, ysize);
1129         break;
1130     case 7:
1131     case 15:
1132         build_target_vault(player_ptr, x0, y0, xsize, ysize);
1133         break;
1134     case 8:
1135         build_elemental_vault(player_ptr, x0, y0, xsize, ysize);
1136         break;
1137         /* I know how to add a few more... give me some time. */
1138     default:
1139         return FALSE;
1140     }
1141
1142     return TRUE;
1143 }
1144
1145 /*!
1146  * @brief タイプ17の部屋…v_info.txtより固定特殊部屋を生成する / Type 17 -- fixed special room (see "v_info.txt")
1147  */
1148 bool build_type17(player_type *player_ptr, dun_data_type *dd_ptr)
1149 {
1150     vault_type *v_ptr = NULL;
1151     int dummy;
1152     POSITION x, y;
1153     POSITION xval, yval;
1154     POSITION xoffset, yoffset;
1155     int transno;
1156
1157     /* Pick a lesser vault */
1158     for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++) {
1159         /* Access a random vault record */
1160         v_ptr = &v_info[randint0(max_v_idx)];
1161
1162         /* Accept the special fix room. */
1163         if (v_ptr->typ == 17)
1164             break;
1165     }
1166
1167     /* No lesser vault found */
1168     if (dummy >= SAFE_MAX_ATTEMPTS) {
1169         msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("固定特殊部屋を配置できませんでした。", "Could not place fixed special room."));
1170         return FALSE;
1171     }
1172
1173     /* pick type of transformation (0-7) */
1174     transno = randint0(8);
1175
1176     /* calculate offsets */
1177     x = v_ptr->wid;
1178     y = v_ptr->hgt;
1179
1180     /* Some huge vault cannot be ratated to fit in the dungeon */
1181     floor_type *floor_ptr = player_ptr->current_floor_ptr;
1182     if (x + 2 > floor_ptr->height - 2) {
1183         /* Forbid 90 or 270 degree ratation */
1184         transno &= ~1;
1185     }
1186
1187     coord_trans(&x, &y, 0, 0, transno);
1188
1189     if (x < 0) {
1190         xoffset = -x - 1;
1191     } else {
1192         xoffset = 0;
1193     }
1194
1195     if (y < 0) {
1196         yoffset = -y - 1;
1197     } else {
1198         yoffset = 0;
1199     }
1200
1201     /* Find and reserve some space in the dungeon.  Get center of room. */
1202     if (!find_space(player_ptr, dd_ptr, &yval, &xval, abs(y), abs(x)))
1203         return FALSE;
1204
1205     msg_format_wizard(player_ptr, CHEAT_DUNGEON, _("特殊固定部屋(%s)を生成しました。", "Special Fixed Room (%s)."), v_ptr->name.c_str());
1206
1207     /* Hack -- Build the vault */
1208     build_vault(player_ptr, yval, xval, v_ptr->hgt, v_ptr->wid, v_ptr->text.c_str(), xoffset, yoffset, transno);
1209
1210     return TRUE;
1211 }