OSDN Git Service

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