OSDN Git Service

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