OSDN Git Service

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