OSDN Git Service

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