OSDN Git Service

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