OSDN Git Service

[Refactor] #37353 generate.h を floor-generate.hへ統合。
[hengband/hengband.git] / src / rooms-pitnest.c
1 #include "angband.h"
2 #include "grid.h"
3 #include "floor-generate.h"
4 #include "rooms.h"
5 #include "rooms-pitnest.h"
6 #include "monster.h"
7 #include "monsterrace-hook.h"
8 #include "sort.h"
9 #include "floor.h"
10
11
12
13 #define NUM_NEST_MON_TYPE 64 /*!<nestの種別数 */
14
15 /*! pit/nest型情報のtypedef */
16 typedef struct vault_aux_type vault_aux_type;
17
18 /*! pit/nest型情報の構造体定義 */
19 struct vault_aux_type
20 {
21         concptr name;
22         bool(*hook_func)(MONRACE_IDX r_idx);
23         void(*prep_func)(void);
24         DEPTH level;
25         int chance;
26 };
27
28 /*! nestのID定義 /  Nest types code */
29 #define NEST_TYPE_CLONE        0
30 #define NEST_TYPE_JELLY        1
31 #define NEST_TYPE_SYMBOL_GOOD  2
32 #define NEST_TYPE_SYMBOL_EVIL  3
33 #define NEST_TYPE_MIMIC        4
34 #define NEST_TYPE_LOVECRAFTIAN 5
35 #define NEST_TYPE_KENNEL       6
36 #define NEST_TYPE_ANIMAL       7
37 #define NEST_TYPE_CHAPEL       8
38 #define NEST_TYPE_UNDEAD       9
39
40 /*! pitのID定義 / Pit types code */
41 #define PIT_TYPE_ORC           0
42 #define PIT_TYPE_TROLL         1
43 #define PIT_TYPE_GIANT         2
44 #define PIT_TYPE_LOVECRAFTIAN  3
45 #define PIT_TYPE_SYMBOL_GOOD   4
46 #define PIT_TYPE_SYMBOL_EVIL   5
47 #define PIT_TYPE_CHAPEL        6
48 #define PIT_TYPE_DRAGON        7
49 #define PIT_TYPE_DEMON         8
50 #define PIT_TYPE_DARK_ELF      9
51
52
53 /*!
54 * @brief ダンジョン毎に指定されたピット配列を基準にランダムなpit/nestタイプを決める
55 * @param l_ptr 選択されたpit/nest情報を返す参照ポインタ
56 * @param allow_flag_mask 生成が許されるpit/nestのビット配列
57 * @return 選択されたpit/nestのID、選択失敗した場合-1を返す。
58 */
59 static int pick_vault_type(vault_aux_type *l_ptr, BIT_FLAGS16 allow_flag_mask)
60 {
61         int tmp, total, count;
62
63         vault_aux_type *n_ptr;
64
65         /* Calculate the total possibilities */
66         for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
67         {
68                 /* Note end */
69                 if (!n_ptr->name) break;
70
71                 /* Ignore excessive depth */
72                 if (n_ptr->level > current_floor_ptr->dun_level) continue;
73
74                 /* Not matched with pit/nest flag */
75                 if (!(allow_flag_mask & (1L << count))) continue;
76
77                 /* Count this possibility */
78                 total += n_ptr->chance * MAX_DEPTH / (MIN(current_floor_ptr->dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
79         }
80
81         /* Pick a random type */
82         tmp = randint0(total);
83
84         /* Find this type */
85         for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
86         {
87                 /* Note end */
88                 if (!n_ptr->name) break;
89
90                 /* Ignore excessive depth */
91                 if (n_ptr->level > current_floor_ptr->dun_level) continue;
92
93                 /* Not matched with pit/nest flag */
94                 if (!(allow_flag_mask & (1L << count))) continue;
95
96                 /* Count this possibility */
97                 total += n_ptr->chance * MAX_DEPTH / (MIN(current_floor_ptr->dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
98
99                 /* Found the type */
100                 if (tmp < total) break;
101         }
102
103         return n_ptr->name ? count : -1;
104 }
105
106 /*!
107 * @brief デバッグ時に生成されたpit/nestの型を出力する処理
108 * @param type pit/nestの型ID
109 * @param nest TRUEならばnest、FALSEならばpit
110 * @return デバッグ表示文字列の参照ポインタ
111 * @details
112 * Hack -- Get the string describing subtype of pit/nest
113 * Determined in prepare function (some pit/nest only)
114 */
115 static concptr pit_subtype_string(int type, bool nest)
116 {
117         static char inner_buf[256] = "";
118
119         inner_buf[0] = '\0'; /* Init string */
120
121         if (nest) /* Nests */
122         {
123                 switch (type)
124                 {
125                 case NEST_TYPE_CLONE:
126                         sprintf(inner_buf, "(%s)", r_name + r_info[vault_aux_race].name);
127                         break;
128                 case NEST_TYPE_SYMBOL_GOOD:
129                 case NEST_TYPE_SYMBOL_EVIL:
130                         sprintf(inner_buf, "(%c)", vault_aux_char);
131                         break;
132                 }
133         }
134         else /* Pits */
135         {
136                 switch (type)
137                 {
138                 case PIT_TYPE_SYMBOL_GOOD:
139                 case PIT_TYPE_SYMBOL_EVIL:
140                         sprintf(inner_buf, "(%c)", vault_aux_char);
141                         break;
142                 case PIT_TYPE_DRAGON:
143                         switch (vault_aux_dragon_mask4)
144                         {
145                         case RF4_BR_ACID: strcpy(inner_buf, _("(酸)", "(acid)"));   break;
146                         case RF4_BR_ELEC: strcpy(inner_buf, _("(稲妻)", "(lightning)")); break;
147                         case RF4_BR_FIRE: strcpy(inner_buf, _("(火炎)", "(fire)")); break;
148                         case RF4_BR_COLD: strcpy(inner_buf, _("(冷気)", "(frost)")); break;
149                         case RF4_BR_POIS: strcpy(inner_buf, _("(毒)", "(poison)"));   break;
150                         case (RF4_BR_ACID | RF4_BR_ELEC | RF4_BR_FIRE | RF4_BR_COLD | RF4_BR_POIS) :
151                                 strcpy(inner_buf, _("(万色)", "(multi-hued)")); break;
152                         default: strcpy(inner_buf, _("(未定義)", "(undefined)")); break;
153                         }
154                         break;
155                 }
156         }
157
158         return inner_buf;
159 }
160
161 /*
162 *! @brief nestのモンスターリストをソートするための関数 /
163 *  Comp function for sorting nest monster information
164 *  @param u ソート処理対象配列ポインタ
165 *  @param v 未使用
166 *  @param a 比較対象参照ID1
167 *  @param b 比較対象参照ID2
168 *  TODO: to sort.c
169 */
170 static bool ang_sort_comp_nest_mon_info(vptr u, vptr v, int a, int b)
171 {
172         nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
173         MONSTER_IDX w1 = nest_mon_info[a].r_idx;
174         MONSTER_IDX w2 = nest_mon_info[b].r_idx;
175         monster_race *r1_ptr = &r_info[w1];
176         monster_race *r2_ptr = &r_info[w2];
177         int z1, z2;
178
179         /* Unused */
180         (void)v;
181
182         /* Extract used info */
183         z1 = nest_mon_info[a].used;
184         z2 = nest_mon_info[b].used;
185
186         /* Compare used status */
187         if (z1 < z2) return FALSE;
188         if (z1 > z2) return TRUE;
189
190         /* Compare levels */
191         if (r1_ptr->level < r2_ptr->level) return TRUE;
192         if (r1_ptr->level > r2_ptr->level) return FALSE;
193
194         /* Compare experience */
195         if (r1_ptr->mexp < r2_ptr->mexp) return TRUE;
196         if (r1_ptr->mexp > r2_ptr->mexp) return FALSE;
197
198         /* Compare indexes */
199         return w1 <= w2;
200 }
201
202 /*!
203 * @brief nestのモンスターリストをスワップするための関数 /
204 * Swap function for sorting nest monster information
205 * @param u スワップ処理対象配列ポインタ
206 * @param v 未使用
207 * @param a スワップ対象参照ID1
208 * @param b スワップ対象参照ID2
209 * TODO: to sort.c
210 */
211 static void ang_sort_swap_nest_mon_info(vptr u, vptr v, int a, int b)
212 {
213         nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
214         nest_mon_info_type holder;
215
216         /* Unused */
217         (void)v;
218
219         /* Swap */
220         holder = nest_mon_info[a];
221         nest_mon_info[a] = nest_mon_info[b];
222         nest_mon_info[b] = holder;
223 }
224
225
226
227 /*!nest情報テーブル*/
228 static vault_aux_type nest_types[] =
229 {
230         { _("クローン", "clone"),      vault_aux_clone,    vault_prep_clone,   5, 3 },
231         { _("ゼリー", "jelly"),        vault_aux_jelly,    NULL,               5, 6 },
232         { _("シンボル(善)", "symbol good"), vault_aux_symbol_g, vault_prep_symbol, 25, 2 },
233         { _("シンボル(悪)", "symbol evil"), vault_aux_symbol_e, vault_prep_symbol, 25, 2 },
234         { _("ミミック", "mimic"),      vault_aux_mimic,    NULL,              30, 4 },
235         { _("狂気", "lovecraftian"),   vault_aux_cthulhu,  NULL,              70, 2 },
236         { _("犬小屋", "kennel"),       vault_aux_kennel,   NULL,              45, 4 },
237         { _("動物園", "animal"),       vault_aux_animal,   NULL,              35, 5 },
238         { _("教会", "chapel"),         vault_aux_chapel_g, NULL,              75, 4 },
239         { _("アンデッド", "undead"),   vault_aux_undead,   NULL,              75, 5 },
240         { NULL,           NULL,               NULL,               0, 0 },
241 };
242
243 /*!pit情報テーブル*/
244 static vault_aux_type pit_types[] =
245 {
246         { _("オーク", "orc"),            vault_aux_orc,      NULL,               5, 6 },
247         { _("トロル", "troll"),          vault_aux_troll,    NULL,              20, 6 },
248         { _("ジャイアント", "giant"),    vault_aux_giant,    NULL,              50, 6 },
249         { _("狂気", "lovecraftian"),     vault_aux_cthulhu,  NULL,              80, 2 },
250         { _("シンボル(善)", "symbol good"), vault_aux_symbol_g, vault_prep_symbol, 70, 1 },
251         { _("シンボル(悪)", "symbol evil"), vault_aux_symbol_e, vault_prep_symbol, 70, 1 },
252         { _("教会", "chapel"),           vault_aux_chapel_g, NULL,              65, 2 },
253         { _("ドラゴン", "dragon"),       vault_aux_dragon,   vault_prep_dragon, 70, 6 },
254         { _("デーモン", "demon"),        vault_aux_demon,    NULL,              80, 6 },
255         { _("ダークエルフ", "dark elf"), vault_aux_dark_elf, NULL,              45, 4 },
256         { NULL,           NULL,               NULL,               0, 0 },
257 };
258
259
260
261
262 /*!
263 * @brief タイプ5の部屋…nestを生成する / Type 5 -- Monster nests
264 * @return なし
265 * @details
266 * A monster nest is a "big" room, with an "inner" room, containing\n
267 * a "collection" of monsters of a given type strewn about the room.\n
268 *\n
269 * The monsters are chosen from a set of 64 randomly selected monster\n
270 * races, to allow the nest creation to fail instead of having "holes".\n
271 *\n
272 * Note the use of the "get_mon_num_prep()" function, and the special\n
273 * "get_mon_num_hook()" restriction function, to prepare the "monster\n
274 * allocation table" in such a way as to optimize the selection of\n
275 * "appropriate" non-unique monsters for the nest.\n
276 *\n
277 * Note that the "get_mon_num()" function may (rarely) fail, in which\n
278 * case the nest will be empty.\n
279 *\n
280 * Note that "monster nests" will never contain "unique" monsters.\n
281 */
282 bool build_type5(void)
283 {
284         POSITION y, x, y1, x1, y2, x2, xval, yval;
285         int i;
286         nest_mon_info_type nest_mon_info[NUM_NEST_MON_TYPE];
287
288         monster_type align;
289
290         grid_type *g_ptr;
291
292         int cur_nest_type = pick_vault_type(nest_types, d_info[p_ptr->dungeon_idx].nest);
293         vault_aux_type *n_ptr;
294
295         /* No type available */
296         if (cur_nest_type < 0) return FALSE;
297
298         n_ptr = &nest_types[cur_nest_type];
299
300         /* Process a preparation function if necessary */
301         if (n_ptr->prep_func) (*(n_ptr->prep_func))();
302         get_mon_num_prep(n_ptr->hook_func, NULL);
303
304         align.sub_align = SUB_ALIGN_NEUTRAL;
305
306         /* Pick some monster types */
307         for (i = 0; i < NUM_NEST_MON_TYPE; i++)
308         {
309                 MONRACE_IDX r_idx = 0;
310                 int attempts = 100;
311                 monster_race *r_ptr = NULL;
312
313                 while (attempts--)
314                 {
315                         /* Get a (hard) monster type */
316                         r_idx = get_mon_num(current_floor_ptr->dun_level + 11);
317                         r_ptr = &r_info[r_idx];
318
319                         /* Decline incorrect alignment */
320                         if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
321
322                         /* Accept this monster */
323                         break;
324                 }
325
326                 /* Notice failure */
327                 if (!r_idx || !attempts) return FALSE;
328
329                 /* Note the alignment */
330                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
331                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
332
333                 nest_mon_info[i].r_idx = (s16b)r_idx;
334                 nest_mon_info[i].used = FALSE;
335         }
336
337         /* Find and reserve some space in the dungeon.  Get center of room. */
338         if (!find_space(&yval, &xval, 11, 25)) return FALSE;
339
340         /* Large room */
341         y1 = yval - 4;
342         y2 = yval + 4;
343         x1 = xval - 11;
344         x2 = xval + 11;
345
346         /* Place the floor area */
347         for (y = y1 - 1; y <= y2 + 1; y++)
348         {
349                 for (x = x1 - 1; x <= x2 + 1; x++)
350                 {
351                         g_ptr = &current_floor_ptr->grid_array[y][x];
352                         place_floor_grid(g_ptr);
353                         g_ptr->info |= (CAVE_ROOM);
354                 }
355         }
356
357         /* Place the outer walls */
358         for (y = y1 - 1; y <= y2 + 1; y++)
359         {
360                 g_ptr = &current_floor_ptr->grid_array[y][x1 - 1];
361                 place_outer_grid(g_ptr);
362                 g_ptr = &current_floor_ptr->grid_array[y][x2 + 1];
363                 place_outer_grid(g_ptr);
364         }
365         for (x = x1 - 1; x <= x2 + 1; x++)
366         {
367                 g_ptr = &current_floor_ptr->grid_array[y1 - 1][x];
368                 place_outer_grid(g_ptr);
369                 g_ptr = &current_floor_ptr->grid_array[y2 + 1][x];
370                 place_outer_grid(g_ptr);
371         }
372
373
374         /* Advance to the center room */
375         y1 = y1 + 2;
376         y2 = y2 - 2;
377         x1 = x1 + 2;
378         x2 = x2 - 2;
379
380         /* The inner walls */
381         for (y = y1 - 1; y <= y2 + 1; y++)
382         {
383                 g_ptr = &current_floor_ptr->grid_array[y][x1 - 1];
384                 place_inner_grid(g_ptr);
385                 g_ptr = &current_floor_ptr->grid_array[y][x2 + 1];
386                 place_inner_grid(g_ptr);
387         }
388
389         for (x = x1 - 1; x <= x2 + 1; x++)
390         {
391                 g_ptr = &current_floor_ptr->grid_array[y1 - 1][x];
392                 place_inner_grid(g_ptr);
393                 g_ptr = &current_floor_ptr->grid_array[y2 + 1][x];
394                 place_inner_grid(g_ptr);
395         }
396         for (y = y1; y <= y2; y++)
397         {
398                 for (x = x1; x <= x2; x++)
399                 {
400                         add_cave_info(y, x, CAVE_ICKY);
401                 }
402         }
403
404         /* Place a secret door */
405         switch (randint1(4))
406         {
407         case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
408         case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
409         case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
410         case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
411         }
412
413         msg_format_wizard(CHEAT_DUNGEON, _("モンスター部屋(nest)(%s%s)を生成します。", "Monster nest (%s%s)"), n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
414
415         /* Place some monsters */
416         for (y = yval - 2; y <= yval + 2; y++)
417         {
418                 for (x = xval - 9; x <= xval + 9; x++)
419                 {
420                         MONRACE_IDX r_idx;
421
422                         i = randint0(NUM_NEST_MON_TYPE);
423                         r_idx = nest_mon_info[i].r_idx;
424
425                         /* Place that "random" monster (no groups) */
426                         (void)place_monster_aux(0, y, x, r_idx, 0L);
427
428                         nest_mon_info[i].used = TRUE;
429                 }
430         }
431
432         if (cheat_room)
433         {
434                 ang_sort(nest_mon_info, NULL, NUM_NEST_MON_TYPE, ang_sort_comp_nest_mon_info, ang_sort_swap_nest_mon_info);
435
436                 /* Dump the entries (prevent multi-printing) */
437                 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
438                 {
439                         if (!nest_mon_info[i].used) break;
440                         for (; i < NUM_NEST_MON_TYPE - 1; i++)
441                         {
442                                 if (nest_mon_info[i].r_idx != nest_mon_info[i + 1].r_idx) break;
443                                 if (!nest_mon_info[i + 1].used) break;
444                         }
445                         msg_format_wizard(CHEAT_DUNGEON, "Nest構成モンスターNo.%d:%s", i, r_name + r_info[nest_mon_info[i].r_idx].name);
446                 }
447         }
448
449         return TRUE;
450 }
451
452
453 /*!
454 * @brief タイプ6の部屋…pitを生成する / Type 6 -- Monster pits
455 * @return なし
456 * @details
457 * A monster pit is a "big" room, with an "inner" room, containing\n
458 * a "collection" of monsters of a given type organized in the room.\n
459 *\n
460 * The inside room in a monster pit appears as shown below, where the\n
461 * actual monsters in each location depend on the type of the pit\n
462 *\n
463 *   XXXXXXXXXXXXXXXXXXXXX\n
464 *   X0000000000000000000X\n
465 *   X0112233455543322110X\n
466 *   X0112233467643322110X\n
467 *   X0112233455543322110X\n
468 *   X0000000000000000000X\n
469 *   XXXXXXXXXXXXXXXXXXXXX\n
470 *\n
471 * Note that the monsters in the pit are now chosen by using "get_mon_num()"\n
472 * to request 16 "appropriate" monsters, sorting them by level, and using\n
473 * the "even" entries in this sorted list for the contents of the pit.\n
474 *\n
475 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",\n
476 * which is handled by requiring a specific "breath" attack for all of the\n
477 * dragons.  This may include "multi-hued" breath.  Note that "wyrms" may\n
478 * be present in many of the dragon pits, if they have the proper breath.\n
479 *\n
480 * Note the use of the "get_mon_num_prep()" function, and the special\n
481 * "get_mon_num_hook()" restriction function, to prepare the "monster\n
482 * allocation table" in such a way as to optimize the selection of\n
483 * "appropriate" non-unique monsters for the pit.\n
484 *\n
485 * Note that the "get_mon_num()" function may (rarely) fail, in which case\n
486 * the pit will be empty.\n
487 *\n
488 * Note that "monster pits" will never contain "unique" monsters.\n
489 */
490 bool build_type6(void)
491 {
492         POSITION y, x, y1, x1, y2, x2, xval, yval;
493         int i, j;
494
495         MONRACE_IDX what[16];
496
497         monster_type align;
498
499         grid_type *g_ptr;
500
501         int cur_pit_type = pick_vault_type(pit_types, d_info[p_ptr->dungeon_idx].pit);
502         vault_aux_type *n_ptr;
503
504         /* No type available */
505         if (cur_pit_type < 0) return FALSE;
506
507         n_ptr = &pit_types[cur_pit_type];
508
509         /* Process a preparation function if necessary */
510         if (n_ptr->prep_func) (*(n_ptr->prep_func))();
511         get_mon_num_prep(n_ptr->hook_func, NULL);
512
513         align.sub_align = SUB_ALIGN_NEUTRAL;
514
515         /* Pick some monster types */
516         for (i = 0; i < 16; i++)
517         {
518                 MONRACE_IDX r_idx = 0;
519                 int attempts = 100;
520                 monster_race *r_ptr = NULL;
521
522                 while (attempts--)
523                 {
524                         /* Get a (hard) monster type */
525                         r_idx = get_mon_num(current_floor_ptr->dun_level + 11);
526                         r_ptr = &r_info[r_idx];
527
528                         /* Decline incorrect alignment */
529                         if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
530
531                         /* Accept this monster */
532                         break;
533                 }
534
535                 /* Notice failure */
536                 if (!r_idx || !attempts) return FALSE;
537
538                 /* Note the alignment */
539                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
540                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
541
542                 what[i] = r_idx;
543         }
544
545         /* Find and reserve some space in the dungeon.  Get center of room. */
546         if (!find_space(&yval, &xval, 11, 25)) return FALSE;
547
548         /* Large room */
549         y1 = yval - 4;
550         y2 = yval + 4;
551         x1 = xval - 11;
552         x2 = xval + 11;
553
554         /* Place the floor area */
555         for (y = y1 - 1; y <= y2 + 1; y++)
556         {
557                 for (x = x1 - 1; x <= x2 + 1; x++)
558                 {
559                         g_ptr = &current_floor_ptr->grid_array[y][x];
560                         place_floor_grid(g_ptr);
561                         g_ptr->info |= (CAVE_ROOM);
562                 }
563         }
564
565         /* Place the outer walls */
566         for (y = y1 - 1; y <= y2 + 1; y++)
567         {
568                 g_ptr = &current_floor_ptr->grid_array[y][x1 - 1];
569                 place_outer_grid(g_ptr);
570                 g_ptr = &current_floor_ptr->grid_array[y][x2 + 1];
571                 place_outer_grid(g_ptr);
572         }
573         for (x = x1 - 1; x <= x2 + 1; x++)
574         {
575                 g_ptr = &current_floor_ptr->grid_array[y1 - 1][x];
576                 place_outer_grid(g_ptr);
577                 g_ptr = &current_floor_ptr->grid_array[y2 + 1][x];
578                 place_outer_grid(g_ptr);
579         }
580
581         /* Advance to the center room */
582         y1 = y1 + 2;
583         y2 = y2 - 2;
584         x1 = x1 + 2;
585         x2 = x2 - 2;
586
587         /* The inner walls */
588         for (y = y1 - 1; y <= y2 + 1; y++)
589         {
590                 g_ptr = &current_floor_ptr->grid_array[y][x1 - 1];
591                 place_inner_grid(g_ptr);
592                 g_ptr = &current_floor_ptr->grid_array[y][x2 + 1];
593                 place_inner_grid(g_ptr);
594         }
595         for (x = x1 - 1; x <= x2 + 1; x++)
596         {
597                 g_ptr = &current_floor_ptr->grid_array[y1 - 1][x];
598                 place_inner_grid(g_ptr);
599                 g_ptr = &current_floor_ptr->grid_array[y2 + 1][x];
600                 place_inner_grid(g_ptr);
601         }
602         for (y = y1; y <= y2; y++)
603         {
604                 for (x = x1; x <= x2; x++)
605                 {
606                         add_cave_info(y, x, CAVE_ICKY);
607                 }
608         }
609
610         /* Place a secret door */
611         switch (randint1(4))
612         {
613         case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
614         case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
615         case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
616         case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
617         }
618
619         /* Sort the entries */
620         for (i = 0; i < 16 - 1; i++)
621         {
622                 /* Sort the entries */
623                 for (j = 0; j < 16 - 1; j++)
624                 {
625                         int i1 = j;
626                         int i2 = j + 1;
627
628                         int p1 = r_info[what[i1]].level;
629                         int p2 = r_info[what[i2]].level;
630
631                         /* Bubble */
632                         if (p1 > p2)
633                         {
634                                 MONRACE_IDX tmp = what[i1];
635                                 what[i1] = what[i2];
636                                 what[i2] = tmp;
637                         }
638                 }
639         }
640
641         msg_format_wizard(CHEAT_DUNGEON, _("モンスター部屋(pit)(%s%s)を生成します。", "Monster pit (%s%s)"), n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
642
643         /* Select the entries */
644         for (i = 0; i < 8; i++)
645         {
646                 /* Every other entry */
647                 what[i] = what[i * 2];
648                 msg_format_wizard(CHEAT_DUNGEON, _("Nest構成モンスター選択No.%d:%s", "Nest Monster Select No.%d:%s"), i, r_name + r_info[what[i]].name);
649         }
650
651         /* Top and bottom rows */
652         for (x = xval - 9; x <= xval + 9; x++)
653         {
654                 place_monster_aux(0, yval - 2, x, what[0], PM_NO_KAGE);
655                 place_monster_aux(0, yval + 2, x, what[0], PM_NO_KAGE);
656         }
657
658         /* Middle columns */
659         for (y = yval - 1; y <= yval + 1; y++)
660         {
661                 place_monster_aux(0, y, xval - 9, what[0], PM_NO_KAGE);
662                 place_monster_aux(0, y, xval + 9, what[0], PM_NO_KAGE);
663
664                 place_monster_aux(0, y, xval - 8, what[1], PM_NO_KAGE);
665                 place_monster_aux(0, y, xval + 8, what[1], PM_NO_KAGE);
666
667                 place_monster_aux(0, y, xval - 7, what[1], PM_NO_KAGE);
668                 place_monster_aux(0, y, xval + 7, what[1], PM_NO_KAGE);
669
670                 place_monster_aux(0, y, xval - 6, what[2], PM_NO_KAGE);
671                 place_monster_aux(0, y, xval + 6, what[2], PM_NO_KAGE);
672
673                 place_monster_aux(0, y, xval - 5, what[2], PM_NO_KAGE);
674                 place_monster_aux(0, y, xval + 5, what[2], PM_NO_KAGE);
675
676                 place_monster_aux(0, y, xval - 4, what[3], PM_NO_KAGE);
677                 place_monster_aux(0, y, xval + 4, what[3], PM_NO_KAGE);
678
679                 place_monster_aux(0, y, xval - 3, what[3], PM_NO_KAGE);
680                 place_monster_aux(0, y, xval + 3, what[3], PM_NO_KAGE);
681
682                 place_monster_aux(0, y, xval - 2, what[4], PM_NO_KAGE);
683                 place_monster_aux(0, y, xval + 2, what[4], PM_NO_KAGE);
684         }
685
686         /* Above/Below the center monster */
687         for (x = xval - 1; x <= xval + 1; x++)
688         {
689                 place_monster_aux(0, yval + 1, x, what[5], PM_NO_KAGE);
690                 place_monster_aux(0, yval - 1, x, what[5], PM_NO_KAGE);
691         }
692
693         /* Next to the center monster */
694         place_monster_aux(0, yval, xval + 1, what[6], PM_NO_KAGE);
695         place_monster_aux(0, yval, xval - 1, what[6], PM_NO_KAGE);
696
697         /* Center monster */
698         place_monster_aux(0, yval, xval, what[7], PM_NO_KAGE);
699
700         return TRUE;
701 }
702
703
704
705 /*
706 * Helper function for "trapped monster pit"
707 */
708 static bool vault_aux_trapped_pit(MONRACE_IDX r_idx)
709 {
710         monster_race *r_ptr = &r_info[r_idx];
711
712         if (!vault_monster_okay(r_idx)) return (FALSE);
713
714         /* No wall passing monster */
715         if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return (FALSE);
716
717         return (TRUE);
718 }
719
720
721 /*!
722 * @brief タイプ13の部屋…トラップpitの生成 / Type 13 -- Trapped monster pits
723 * @return なし
724 * @details
725 * A trapped monster pit is a "big" room with a straight corridor in\n
726 * which wall opening traps are placed, and with two "inner" rooms\n
727 * containing a "collection" of monsters of a given type organized in\n
728 * the room.\n
729 *\n
730 * The trapped monster pit appears as shown below, where the actual\n
731 * monsters in each location depend on the type of the pit\n
732 *\n
733 *  XXXXXXXXXXXXXXXXXXXXXXXXX\n
734 *  X                       X\n
735 *  XXXXXXXXXXXXXXXXXXXXXXX X\n
736 *  XXXXX001123454321100XXX X\n
737 *  XXX0012234567654322100X X\n
738 *  XXXXXXXXXXXXXXXXXXXXXXX X\n
739 *  X           ^           X\n
740 *  X XXXXXXXXXXXXXXXXXXXXXXX\n
741 *  X X0012234567654322100XXX\n
742 *  X XXX001123454321100XXXXX\n
743 *  X XXXXXXXXXXXXXXXXXXXXXXX\n
744 *  X                       X\n
745 *  XXXXXXXXXXXXXXXXXXXXXXXXX\n
746 *\n
747 * Note that the monsters in the pit are now chosen by using "get_mon_num()"\n
748 * to request 16 "appropriate" monsters, sorting them by level, and using\n
749 * the "even" entries in this sorted list for the contents of the pit.\n
750 *\n
751 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",\n
752 * which is handled by requiring a specific "breath" attack for all of the\n
753 * dragons.  This may include "multi-hued" breath.  Note that "wyrms" may\n
754 * be present in many of the dragon pits, if they have the proper breath.\n
755 *\n
756 * Note the use of the "get_mon_num_prep()" function, and the special\n
757 * "get_mon_num_hook()" restriction function, to prepare the "monster\n
758 * allocation table" in such a way as to optimize the selection of\n
759 * "appropriate" non-unique monsters for the pit.\n
760 *\n
761 * Note that the "get_mon_num()" function may (rarely) fail, in which case\n
762 * the pit will be empty.\n
763 *\n
764 * Note that "monster pits" will never contain "unique" monsters.\n
765 */
766 bool build_type13(void)
767 {
768         static int placing[][3] = {
769                 { -2, -9, 0 },{ -2, -8, 0 },{ -3, -7, 0 },{ -3, -6, 0 },
770                 { +2, -9, 0 },{ +2, -8, 0 },{ +3, -7, 0 },{ +3, -6, 0 },
771                 { -2, +9, 0 },{ -2, +8, 0 },{ -3, +7, 0 },{ -3, +6, 0 },
772                 { +2, +9, 0 },{ +2, +8, 0 },{ +3, +7, 0 },{ +3, +6, 0 },
773                 { -2, -7, 1 },{ -3, -5, 1 },{ -3, -4, 1 },
774                 { +2, -7, 1 },{ +3, -5, 1 },{ +3, -4, 1 },
775                 { -2, +7, 1 },{ -3, +5, 1 },{ -3, +4, 1 },
776                 { +2, +7, 1 },{ +3, +5, 1 },{ +3, +4, 1 },
777                 { -2, -6, 2 },{ -2, -5, 2 },{ -3, -3, 2 },
778                 { +2, -6, 2 },{ +2, -5, 2 },{ +3, -3, 2 },
779                 { -2, +6, 2 },{ -2, +5, 2 },{ -3, +3, 2 },
780                 { +2, +6, 2 },{ +2, +5, 2 },{ +3, +3, 2 },
781                 { -2, -4, 3 },{ -3, -2, 3 },
782                 { +2, -4, 3 },{ +3, -2, 3 },
783                 { -2, +4, 3 },{ -3, +2, 3 },
784                 { +2, +4, 3 },{ +3, +2, 3 },
785                 { -2, -3, 4 },{ -3, -1, 4 },
786                 { +2, -3, 4 },{ +3, -1, 4 },
787                 { -2, +3, 4 },{ -3, +1, 4 },
788                 { +2, +3, 4 },{ +3, +1, 4 },
789                 { -2, -2, 5 },{ -3, 0, 5 },{ -2, +2, 5 },
790                 { +2, -2, 5 },{ +3, 0, 5 },{ +2, +2, 5 },
791                 { -2, -1, 6 },{ -2, +1, 6 },
792                 { +2, -1, 6 },{ +2, +1, 6 },
793                 { -2, 0, 7 },{ +2, 0, 7 },
794                 { 0, 0, -1 }
795         };
796
797         POSITION y, x, y1, x1, y2, x2, xval, yval;
798         int i, j;
799
800         MONRACE_IDX what[16];
801
802         monster_type align;
803
804         grid_type *g_ptr;
805
806         int cur_pit_type = pick_vault_type(pit_types, d_info[p_ptr->dungeon_idx].pit);
807         vault_aux_type *n_ptr;
808
809         /* Only in Angband */
810         if (p_ptr->dungeon_idx != DUNGEON_ANGBAND) return FALSE;
811
812         /* No type available */
813         if (cur_pit_type < 0) return FALSE;
814
815         n_ptr = &pit_types[cur_pit_type];
816
817         /* Process a preparation function if necessary */
818         if (n_ptr->prep_func) (*(n_ptr->prep_func))();
819         get_mon_num_prep(n_ptr->hook_func, vault_aux_trapped_pit);
820
821         align.sub_align = SUB_ALIGN_NEUTRAL;
822
823         /* Pick some monster types */
824         for (i = 0; i < 16; i++)
825         {
826                 MONRACE_IDX r_idx = 0;
827                 int attempts = 100;
828                 monster_race *r_ptr = NULL;
829
830                 while (attempts--)
831                 {
832                         /* Get a (hard) monster type */
833                         r_idx = get_mon_num(current_floor_ptr->dun_level + 0);
834                         r_ptr = &r_info[r_idx];
835
836                         /* Decline incorrect alignment */
837                         if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
838
839                         /* Accept this monster */
840                         break;
841                 }
842
843                 /* Notice failure */
844                 if (!r_idx || !attempts) return FALSE;
845
846                 /* Note the alignment */
847                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
848                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
849
850                 what[i] = r_idx;
851         }
852
853         /* Find and reserve some space in the dungeon.  Get center of room. */
854         if (!find_space(&yval, &xval, 13, 25)) return FALSE;
855
856         /* Large room */
857         y1 = yval - 5;
858         y2 = yval + 5;
859         x1 = xval - 11;
860         x2 = xval + 11;
861
862         /* Fill with inner walls */
863         for (y = y1 - 1; y <= y2 + 1; y++)
864         {
865                 for (x = x1 - 1; x <= x2 + 1; x++)
866                 {
867                         g_ptr = &current_floor_ptr->grid_array[y][x];
868                         place_inner_grid(g_ptr);
869                         g_ptr->info |= (CAVE_ROOM);
870                 }
871         }
872
873         /* Place the floor area 1 */
874         for (x = x1 + 3; x <= x2 - 3; x++)
875         {
876                 g_ptr = &current_floor_ptr->grid_array[yval - 2][x];
877                 place_floor_grid(g_ptr);
878                 add_cave_info(yval - 2, x, CAVE_ICKY);
879
880                 g_ptr = &current_floor_ptr->grid_array[yval + 2][x];
881                 place_floor_grid(g_ptr);
882                 add_cave_info(yval + 2, x, CAVE_ICKY);
883         }
884
885         /* Place the floor area 2 */
886         for (x = x1 + 5; x <= x2 - 5; x++)
887         {
888                 g_ptr = &current_floor_ptr->grid_array[yval - 3][x];
889                 place_floor_grid(g_ptr);
890                 add_cave_info(yval - 3, x, CAVE_ICKY);
891
892                 g_ptr = &current_floor_ptr->grid_array[yval + 3][x];
893                 place_floor_grid(g_ptr);
894                 add_cave_info(yval + 3, x, CAVE_ICKY);
895         }
896
897         /* Corridor */
898         for (x = x1; x <= x2; x++)
899         {
900                 g_ptr = &current_floor_ptr->grid_array[yval][x];
901                 place_floor_grid(g_ptr);
902                 g_ptr = &current_floor_ptr->grid_array[y1][x];
903                 place_floor_grid(g_ptr);
904                 g_ptr = &current_floor_ptr->grid_array[y2][x];
905                 place_floor_grid(g_ptr);
906         }
907
908         /* Place the outer walls */
909         for (y = y1 - 1; y <= y2 + 1; y++)
910         {
911                 g_ptr = &current_floor_ptr->grid_array[y][x1 - 1];
912                 place_outer_grid(g_ptr);
913                 g_ptr = &current_floor_ptr->grid_array[y][x2 + 1];
914                 place_outer_grid(g_ptr);
915         }
916         for (x = x1 - 1; x <= x2 + 1; x++)
917         {
918                 g_ptr = &current_floor_ptr->grid_array[y1 - 1][x];
919                 place_outer_grid(g_ptr);
920                 g_ptr = &current_floor_ptr->grid_array[y2 + 1][x];
921                 place_outer_grid(g_ptr);
922         }
923
924         /* Random corridor */
925         if (one_in_(2))
926         {
927                 for (y = y1; y <= yval; y++)
928                 {
929                         place_floor_bold(y, x2);
930                         place_solid_bold(y, x1 - 1);
931                 }
932                 for (y = yval; y <= y2 + 1; y++)
933                 {
934                         place_floor_bold(y, x1);
935                         place_solid_bold(y, x2 + 1);
936                 }
937         }
938         else
939         {
940                 for (y = yval; y <= y2 + 1; y++)
941                 {
942                         place_floor_bold(y, x1);
943                         place_solid_bold(y, x2 + 1);
944                 }
945                 for (y = y1; y <= yval; y++)
946                 {
947                         place_floor_bold(y, x2);
948                         place_solid_bold(y, x1 - 1);
949                 }
950         }
951
952         /* Place the wall open trap */
953         current_floor_ptr->grid_array[yval][xval].mimic = current_floor_ptr->grid_array[yval][xval].feat;
954         current_floor_ptr->grid_array[yval][xval].feat = feat_trap_open;
955
956         /* Sort the entries */
957         for (i = 0; i < 16 - 1; i++)
958         {
959                 /* Sort the entries */
960                 for (j = 0; j < 16 - 1; j++)
961                 {
962                         int i1 = j;
963                         int i2 = j + 1;
964
965                         int p1 = r_info[what[i1]].level;
966                         int p2 = r_info[what[i2]].level;
967
968                         /* Bubble */
969                         if (p1 > p2)
970                         {
971                                 MONRACE_IDX tmp = what[i1];
972                                 what[i1] = what[i2];
973                                 what[i2] = tmp;
974                         }
975                 }
976         }
977
978         msg_format_wizard(CHEAT_DUNGEON, _("%s%sの罠ピットが生成されました。", "Trapped monster pit (%s%s)"),
979                 n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
980
981         /* Select the entries */
982         for (i = 0; i < 8; i++)
983         {
984                 /* Every other entry */
985                 what[i] = what[i * 2];
986
987                 if (cheat_hear)
988                 {
989                         msg_print(r_name + r_info[what[i]].name);
990                 }
991         }
992
993         for (i = 0; placing[i][2] >= 0; i++)
994         {
995                 y = yval + placing[i][0];
996                 x = xval + placing[i][1];
997                 place_monster_aux(0, y, x, what[placing[i][2]], PM_NO_KAGE);
998         }
999
1000         return TRUE;
1001 }
1002