OSDN Git Service

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