OSDN Git Service

e3507c8d13c6996e0ad709c91cf4202da58c5642
[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(floor_type *floor_ptr, 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 > 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(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 > 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(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 * @param player_ptr プレーヤーへの参照ポインタ
269 * @return なし
270 * @details
271 * A monster nest is a "big" room, with an "inner" room, containing\n
272 * a "collection" of monsters of a given type strewn about the room.\n
273 *\n
274 * The monsters are chosen from a set of 64 randomly selected monster\n
275 * races, to allow the nest creation to fail instead of having "holes".\n
276 *\n
277 * Note the use of the "get_mon_num_prep()" function, and the special\n
278 * "get_mon_num_hook()" restriction function, to prepare the "monster\n
279 * allocation table" in such a way as to optimize the selection of\n
280 * "appropriate" non-unique monsters for the nest.\n
281 *\n
282 * Note that the "get_mon_num()" function may (rarely) fail, in which\n
283 * case the nest will be empty.\n
284 *\n
285 * Note that "monster nests" will never contain "unique" monsters.\n
286 */
287 bool build_type5(player_type *player_ptr)
288 {
289         POSITION y, x, y1, x1, y2, x2, xval, yval;
290         int i;
291         nest_mon_info_type nest_mon_info[NUM_NEST_MON_TYPE];
292
293         monster_type align;
294
295         grid_type *g_ptr;
296
297         floor_type *floor_ptr = player_ptr->current_floor_ptr;
298         int cur_nest_type = pick_vault_type(floor_ptr, nest_types, d_info[floor_ptr->dungeon_idx].nest);
299         vault_aux_type *n_ptr;
300
301         /* No type available */
302         if (cur_nest_type < 0) return FALSE;
303
304         n_ptr = &nest_types[cur_nest_type];
305
306         /* Process a preparation function if necessary */
307         if (n_ptr->prep_func) (*(n_ptr->prep_func))();
308         get_mon_num_prep(n_ptr->hook_func, NULL);
309
310         align.sub_align = SUB_ALIGN_NEUTRAL;
311
312         /* Pick some monster types */
313         for (i = 0; i < NUM_NEST_MON_TYPE; i++)
314         {
315                 MONRACE_IDX r_idx = 0;
316                 int attempts = 100;
317                 monster_race *r_ptr = NULL;
318
319                 while (attempts--)
320                 {
321                         /* Get a (hard) monster type */
322                         r_idx = get_mon_num(floor_ptr->dun_level + 11);
323                         r_ptr = &r_info[r_idx];
324
325                         /* Decline incorrect alignment */
326                         if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
327
328                         /* Accept this monster */
329                         break;
330                 }
331
332                 /* Notice failure */
333                 if (!r_idx || !attempts) return FALSE;
334
335                 /* Note the alignment */
336                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
337                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
338
339                 nest_mon_info[i].r_idx = (s16b)r_idx;
340                 nest_mon_info[i].used = FALSE;
341         }
342
343         /* Find and reserve some space in the dungeon.  Get center of room. */
344         if (!find_space(floor_ptr, &yval, &xval, 11, 25)) return FALSE;
345
346         /* Large room */
347         y1 = yval - 4;
348         y2 = yval + 4;
349         x1 = xval - 11;
350         x2 = xval + 11;
351
352         /* Place the floor area */
353         for (y = y1 - 1; y <= y2 + 1; y++)
354         {
355                 for (x = x1 - 1; x <= x2 + 1; x++)
356                 {
357                         g_ptr = &floor_ptr->grid_array[y][x];
358                         place_floor_grid(g_ptr);
359                         g_ptr->info |= (CAVE_ROOM);
360                 }
361         }
362
363         /* Place the outer walls */
364         for (y = y1 - 1; y <= y2 + 1; y++)
365         {
366                 g_ptr = &floor_ptr->grid_array[y][x1 - 1];
367                 place_outer_grid(g_ptr);
368                 g_ptr = &floor_ptr->grid_array[y][x2 + 1];
369                 place_outer_grid(g_ptr);
370         }
371         for (x = x1 - 1; x <= x2 + 1; x++)
372         {
373                 g_ptr = &floor_ptr->grid_array[y1 - 1][x];
374                 place_outer_grid(g_ptr);
375                 g_ptr = &floor_ptr->grid_array[y2 + 1][x];
376                 place_outer_grid(g_ptr);
377         }
378
379
380         /* Advance to the center room */
381         y1 = y1 + 2;
382         y2 = y2 - 2;
383         x1 = x1 + 2;
384         x2 = x2 - 2;
385
386         /* The inner walls */
387         for (y = y1 - 1; y <= y2 + 1; y++)
388         {
389                 g_ptr = &floor_ptr->grid_array[y][x1 - 1];
390                 place_inner_grid(g_ptr);
391                 g_ptr = &floor_ptr->grid_array[y][x2 + 1];
392                 place_inner_grid(g_ptr);
393         }
394
395         for (x = x1 - 1; x <= x2 + 1; x++)
396         {
397                 g_ptr = &floor_ptr->grid_array[y1 - 1][x];
398                 place_inner_grid(g_ptr);
399                 g_ptr = &floor_ptr->grid_array[y2 + 1][x];
400                 place_inner_grid(g_ptr);
401         }
402         for (y = y1; y <= y2; y++)
403         {
404                 for (x = x1; x <= x2; x++)
405                 {
406                         add_cave_info(floor_ptr, y, x, CAVE_ICKY);
407                 }
408         }
409
410         /* Place a secret door */
411         switch (randint1(4))
412         {
413         case 1: place_secret_door(player_ptr, y1 - 1, xval, DOOR_DEFAULT); break;
414         case 2: place_secret_door(player_ptr, y2 + 1, xval, DOOR_DEFAULT); break;
415         case 3: place_secret_door(player_ptr, yval, x1 - 1, DOOR_DEFAULT); break;
416         case 4: place_secret_door(player_ptr, yval, x2 + 1, DOOR_DEFAULT); break;
417         }
418
419         msg_format_wizard(CHEAT_DUNGEON, _("モンスター部屋(nest)(%s%s)を生成します。", "Monster nest (%s%s)"), n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
420
421         /* Place some monsters */
422         for (y = yval - 2; y <= yval + 2; y++)
423         {
424                 for (x = xval - 9; x <= xval + 9; x++)
425                 {
426                         MONRACE_IDX r_idx;
427
428                         i = randint0(NUM_NEST_MON_TYPE);
429                         r_idx = nest_mon_info[i].r_idx;
430
431                         /* Place that "random" monster (no groups) */
432                         (void)place_monster_aux(0, y, x, r_idx, 0L);
433
434                         nest_mon_info[i].used = TRUE;
435                 }
436         }
437
438         if (cheat_room)
439         {
440                 ang_sort(nest_mon_info, NULL, NUM_NEST_MON_TYPE, ang_sort_comp_nest_mon_info, ang_sort_swap_nest_mon_info);
441
442                 /* Dump the entries (prevent multi-printing) */
443                 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
444                 {
445                         if (!nest_mon_info[i].used) break;
446                         for (; i < NUM_NEST_MON_TYPE - 1; i++)
447                         {
448                                 if (nest_mon_info[i].r_idx != nest_mon_info[i + 1].r_idx) break;
449                                 if (!nest_mon_info[i + 1].used) break;
450                         }
451                         msg_format_wizard(CHEAT_DUNGEON, "Nest構成モンスターNo.%d:%s", i, r_name + r_info[nest_mon_info[i].r_idx].name);
452                 }
453         }
454
455         return TRUE;
456 }
457
458
459 /*!
460 * @brief タイプ6の部屋…pitを生成する / Type 6 -- Monster pits
461 * @return なし
462 * @details
463 * A monster pit is a "big" room, with an "inner" room, containing\n
464 * a "collection" of monsters of a given type organized in the room.\n
465 *\n
466 * The inside room in a monster pit appears as shown below, where the\n
467 * actual monsters in each location depend on the type of the pit\n
468 *\n
469 *   XXXXXXXXXXXXXXXXXXXXX\n
470 *   X0000000000000000000X\n
471 *   X0112233455543322110X\n
472 *   X0112233467643322110X\n
473 *   X0112233455543322110X\n
474 *   X0000000000000000000X\n
475 *   XXXXXXXXXXXXXXXXXXXXX\n
476 *\n
477 * Note that the monsters in the pit are now chosen by using "get_mon_num()"\n
478 * to request 16 "appropriate" monsters, sorting them by level, and using\n
479 * the "even" entries in this sorted list for the contents of the pit.\n
480 *\n
481 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",\n
482 * which is handled by requiring a specific "breath" attack for all of the\n
483 * dragons.  This may include "multi-hued" breath.  Note that "wyrms" may\n
484 * be present in many of the dragon pits, if they have the proper breath.\n
485 *\n
486 * Note the use of the "get_mon_num_prep()" function, and the special\n
487 * "get_mon_num_hook()" restriction function, to prepare the "monster\n
488 * allocation table" in such a way as to optimize the selection of\n
489 * "appropriate" non-unique monsters for the pit.\n
490 *\n
491 * Note that the "get_mon_num()" function may (rarely) fail, in which case\n
492 * the pit will be empty.\n
493 *\n
494 * Note that "monster pits" will never contain "unique" monsters.\n
495 */
496 bool build_type6(player_type *player_ptr)
497 {
498         POSITION y, x, y1, x1, y2, x2, xval, yval;
499         int i, j;
500
501         MONRACE_IDX what[16];
502
503         monster_type align;
504
505         grid_type *g_ptr;
506
507         floor_type *floor_ptr = player_ptr->current_floor_ptr;
508         int cur_pit_type = pick_vault_type(floor_ptr, pit_types, d_info[floor_ptr->dungeon_idx].pit);
509         vault_aux_type *n_ptr;
510
511         /* No type available */
512         if (cur_pit_type < 0) return FALSE;
513
514         n_ptr = &pit_types[cur_pit_type];
515
516         /* Process a preparation function if necessary */
517         if (n_ptr->prep_func) (*(n_ptr->prep_func))();
518         get_mon_num_prep(n_ptr->hook_func, NULL);
519
520         align.sub_align = SUB_ALIGN_NEUTRAL;
521
522         /* Pick some monster types */
523         for (i = 0; i < 16; i++)
524         {
525                 MONRACE_IDX r_idx = 0;
526                 int attempts = 100;
527                 monster_race *r_ptr = NULL;
528
529                 while (attempts--)
530                 {
531                         /* Get a (hard) monster type */
532                         r_idx = get_mon_num(floor_ptr->dun_level + 11);
533                         r_ptr = &r_info[r_idx];
534
535                         /* Decline incorrect alignment */
536                         if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
537
538                         /* Accept this monster */
539                         break;
540                 }
541
542                 /* Notice failure */
543                 if (!r_idx || !attempts) return FALSE;
544
545                 /* Note the alignment */
546                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
547                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
548
549                 what[i] = r_idx;
550         }
551
552         /* Find and reserve some space in the dungeon.  Get center of room. */
553         if (!find_space(floor_ptr, &yval, &xval, 11, 25)) return FALSE;
554
555         /* Large room */
556         y1 = yval - 4;
557         y2 = yval + 4;
558         x1 = xval - 11;
559         x2 = xval + 11;
560
561         /* Place the floor area */
562         for (y = y1 - 1; y <= y2 + 1; y++)
563         {
564                 for (x = x1 - 1; x <= x2 + 1; x++)
565                 {
566                         g_ptr = &floor_ptr->grid_array[y][x];
567                         place_floor_grid(g_ptr);
568                         g_ptr->info |= (CAVE_ROOM);
569                 }
570         }
571
572         /* Place the outer walls */
573         for (y = y1 - 1; y <= y2 + 1; y++)
574         {
575                 g_ptr = &floor_ptr->grid_array[y][x1 - 1];
576                 place_outer_grid(g_ptr);
577                 g_ptr = &floor_ptr->grid_array[y][x2 + 1];
578                 place_outer_grid(g_ptr);
579         }
580         for (x = x1 - 1; x <= x2 + 1; x++)
581         {
582                 g_ptr = &floor_ptr->grid_array[y1 - 1][x];
583                 place_outer_grid(g_ptr);
584                 g_ptr = &floor_ptr->grid_array[y2 + 1][x];
585                 place_outer_grid(g_ptr);
586         }
587
588         /* Advance to the center room */
589         y1 = y1 + 2;
590         y2 = y2 - 2;
591         x1 = x1 + 2;
592         x2 = x2 - 2;
593
594         /* The inner walls */
595         for (y = y1 - 1; y <= y2 + 1; y++)
596         {
597                 g_ptr = &floor_ptr->grid_array[y][x1 - 1];
598                 place_inner_grid(g_ptr);
599                 g_ptr = &floor_ptr->grid_array[y][x2 + 1];
600                 place_inner_grid(g_ptr);
601         }
602         for (x = x1 - 1; x <= x2 + 1; x++)
603         {
604                 g_ptr = &floor_ptr->grid_array[y1 - 1][x];
605                 place_inner_grid(g_ptr);
606                 g_ptr = &floor_ptr->grid_array[y2 + 1][x];
607                 place_inner_grid(g_ptr);
608         }
609         for (y = y1; y <= y2; y++)
610         {
611                 for (x = x1; x <= x2; x++)
612                 {
613                         add_cave_info(floor_ptr, y, x, CAVE_ICKY);
614                 }
615         }
616
617         /* Place a secret door */
618         switch (randint1(4))
619         {
620         case 1: place_secret_door(player_ptr, y1 - 1, xval, DOOR_DEFAULT); break;
621         case 2: place_secret_door(player_ptr, y2 + 1, xval, DOOR_DEFAULT); break;
622         case 3: place_secret_door(player_ptr, yval, x1 - 1, DOOR_DEFAULT); break;
623         case 4: place_secret_door(player_ptr, yval, x2 + 1, DOOR_DEFAULT); break;
624         }
625
626         /* Sort the entries */
627         for (i = 0; i < 16 - 1; i++)
628         {
629                 /* Sort the entries */
630                 for (j = 0; j < 16 - 1; j++)
631                 {
632                         int i1 = j;
633                         int i2 = j + 1;
634
635                         int p1 = r_info[what[i1]].level;
636                         int p2 = r_info[what[i2]].level;
637
638                         /* Bubble */
639                         if (p1 > p2)
640                         {
641                                 MONRACE_IDX tmp = what[i1];
642                                 what[i1] = what[i2];
643                                 what[i2] = tmp;
644                         }
645                 }
646         }
647
648         msg_format_wizard(CHEAT_DUNGEON, _("モンスター部屋(pit)(%s%s)を生成します。", "Monster pit (%s%s)"), n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
649
650         /* Select the entries */
651         for (i = 0; i < 8; i++)
652         {
653                 /* Every other entry */
654                 what[i] = what[i * 2];
655                 msg_format_wizard(CHEAT_DUNGEON, _("Nest構成モンスター選択No.%d:%s", "Nest Monster Select No.%d:%s"), i, r_name + r_info[what[i]].name);
656         }
657
658         /* Top and bottom rows */
659         for (x = xval - 9; x <= xval + 9; x++)
660         {
661                 place_monster_aux(0, yval - 2, x, what[0], PM_NO_KAGE);
662                 place_monster_aux(0, yval + 2, x, what[0], PM_NO_KAGE);
663         }
664
665         /* Middle columns */
666         for (y = yval - 1; y <= yval + 1; y++)
667         {
668                 place_monster_aux(0, y, xval - 9, what[0], PM_NO_KAGE);
669                 place_monster_aux(0, y, xval + 9, what[0], PM_NO_KAGE);
670
671                 place_monster_aux(0, y, xval - 8, what[1], PM_NO_KAGE);
672                 place_monster_aux(0, y, xval + 8, what[1], PM_NO_KAGE);
673
674                 place_monster_aux(0, y, xval - 7, what[1], PM_NO_KAGE);
675                 place_monster_aux(0, y, xval + 7, what[1], PM_NO_KAGE);
676
677                 place_monster_aux(0, y, xval - 6, what[2], PM_NO_KAGE);
678                 place_monster_aux(0, y, xval + 6, what[2], PM_NO_KAGE);
679
680                 place_monster_aux(0, y, xval - 5, what[2], PM_NO_KAGE);
681                 place_monster_aux(0, y, xval + 5, what[2], PM_NO_KAGE);
682
683                 place_monster_aux(0, y, xval - 4, what[3], PM_NO_KAGE);
684                 place_monster_aux(0, y, xval + 4, what[3], PM_NO_KAGE);
685
686                 place_monster_aux(0, y, xval - 3, what[3], PM_NO_KAGE);
687                 place_monster_aux(0, y, xval + 3, what[3], PM_NO_KAGE);
688
689                 place_monster_aux(0, y, xval - 2, what[4], PM_NO_KAGE);
690                 place_monster_aux(0, y, xval + 2, what[4], PM_NO_KAGE);
691         }
692
693         /* Above/Below the center monster */
694         for (x = xval - 1; x <= xval + 1; x++)
695         {
696                 place_monster_aux(0, yval + 1, x, what[5], PM_NO_KAGE);
697                 place_monster_aux(0, yval - 1, x, what[5], PM_NO_KAGE);
698         }
699
700         /* Next to the center monster */
701         place_monster_aux(0, yval, xval + 1, what[6], PM_NO_KAGE);
702         place_monster_aux(0, yval, xval - 1, what[6], PM_NO_KAGE);
703
704         /* Center monster */
705         place_monster_aux(0, yval, xval, what[7], PM_NO_KAGE);
706
707         return TRUE;
708 }
709
710
711
712 /*
713 * Helper function for "trapped monster pit"
714 */
715 static bool vault_aux_trapped_pit(MONRACE_IDX r_idx)
716 {
717         monster_race *r_ptr = &r_info[r_idx];
718
719         if (!vault_monster_okay(r_idx)) return FALSE;
720
721         /* No wall passing monster */
722         if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return FALSE;
723
724         return TRUE;
725 }
726
727
728 /*!
729 * @brief タイプ13の部屋…トラップpitの生成 / Type 13 -- Trapped monster pits
730 * @return なし
731 * @details
732 * A trapped monster pit is a "big" room with a straight corridor in\n
733 * which wall opening traps are placed, and with two "inner" rooms\n
734 * containing a "collection" of monsters of a given type organized in\n
735 * the room.\n
736 *\n
737 * The trapped monster pit appears as shown below, where the actual\n
738 * monsters in each location depend on the type of the pit\n
739 *\n
740 *  XXXXXXXXXXXXXXXXXXXXXXXXX\n
741 *  X                       X\n
742 *  XXXXXXXXXXXXXXXXXXXXXXX X\n
743 *  XXXXX001123454321100XXX X\n
744 *  XXX0012234567654322100X X\n
745 *  XXXXXXXXXXXXXXXXXXXXXXX X\n
746 *  X           ^           X\n
747 *  X XXXXXXXXXXXXXXXXXXXXXXX\n
748 *  X X0012234567654322100XXX\n
749 *  X XXX001123454321100XXXXX\n
750 *  X XXXXXXXXXXXXXXXXXXXXXXX\n
751 *  X                       X\n
752 *  XXXXXXXXXXXXXXXXXXXXXXXXX\n
753 *\n
754 * Note that the monsters in the pit are now chosen by using "get_mon_num()"\n
755 * to request 16 "appropriate" monsters, sorting them by level, and using\n
756 * the "even" entries in this sorted list for the contents of the pit.\n
757 *\n
758 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",\n
759 * which is handled by requiring a specific "breath" attack for all of the\n
760 * dragons.  This may include "multi-hued" breath.  Note that "wyrms" may\n
761 * be present in many of the dragon pits, if they have the proper breath.\n
762 *\n
763 * Note the use of the "get_mon_num_prep()" function, and the special\n
764 * "get_mon_num_hook()" restriction function, to prepare the "monster\n
765 * allocation table" in such a way as to optimize the selection of\n
766 * "appropriate" non-unique monsters for the pit.\n
767 *\n
768 * Note that the "get_mon_num()" function may (rarely) fail, in which case\n
769 * the pit will be empty.\n
770 *\n
771 * Note that "monster pits" will never contain "unique" monsters.\n
772 */
773 bool build_type13(floor_type *floor_ptr)
774 {
775         static int placing[][3] = {
776                 { -2, -9, 0 },{ -2, -8, 0 },{ -3, -7, 0 },{ -3, -6, 0 },
777                 { +2, -9, 0 },{ +2, -8, 0 },{ +3, -7, 0 },{ +3, -6, 0 },
778                 { -2, +9, 0 },{ -2, +8, 0 },{ -3, +7, 0 },{ -3, +6, 0 },
779                 { +2, +9, 0 },{ +2, +8, 0 },{ +3, +7, 0 },{ +3, +6, 0 },
780                 { -2, -7, 1 },{ -3, -5, 1 },{ -3, -4, 1 },
781                 { +2, -7, 1 },{ +3, -5, 1 },{ +3, -4, 1 },
782                 { -2, +7, 1 },{ -3, +5, 1 },{ -3, +4, 1 },
783                 { +2, +7, 1 },{ +3, +5, 1 },{ +3, +4, 1 },
784                 { -2, -6, 2 },{ -2, -5, 2 },{ -3, -3, 2 },
785                 { +2, -6, 2 },{ +2, -5, 2 },{ +3, -3, 2 },
786                 { -2, +6, 2 },{ -2, +5, 2 },{ -3, +3, 2 },
787                 { +2, +6, 2 },{ +2, +5, 2 },{ +3, +3, 2 },
788                 { -2, -4, 3 },{ -3, -2, 3 },
789                 { +2, -4, 3 },{ +3, -2, 3 },
790                 { -2, +4, 3 },{ -3, +2, 3 },
791                 { +2, +4, 3 },{ +3, +2, 3 },
792                 { -2, -3, 4 },{ -3, -1, 4 },
793                 { +2, -3, 4 },{ +3, -1, 4 },
794                 { -2, +3, 4 },{ -3, +1, 4 },
795                 { +2, +3, 4 },{ +3, +1, 4 },
796                 { -2, -2, 5 },{ -3, 0, 5 },{ -2, +2, 5 },
797                 { +2, -2, 5 },{ +3, 0, 5 },{ +2, +2, 5 },
798                 { -2, -1, 6 },{ -2, +1, 6 },
799                 { +2, -1, 6 },{ +2, +1, 6 },
800                 { -2, 0, 7 },{ +2, 0, 7 },
801                 { 0, 0, -1 }
802         };
803
804         POSITION y, x, y1, x1, y2, x2, xval, yval;
805         int i, j;
806
807         MONRACE_IDX what[16];
808
809         monster_type align;
810
811         grid_type *g_ptr;
812
813         int cur_pit_type = pick_vault_type(floor_ptr, pit_types, d_info[floor_ptr->dungeon_idx].pit);
814         vault_aux_type *n_ptr;
815
816         /* Only in Angband */
817         if (floor_ptr->dungeon_idx != DUNGEON_ANGBAND) return FALSE;
818
819         /* No type available */
820         if (cur_pit_type < 0) return FALSE;
821
822         n_ptr = &pit_types[cur_pit_type];
823
824         /* Process a preparation function if necessary */
825         if (n_ptr->prep_func) (*(n_ptr->prep_func))();
826         get_mon_num_prep(n_ptr->hook_func, vault_aux_trapped_pit);
827
828         align.sub_align = SUB_ALIGN_NEUTRAL;
829
830         /* Pick some monster types */
831         for (i = 0; i < 16; i++)
832         {
833                 MONRACE_IDX r_idx = 0;
834                 int attempts = 100;
835                 monster_race *r_ptr = NULL;
836
837                 while (attempts--)
838                 {
839                         /* Get a (hard) monster type */
840                         r_idx = get_mon_num(floor_ptr->dun_level + 0);
841                         r_ptr = &r_info[r_idx];
842
843                         /* Decline incorrect alignment */
844                         if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
845
846                         /* Accept this monster */
847                         break;
848                 }
849
850                 /* Notice failure */
851                 if (!r_idx || !attempts) return FALSE;
852
853                 /* Note the alignment */
854                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
855                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
856
857                 what[i] = r_idx;
858         }
859
860         /* Find and reserve some space in the dungeon.  Get center of room. */
861         if (!find_space(floor_ptr, &yval, &xval, 13, 25)) return FALSE;
862
863         /* Large room */
864         y1 = yval - 5;
865         y2 = yval + 5;
866         x1 = xval - 11;
867         x2 = xval + 11;
868
869         /* Fill with inner walls */
870         for (y = y1 - 1; y <= y2 + 1; y++)
871         {
872                 for (x = x1 - 1; x <= x2 + 1; x++)
873                 {
874                         g_ptr = &floor_ptr->grid_array[y][x];
875                         place_inner_grid(g_ptr);
876                         g_ptr->info |= (CAVE_ROOM);
877                 }
878         }
879
880         /* Place the floor area 1 */
881         for (x = x1 + 3; x <= x2 - 3; x++)
882         {
883                 g_ptr = &floor_ptr->grid_array[yval - 2][x];
884                 place_floor_grid(g_ptr);
885                 add_cave_info(floor_ptr, yval - 2, x, CAVE_ICKY);
886
887                 g_ptr = &floor_ptr->grid_array[yval + 2][x];
888                 place_floor_grid(g_ptr);
889                 add_cave_info(floor_ptr, yval + 2, x, CAVE_ICKY);
890         }
891
892         /* Place the floor area 2 */
893         for (x = x1 + 5; x <= x2 - 5; x++)
894         {
895                 g_ptr = &floor_ptr->grid_array[yval - 3][x];
896                 place_floor_grid(g_ptr);
897                 add_cave_info(floor_ptr, yval - 3, x, CAVE_ICKY);
898
899                 g_ptr = &floor_ptr->grid_array[yval + 3][x];
900                 place_floor_grid(g_ptr);
901                 add_cave_info(floor_ptr, yval + 3, x, CAVE_ICKY);
902         }
903
904         /* Corridor */
905         for (x = x1; x <= x2; x++)
906         {
907                 g_ptr = &floor_ptr->grid_array[yval][x];
908                 place_floor_grid(g_ptr);
909                 g_ptr = &floor_ptr->grid_array[y1][x];
910                 place_floor_grid(g_ptr);
911                 g_ptr = &floor_ptr->grid_array[y2][x];
912                 place_floor_grid(g_ptr);
913         }
914
915         /* Place the outer walls */
916         for (y = y1 - 1; y <= y2 + 1; y++)
917         {
918                 g_ptr = &floor_ptr->grid_array[y][x1 - 1];
919                 place_outer_grid(g_ptr);
920                 g_ptr = &floor_ptr->grid_array[y][x2 + 1];
921                 place_outer_grid(g_ptr);
922         }
923         for (x = x1 - 1; x <= x2 + 1; x++)
924         {
925                 g_ptr = &floor_ptr->grid_array[y1 - 1][x];
926                 place_outer_grid(g_ptr);
927                 g_ptr = &floor_ptr->grid_array[y2 + 1][x];
928                 place_outer_grid(g_ptr);
929         }
930
931         /* Random corridor */
932         if (one_in_(2))
933         {
934                 for (y = y1; y <= yval; y++)
935                 {
936                         place_floor_bold(floor_ptr, y, x2);
937                         place_solid_bold(floor_ptr, y, x1 - 1);
938                 }
939                 for (y = yval; y <= y2 + 1; y++)
940                 {
941                         place_floor_bold(floor_ptr, y, x1);
942                         place_solid_bold(floor_ptr, y, x2 + 1);
943                 }
944         }
945         else
946         {
947                 for (y = yval; y <= y2 + 1; y++)
948                 {
949                         place_floor_bold(floor_ptr, y, x1);
950                         place_solid_bold(floor_ptr, y, x2 + 1);
951                 }
952                 for (y = y1; y <= yval; y++)
953                 {
954                         place_floor_bold(floor_ptr, y, x2);
955                         place_solid_bold(floor_ptr, y, x1 - 1);
956                 }
957         }
958
959         /* Place the wall open trap */
960         floor_ptr->grid_array[yval][xval].mimic = floor_ptr->grid_array[yval][xval].feat;
961         floor_ptr->grid_array[yval][xval].feat = feat_trap_open;
962
963         /* Sort the entries */
964         for (i = 0; i < 16 - 1; i++)
965         {
966                 /* Sort the entries */
967                 for (j = 0; j < 16 - 1; j++)
968                 {
969                         int i1 = j;
970                         int i2 = j + 1;
971
972                         int p1 = r_info[what[i1]].level;
973                         int p2 = r_info[what[i2]].level;
974
975                         /* Bubble */
976                         if (p1 > p2)
977                         {
978                                 MONRACE_IDX tmp = what[i1];
979                                 what[i1] = what[i2];
980                                 what[i2] = tmp;
981                         }
982                 }
983         }
984
985         msg_format_wizard(CHEAT_DUNGEON, _("%s%sの罠ピットが生成されました。", "Trapped monster pit (%s%s)"),
986                 n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
987
988         /* Select the entries */
989         for (i = 0; i < 8; i++)
990         {
991                 /* Every other entry */
992                 what[i] = what[i * 2];
993
994                 if (cheat_hear)
995                 {
996                         msg_print(r_name + r_info[what[i]].name);
997                 }
998         }
999
1000         for (i = 0; placing[i][2] >= 0; i++)
1001         {
1002                 y = yval + placing[i][0];
1003                 x = xval + placing[i][1];
1004                 place_monster_aux(0, y, x, what[placing[i][2]], PM_NO_KAGE);
1005         }
1006
1007         return TRUE;
1008 }
1009