OSDN Git Service

Merge branch 'master' of git.osdn.net:/gitroot/hengband/hengband
[hengband/hengband.git] / src / room / rooms-vault.c
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/wild.h"
14 #include "game-option/cheat-types.h"
15 #include "grid/door.h"
16 #include "grid/feature.h"
17 #include "grid/grid.h"
18 #include "grid/object-placer.h"
19 #include "grid/trap.h"
20 #include "monster-floor/monster-generator.h"
21 #include "monster-floor/place-monster-types.h"
22 #include "object-enchant/item-apply-magic.h"
23 #include "room/cave-filler.h"
24 #include "room/lake-types.h"
25 #include "room/rooms-builder.h"
26 #include "room/rooms-maze-vault.h"
27 #include "room/space-finder.h"
28 #include "room/treasure-deployment.h"
29 #include "store/store-util.h"
30 #include "store/store.h"
31 #include "system/dungeon-data-definition.h"
32 #include "system/floor-type-definition.h"
33 #include "wizard/wizard-messages.h"
34
35 /*
36  * The vault generation arrays
37  */
38 vault_type *v_info;
39 char *v_name;
40 char *v_text;
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を生成しました。", "Room 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  * @return なし
274  */
275 static void coord_trans(POSITION *x, POSITION *y, POSITION xoffset, POSITION yoffset, int transno)
276 {
277     int i;
278     int temp;
279
280     /*
281      * transno specifies what transformation is required. (0-7)
282      * The lower two bits indicate by how much the vault is rotated,
283      * and the upper bit indicates a reflection.
284      * This is done by using rotation matrices... however since
285      * these are mostly zeros for rotations by 90 degrees this can
286      * be expressed simply in terms of swapping and inverting the
287      * x and y coordinates.
288      */
289     for (i = 0; i < transno % 4; i++) {
290         /* rotate by 90 degrees */
291         temp = *x;
292         *x = -(*y);
293         *y = temp;
294     }
295
296     if (transno / 4) {
297         /* Reflect depending on status of 3rd bit. */
298         *x = -(*x);
299     }
300
301     /* Add offsets so vault stays in the first quadrant */
302     *x += xoffset;
303     *y += yoffset;
304 }
305
306 /*!
307  * @brief Vaultをフロアに配置する / Hack -- fill in "vault" rooms
308  * @param player_ptr プレーヤーへの参照ポインタ
309  * @param yval 生成基準Y座標
310  * @param xval 生成基準X座標
311  * @param ymax VaultのYサイズ
312  * @param xmax VaultのXサイズ
313  * @param data Vaultのデータ文字列
314  * @param xoffset 変換基準X座標
315  * @param yoffset 変換基準Y座標
316  * @param transno 変換ID
317  * @return なし
318  */
319 static void build_vault(
320     player_type *player_ptr, POSITION yval, POSITION xval, POSITION ymax, POSITION xmax, concptr data, POSITION xoffset, POSITION yoffset, int transno)
321 {
322     POSITION dx, dy, x, y, i, j;
323     concptr t;
324     grid_type *g_ptr;
325
326     /* Place dungeon features and objects */
327     floor_type *floor_ptr = player_ptr->current_floor_ptr;
328     for (t = data, dy = 0; dy < ymax; dy++) {
329         for (dx = 0; dx < xmax; dx++, t++) {
330             /* prevent loop counter from being overwritten */
331             i = dx;
332             j = dy;
333
334             /* Flip / rotate */
335             coord_trans(&i, &j, xoffset, yoffset, transno);
336
337             if (transno % 2 == 0) {
338                 /* no swap of x/y */
339                 x = xval - (xmax / 2) + i;
340                 y = yval - (ymax / 2) + j;
341             } else {
342                 /* swap of x/y */
343                 x = xval - (ymax / 2) + i;
344                 y = yval - (xmax / 2) + j;
345             }
346
347             /* Hack -- skip "non-grids" */
348             if (*t == ' ')
349                 continue;
350             g_ptr = &floor_ptr->grid_array[y][x];
351
352             /* Lay down a floor */
353             place_grid(player_ptr, g_ptr, GB_FLOOR);
354
355             /* Remove any mimic */
356             g_ptr->mimic = 0;
357
358             /* Part of a vault */
359             g_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
360
361             /* Analyze the grid */
362             switch (*t) {
363                 /* Granite wall (outer) */
364             case '%':
365                 place_grid(player_ptr, g_ptr, GB_OUTER_NOPERM);
366                 break;
367
368                 /* Granite wall (inner) */
369             case '#':
370                 place_grid(player_ptr, g_ptr, GB_INNER);
371                 break;
372
373                 /* Glass wall (inner) */
374             case '$':
375                 place_grid(player_ptr, g_ptr, GB_INNER);
376                 g_ptr->feat = feat_glass_wall;
377                 break;
378
379                 /* Permanent wall (inner) */
380             case 'X':
381                 place_grid(player_ptr, g_ptr, GB_INNER_PERM);
382                 break;
383
384                 /* Permanent glass wall (inner) */
385             case 'Y':
386                 place_grid(player_ptr, g_ptr, GB_INNER_PERM);
387                 g_ptr->feat = feat_permanent_glass_wall;
388                 break;
389
390                 /* Treasure/trap */
391             case '*':
392                 if (randint0(100) < 75) {
393                     place_object(player_ptr, y, x, 0L);
394                 } else {
395                     place_trap(player_ptr, y, x);
396                 }
397                 break;
398
399                 /* Treasure */
400             case '[':
401                 place_object(player_ptr, y, x, 0L);
402                 break;
403
404                 /* Tree */
405             case ':':
406                 g_ptr->feat = feat_tree;
407                 break;
408
409                 /* Secret doors */
410             case '+':
411                 place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
412                 break;
413
414                 /* Secret glass doors */
415             case '-':
416                 place_secret_door(player_ptr, y, x, DOOR_GLASS_DOOR);
417                 if (is_closed_door(player_ptr, g_ptr->feat))
418                     g_ptr->mimic = feat_glass_wall;
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(NO_TOWN, STORE_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             /* Analyze the symbol */
549             switch (*t) {
550             case '&': {
551                 floor_ptr->monster_level = floor_ptr->base_level + 5;
552                 place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
553                 floor_ptr->monster_level = floor_ptr->base_level;
554                 break;
555             }
556
557             /* Meaner monster */
558             case '@': {
559                 floor_ptr->monster_level = floor_ptr->base_level + 11;
560                 place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
561                 floor_ptr->monster_level = floor_ptr->base_level;
562                 break;
563             }
564
565             /* Meaner monster, plus treasure */
566             case '9': {
567                 floor_ptr->monster_level = floor_ptr->base_level + 9;
568                 place_monster(player_ptr, y, x, PM_ALLOW_SLEEP);
569                 floor_ptr->monster_level = floor_ptr->base_level;
570                 floor_ptr->object_level = floor_ptr->base_level + 7;
571                 place_object(player_ptr, y, x, AM_GOOD);
572                 floor_ptr->object_level = floor_ptr->base_level;
573                 break;
574             }
575
576             /* Nasty monster and treasure */
577             case '8': {
578                 floor_ptr->monster_level = floor_ptr->base_level + 40;
579                 place_monster(player_ptr, y, x, PM_ALLOW_SLEEP);
580                 floor_ptr->monster_level = floor_ptr->base_level;
581                 floor_ptr->object_level = floor_ptr->base_level + 20;
582                 place_object(player_ptr, y, x, AM_GOOD | AM_GREAT);
583                 floor_ptr->object_level = floor_ptr->base_level;
584                 break;
585             }
586
587             /* Monster and/or object */
588             case ',': {
589                 if (randint0(100) < 50) {
590                     floor_ptr->monster_level = floor_ptr->base_level + 3;
591                     place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
592                     floor_ptr->monster_level = floor_ptr->base_level;
593                 }
594                 if (randint0(100) < 50) {
595                     floor_ptr->object_level = floor_ptr->base_level + 7;
596                     place_object(player_ptr, y, x, 0L);
597                     floor_ptr->object_level = floor_ptr->base_level;
598                 }
599                 break;
600             }
601             }
602         }
603     }
604 }
605
606 /*!
607  * @brief タイプ7の部屋…v_info.txtより小型vaultを生成する / Type 7 -- simple vaults (see "v_info.txt")
608  * @return なし
609  */
610 bool build_type7(player_type *player_ptr, dun_data_type *dd_ptr)
611 {
612     vault_type *v_ptr = NULL;
613     int dummy;
614     POSITION x, y;
615     POSITION xval, yval;
616     POSITION xoffset, yoffset;
617     int transno;
618
619     /* Pick a lesser vault */
620     for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++) {
621         /* Access a random vault record */
622         v_ptr = &v_info[randint0(max_v_idx)];
623
624         /* Accept the first lesser vault */
625         if (v_ptr->typ == 7)
626             break;
627     }
628
629     /* No lesser vault found */
630     if (dummy >= SAFE_MAX_ATTEMPTS) {
631         msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("小型固定Vaultを配置できませんでした。", "Could not place lesser vault."));
632         return FALSE;
633     }
634
635     /* pick type of transformation (0-7) */
636     transno = randint0(8);
637
638     /* calculate offsets */
639     x = v_ptr->wid;
640     y = v_ptr->hgt;
641
642     /* Some huge vault cannot be ratated to fit in the dungeon */
643     floor_type *floor_ptr = player_ptr->current_floor_ptr;
644     if (x + 2 > floor_ptr->height - 2) {
645         /* Forbid 90 or 270 degree ratation */
646         transno &= ~1;
647     }
648
649     coord_trans(&x, &y, 0, 0, transno);
650
651     if (x < 0) {
652         xoffset = -x - 1;
653     } else {
654         xoffset = 0;
655     }
656
657     if (y < 0) {
658         yoffset = -y - 1;
659     } else {
660         yoffset = 0;
661     }
662
663     /* Find and reserve some space in the dungeon.  Get center of room. */
664     if (!find_space(player_ptr, dd_ptr, &yval, &xval, abs(y), abs(x)))
665         return FALSE;
666
667     msg_format_wizard(player_ptr, CHEAT_DUNGEON, _("小型Vault(%s)を生成しました。", "Lesser vault (%s)."), v_name + v_ptr->name);
668
669     /* Hack -- Build the vault */
670     build_vault(player_ptr, yval, xval, v_ptr->hgt, v_ptr->wid, v_text + v_ptr->text, xoffset, yoffset, transno);
671
672     return TRUE;
673 }
674
675 /*!
676  * @brief タイプ8の部屋…v_info.txtより大型vaultを生成する / Type 8 -- greater vaults (see "v_info.txt")
677  * @return なし
678  */
679 bool build_type8(player_type *player_ptr, dun_data_type *dd_ptr)
680 {
681     vault_type *v_ptr;
682     int dummy;
683     POSITION xval, yval;
684     POSITION x, y;
685     int transno;
686     POSITION xoffset, yoffset;
687
688     /* Pick a greater vault */
689     for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++) {
690         /* Access a random vault record */
691         v_ptr = &v_info[randint0(max_v_idx)];
692
693         /* Accept the first greater vault */
694         if (v_ptr->typ == 8)
695             break;
696     }
697
698     /* No greater vault found */
699     if (dummy >= SAFE_MAX_ATTEMPTS) {
700         msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("大型固定Vaultを配置できませんでした。", "Could not place greater vault."));
701         return FALSE;
702     }
703
704     /* pick type of transformation (0-7) */
705     transno = randint0(8);
706
707     /* calculate offsets */
708     x = v_ptr->wid;
709     y = v_ptr->hgt;
710
711     /* Some huge vault cannot be ratated to fit in the dungeon */
712     floor_type *floor_ptr = player_ptr->current_floor_ptr;
713     if (x + 2 > floor_ptr->height - 2) {
714         /* Forbid 90 or 270 degree ratation */
715         transno &= ~1;
716     }
717
718     coord_trans(&x, &y, 0, 0, transno);
719
720     if (x < 0) {
721         xoffset = -x - 1;
722     } else {
723         xoffset = 0;
724     }
725
726     if (y < 0) {
727         yoffset = -y - 1;
728     } else {
729         yoffset = 0;
730     }
731
732     /*
733      * Try to allocate space for room.  If fails, exit
734      *
735      * Hack -- Prepare a bit larger space (+2, +2) to
736      * prevent generation of vaults with no-entrance.
737      */
738     /* Find and reserve some space in the dungeon.  Get center of room. */
739     if (!find_space(player_ptr, dd_ptr, &yval, &xval, (POSITION)(abs(y) + 2), (POSITION)(abs(x) + 2)))
740         return FALSE;
741
742     msg_format_wizard(player_ptr, CHEAT_DUNGEON, _("大型固定Vault(%s)を生成しました。", "Greater vault (%s)."), v_name + v_ptr->name);
743
744     /* Hack -- Build the vault */
745     build_vault(player_ptr, yval, xval, v_ptr->hgt, v_ptr->wid, v_text + v_ptr->text, xoffset, yoffset, transno);
746
747     return TRUE;
748 }
749
750 /*
751  * Build target vault.
752  * This is made by two concentric "crypts" with perpendicular
753  * walls creating the cross-hairs.
754  */
755 static void build_target_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize)
756 {
757     POSITION rad, x, y;
758
759     /* Make a random metric */
760     POSITION h1, h2, h3, h4;
761     h1 = randint1(32) - 16;
762     h2 = randint1(16);
763     h3 = randint1(32);
764     h4 = randint1(32) - 16;
765
766     msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("対称形ランダムVaultを生成しました。", "Elemental Vault"));
767
768     /* work out outer radius */
769     if (xsize > ysize) {
770         rad = ysize / 2;
771     } else {
772         rad = xsize / 2;
773     }
774
775     /* Make floor */
776     floor_type *floor_ptr = player_ptr->current_floor_ptr;
777     for (x = x0 - rad; x <= x0 + rad; x++) {
778         for (y = y0 - rad; y <= y0 + rad; y++) {
779             /* clear room flag */
780             floor_ptr->grid_array[y][x].info &= ~(CAVE_ROOM);
781
782             /* Vault - so is "icky" */
783             floor_ptr->grid_array[y][x].info |= CAVE_ICKY;
784
785             if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1) {
786                 /* inside- so is floor */
787                 place_bold(player_ptr, y, x, GB_FLOOR);
788             } else {
789                 /* make granite outside so on_defeat_arena_monster works */
790                 place_bold(player_ptr, y, x, GB_EXTRA);
791             }
792
793             /* proper boundary for on_defeat_arena_monster */
794             if (((y + rad) == y0) || ((y - rad) == y0) || ((x + rad) == x0) || ((x - rad) == x0)) {
795                 place_bold(player_ptr, y, x, GB_EXTRA);
796             }
797         }
798     }
799
800     /* Find visible outer walls and set to be FEAT_OUTER */
801     add_outer_wall(player_ptr, x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1, x0 + rad + 1, y0 + rad + 1);
802
803     /* Add inner wall */
804     for (x = x0 - rad / 2; x <= x0 + rad / 2; x++) {
805         for (y = y0 - rad / 2; y <= y0 + rad / 2; y++) {
806             if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2) {
807                 /* Make an internal wall */
808                 place_bold(player_ptr, y, x, GB_INNER);
809             }
810         }
811     }
812
813     /* Add perpendicular walls */
814     for (x = x0 - rad; x <= x0 + rad; x++) {
815         place_bold(player_ptr, y0, x, GB_INNER);
816     }
817
818     for (y = y0 - rad; y <= y0 + rad; y++) {
819         place_bold(player_ptr, y, x0, GB_INNER);
820     }
821
822     /* Make inner vault */
823     for (y = y0 - 1; y <= y0 + 1; y++) {
824         place_bold(player_ptr, y, x0 - 1, GB_INNER);
825         place_bold(player_ptr, y, x0 + 1, GB_INNER);
826     }
827     for (x = x0 - 1; x <= x0 + 1; x++) {
828         place_bold(player_ptr, y0 - 1, x, GB_INNER);
829         place_bold(player_ptr, y0 + 1, x, GB_INNER);
830     }
831
832     place_bold(player_ptr, y0, x0, GB_FLOOR);
833
834     /* Add doors to vault */
835     /* get two distances so can place doors relative to centre */
836     x = (rad - 2) / 4 + 1;
837     y = rad / 2 + x;
838
839     add_door(player_ptr, x0 + x, y0);
840     add_door(player_ptr, x0 + y, y0);
841     add_door(player_ptr, x0 - x, y0);
842     add_door(player_ptr, x0 - y, y0);
843     add_door(player_ptr, x0, y0 + x);
844     add_door(player_ptr, x0, y0 + y);
845     add_door(player_ptr, x0, y0 - x);
846     add_door(player_ptr, x0, y0 - y);
847
848     /* Fill with stuff - medium difficulty */
849     fill_treasure(player_ptr, x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
850 }
851
852 /*
853  * This routine uses a modified version of the lake code to make a
854  * distribution of some terrain type over the vault.  This type
855  * depends on the dungeon depth.
856  *
857  * Miniture rooms are then scattered across the vault.
858  */
859 static void build_elemental_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsiz, POSITION ysiz)
860 {
861     int grd, roug;
862     int c1, c2, c3;
863     bool done = FALSE;
864     POSITION xsize, ysize, xhsize, yhsize, x, y;
865     int i;
866     int type;
867
868     msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("精霊界ランダムVaultを生成しました。", "Elemental Vault"));
869
870     /* round to make sizes even */
871     xhsize = xsiz / 2;
872     yhsize = ysiz / 2;
873     xsize = xhsize * 2;
874     ysize = yhsize * 2;
875
876     floor_type *floor_ptr = player_ptr->current_floor_ptr;
877     if (floor_ptr->dun_level < 25) {
878         /* Earth vault  (Rubble) */
879         type = LAKE_T_EARTH_VAULT;
880     } else if (floor_ptr->dun_level < 50) {
881         /* Air vault (Trees) */
882         type = LAKE_T_AIR_VAULT;
883     } else if (floor_ptr->dun_level < 75) {
884         /* Water vault (shallow water) */
885         type = LAKE_T_WATER_VAULT;
886     } else {
887         /* Fire vault (shallow lava) */
888         type = LAKE_T_FIRE_VAULT;
889     }
890
891     while (!done) {
892         /* testing values for these parameters: feel free to adjust */
893         grd = 1 << (randint0(3));
894
895         /* want average of about 16 */
896         roug = randint1(8) * randint1(4);
897
898         /* Make up size of various componants */
899         /* Floor */
900         c3 = 2 * xsize / 3;
901
902         /* Deep water/lava */
903         c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
904
905         /* Shallow boundary */
906         c2 = (c1 + c3) / 2;
907
908         /* make it */
909         generate_hmap(floor_ptr, y0, x0, xsize, ysize, grd, roug, c3);
910
911         /* Convert to normal format+ clean up */
912         done = generate_lake(player_ptr, y0, x0, xsize, ysize, c1, c2, c3, type);
913     }
914
915     /* Set icky flag because is a vault */
916     for (x = 0; x <= xsize; x++) {
917         for (y = 0; y <= ysize; y++) {
918             floor_ptr->grid_array[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
919         }
920     }
921
922     /* make a few rooms in the vault */
923     for (i = 1; i <= (xsize * ysize) / 50; i++) {
924         build_small_room(player_ptr, x0 + randint0(xsize - 4) - xsize / 2 + 2, y0 + randint0(ysize - 4) - ysize / 2 + 2);
925     }
926
927     /* Fill with monsters and treasure, low difficulty */
928     fill_treasure(player_ptr, x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
929 }
930
931 /* Build a "mini" checkerboard vault
932  *
933  * This is done by making a permanent wall maze and setting
934  * the diagonal sqaures of the checker board to be granite.
935  * The vault has two entrances on opposite sides to guarantee
936  * a way to get in even if the vault abuts a side of the dungeon.
937  */
938 static void build_mini_c_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize)
939 {
940     POSITION dy, dx;
941     POSITION y1, x1, y2, x2, y, x, total;
942     int m, n, num_vertices;
943     int *visited;
944
945     msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("小型チェッカーランダムVaultを生成しました。", "Mini Checker Board Vault."));
946
947     /* Pick a random room size */
948     dy = ysize / 2 - 1;
949     dx = xsize / 2 - 1;
950
951     y1 = y0 - dy;
952     x1 = x0 - dx;
953     y2 = y0 + dy;
954     x2 = x0 + dx;
955
956     /* generate the room */
957     floor_type *floor_ptr = player_ptr->current_floor_ptr;
958     for (x = x1 - 2; x <= x2 + 2; x++) {
959         if (!in_bounds(floor_ptr, y1 - 2, x))
960             break;
961
962         floor_ptr->grid_array[y1 - 2][x].info |= (CAVE_ROOM | CAVE_ICKY);
963
964         place_bold(player_ptr, y1 - 2, x, GB_OUTER_NOPERM);
965     }
966
967     for (x = x1 - 2; x <= x2 + 2; x++) {
968         if (!in_bounds(floor_ptr, y2 + 2, x))
969             break;
970
971         floor_ptr->grid_array[y2 + 2][x].info |= (CAVE_ROOM | CAVE_ICKY);
972
973         place_bold(player_ptr, y2 + 2, x, GB_OUTER_NOPERM);
974     }
975
976     for (y = y1 - 2; y <= y2 + 2; y++) {
977         if (!in_bounds(floor_ptr, y, x1 - 2))
978             break;
979
980         floor_ptr->grid_array[y][x1 - 2].info |= (CAVE_ROOM | CAVE_ICKY);
981
982         place_bold(player_ptr, y, x1 - 2, GB_OUTER_NOPERM);
983     }
984
985     for (y = y1 - 2; y <= y2 + 2; y++) {
986         if (!in_bounds(floor_ptr, y, x2 + 2))
987             break;
988
989         floor_ptr->grid_array[y][x2 + 2].info |= (CAVE_ROOM | CAVE_ICKY);
990
991         place_bold(player_ptr, y, x2 + 2, GB_OUTER_NOPERM);
992     }
993
994     for (y = y1 - 1; y <= y2 + 1; y++) {
995         for (x = x1 - 1; x <= x2 + 1; x++) {
996             grid_type *g_ptr = &floor_ptr->grid_array[y][x];
997
998             g_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
999
1000             /* Permanent walls */
1001             place_grid(player_ptr, g_ptr, GB_INNER_PERM);
1002         }
1003     }
1004
1005     /* dimensions of vertex array */
1006     m = dx + 1;
1007     n = dy + 1;
1008     num_vertices = m * n;
1009
1010     /* initialize array of visited vertices */
1011     C_MAKE(visited, num_vertices, int);
1012
1013     /* traverse the graph to create a spannng tree, pick a random root */
1014     r_visit(player_ptr, y1, x1, y2, x2, randint0(num_vertices), 0, visited);
1015
1016     /* Make it look like a checker board vault */
1017     for (x = x1; x <= x2; x++) {
1018         for (y = y1; y <= y2; y++) {
1019             total = x - x1 + y - y1;
1020             /* If total is odd- and is a floor then make a wall */
1021             if ((total % 2 == 1) && is_floor_bold(floor_ptr, y, x)) {
1022                 place_bold(player_ptr, y, x, GB_INNER);
1023             }
1024         }
1025     }
1026
1027     /* Make a couple of entrances */
1028     if (one_in_(2)) {
1029         /* left and right */
1030         y = randint1(dy) + dy / 2;
1031         place_bold(player_ptr, y1 + y, x1 - 1, GB_INNER);
1032         place_bold(player_ptr, y1 + y, x2 + 1, GB_INNER);
1033     } else {
1034         /* top and bottom */
1035         x = randint1(dx) + dx / 2;
1036         place_bold(player_ptr, y1 - 1, x1 + x, GB_INNER);
1037         place_bold(player_ptr, y2 + 1, x1 + x, GB_INNER);
1038     }
1039
1040     /* Fill with monsters and treasure, highest difficulty */
1041     fill_treasure(player_ptr, x1, x2, y1, y2, 10);
1042
1043     C_KILL(visited, num_vertices, int);
1044 }
1045
1046 /* Build a castle */
1047 /* Driver routine: clear the region and call the recursive
1048  * room routine.
1049  *
1050  *This makes a vault that looks like a castle/ city in the dungeon.
1051  */
1052 static void build_castle_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize)
1053 {
1054     POSITION dy, dx;
1055     POSITION y1, x1, y2, x2;
1056     POSITION y, x;
1057
1058     /* Pick a random room size */
1059     dy = ysize / 2 - 1;
1060     dx = xsize / 2 - 1;
1061
1062     y1 = y0 - dy;
1063     x1 = x0 - dx;
1064     y2 = y0 + dy;
1065     x2 = x0 + dx;
1066
1067     msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("城型ランダムVaultを生成しました。", "Castle Vault"));
1068
1069     /* generate the room */
1070     floor_type *floor_ptr = player_ptr->current_floor_ptr;
1071     for (y = y1 - 1; y <= y2 + 1; y++) {
1072         for (x = x1 - 1; x <= x2 + 1; x++) {
1073             floor_ptr->grid_array[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
1074             /* Make everything a floor */
1075             place_bold(player_ptr, y, x, GB_FLOOR);
1076         }
1077     }
1078
1079     /* Make the castle */
1080     build_recursive_room(player_ptr, x1, y1, x2, y2, randint1(5));
1081
1082     /* Fill with monsters and treasure, low difficulty */
1083     fill_treasure(player_ptr, x1, x2, y1, y2, randint1(3));
1084 }
1085
1086 /*!
1087  * @brief タイプ10の部屋…ランダム生成vault / Type 10 -- Random vaults
1088  * @param player_ptr プレーヤーへの参照ポインタ
1089  * @return なし
1090  */
1091 bool build_type10(player_type *player_ptr, dun_data_type *dd_ptr)
1092 {
1093     POSITION y0, x0, xsize, ysize, vtype;
1094
1095     /* big enough to look good, small enough to be fairly common. */
1096     xsize = randint1(22) + 22;
1097     ysize = randint1(11) + 11;
1098
1099     /* Find and reserve some space in the dungeon.  Get center of room. */
1100     floor_type *floor_ptr = player_ptr->current_floor_ptr;
1101     if (!find_space(player_ptr, dd_ptr, &y0, &x0, ysize + 1, xsize + 1))
1102         return FALSE;
1103
1104     /* Select type of vault */
1105     do {
1106         vtype = randint1(15);
1107     } while ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) && ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11)));
1108
1109     switch (vtype) {
1110         /* Build an appropriate room */
1111     case 1:
1112     case 9:
1113         build_bubble_vault(player_ptr, x0, y0, xsize, ysize);
1114         break;
1115     case 2:
1116     case 10:
1117         build_room_vault(player_ptr, x0, y0, xsize, ysize);
1118         break;
1119     case 3:
1120     case 11:
1121         build_cave_vault(player_ptr, x0, y0, xsize, ysize);
1122         break;
1123     case 4:
1124     case 12:
1125         build_maze_vault(player_ptr, x0, y0, xsize, ysize, TRUE);
1126         break;
1127     case 5:
1128     case 13:
1129         build_mini_c_vault(player_ptr, x0, y0, xsize, ysize);
1130         break;
1131     case 6:
1132     case 14:
1133         build_castle_vault(player_ptr, x0, y0, xsize, ysize);
1134         break;
1135     case 7:
1136     case 15:
1137         build_target_vault(player_ptr, x0, y0, xsize, ysize);
1138         break;
1139     case 8:
1140         build_elemental_vault(player_ptr, x0, y0, xsize, ysize);
1141         break;
1142         /* I know how to add a few more... give me some time. */
1143     default:
1144         return FALSE;
1145     }
1146
1147     return TRUE;
1148 }
1149
1150 /*!
1151  * @brief タイプ17の部屋…v_info.txtより固定特殊部屋を生成する / Type 17 -- fixed special room (see "v_info.txt")
1152  * @return なし
1153  */
1154 bool build_type17(player_type *player_ptr, dun_data_type *dd_ptr)
1155 {
1156     vault_type *v_ptr = NULL;
1157     int dummy;
1158     POSITION x, y;
1159     POSITION xval, yval;
1160     POSITION xoffset, yoffset;
1161     int transno;
1162
1163     /* Pick a lesser vault */
1164     for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++) {
1165         /* Access a random vault record */
1166         v_ptr = &v_info[randint0(max_v_idx)];
1167
1168         /* Accept the special fix room. */
1169         if (v_ptr->typ == 17)
1170             break;
1171     }
1172
1173     /* No lesser vault found */
1174     if (dummy >= SAFE_MAX_ATTEMPTS) {
1175         msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("固定特殊部屋を配置できませんでした。", "Could not place fixed special room."));
1176         return FALSE;
1177     }
1178
1179     /* pick type of transformation (0-7) */
1180     transno = randint0(8);
1181
1182     /* calculate offsets */
1183     x = v_ptr->wid;
1184     y = v_ptr->hgt;
1185
1186     /* Some huge vault cannot be ratated to fit in the dungeon */
1187     floor_type *floor_ptr = player_ptr->current_floor_ptr;
1188     if (x + 2 > floor_ptr->height - 2) {
1189         /* Forbid 90 or 270 degree ratation */
1190         transno &= ~1;
1191     }
1192
1193     coord_trans(&x, &y, 0, 0, transno);
1194
1195     if (x < 0) {
1196         xoffset = -x - 1;
1197     } else {
1198         xoffset = 0;
1199     }
1200
1201     if (y < 0) {
1202         yoffset = -y - 1;
1203     } else {
1204         yoffset = 0;
1205     }
1206
1207     /* Find and reserve some space in the dungeon.  Get center of room. */
1208     if (!find_space(player_ptr, dd_ptr, &yval, &xval, abs(y), abs(x)))
1209         return FALSE;
1210
1211     msg_format_wizard(player_ptr, CHEAT_DUNGEON, _("特殊固定部屋(%s)を生成しました。", "Special Fix room (%s)."), v_name + v_ptr->name);
1212
1213     /* Hack -- Build the vault */
1214     build_vault(player_ptr, yval, xval, v_ptr->hgt, v_ptr->wid, v_text + v_ptr->text, xoffset, yoffset, transno);
1215
1216     return TRUE;
1217 }