OSDN Git Service

[Refactor] #40569 Separated floor-type-definition.h from floor.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 "game-option/cheat-options.h"
5 #include "game-option/cheat-types.h"
6 #include "grid/feature.h"
7 #include "grid/grid.h"
8 #include "monster-floor/monster-generator.h"
9 #include "monster-floor/place-monster-types.h"
10 #include "monster-race/monster-race-hook.h"
11 #include "monster-race/monster-race.h"
12 #include "monster-race/race-flags-resistance.h"
13 #include "monster-race/race-flags1.h"
14 #include "monster-race/race-flags2.h"
15 #include "monster-race/race-flags3.h"
16 #include "monster-race/race-flags4.h"
17 #include "monster-race/race-flags7.h"
18 #include "monster/monster-info.h"
19 #include "monster/monster-list.h"
20 #include "monster/monster-util.h"
21 #include "room/pit-nest-kinds-table.h"
22 #include "room/rooms.h"
23 #include "system/floor-type-definition.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(player_ptr, CHEAT_DUNGEON, _("モンスター部屋(nest)(%s%s)を生成します。", "Monster nest (%s%s)"), n_ptr->name,
360             pit_subtype_string(cur_nest_type, TRUE));
361
362         /* Place some monsters */
363         for (y = yval - 2; y <= yval + 2; y++)
364         {
365                 for (x = xval - 9; x <= xval + 9; x++)
366                 {
367                         MONRACE_IDX r_idx;
368
369                         i = randint0(NUM_NEST_MON_TYPE);
370                         r_idx = nest_mon_info[i].r_idx;
371
372                         /* Place that "random" monster (no groups) */
373                         (void)place_monster_aux(player_ptr, 0, y, x, r_idx, 0L);
374
375                         nest_mon_info[i].used = TRUE;
376                 }
377         }
378
379         if (cheat_room)
380         {
381                 ang_sort(player_ptr, nest_mon_info, NULL, NUM_NEST_MON_TYPE, ang_sort_comp_nest_mon_info, ang_sort_swap_nest_mon_info);
382
383                 /* Dump the entries (prevent multi-printing) */
384                 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
385                 {
386                         if (!nest_mon_info[i].used) break;
387                         for (; i < NUM_NEST_MON_TYPE - 1; i++)
388                         {
389                                 if (nest_mon_info[i].r_idx != nest_mon_info[i + 1].r_idx) break;
390                                 if (!nest_mon_info[i + 1].used) break;
391                         }
392
393                         msg_format_wizard(player_ptr, CHEAT_DUNGEON, "Nest構成モンスターNo.%d:%s", i, r_name + r_info[nest_mon_info[i].r_idx].name);
394                 }
395         }
396
397         return TRUE;
398 }
399
400
401 /*!
402 * @brief タイプ6の部屋…pitを生成する / Type 6 -- Monster pits
403 * @return なし
404 * @details
405 * A monster pit is a "big" room, with an "inner" room, containing\n
406 * a "collection" of monsters of a given type organized in the room.\n
407 *\n
408 * The inside room in a monster pit appears as shown below, where the\n
409 * actual monsters in each location depend on the type of the pit\n
410 *\n
411 *   XXXXXXXXXXXXXXXXXXXXX\n
412 *   X0000000000000000000X\n
413 *   X0112233455543322110X\n
414 *   X0112233467643322110X\n
415 *   X0112233455543322110X\n
416 *   X0000000000000000000X\n
417 *   XXXXXXXXXXXXXXXXXXXXX\n
418 *\n
419 * Note that the monsters in the pit are now chosen by using "get_mon_num()"\n
420 * to request 16 "appropriate" monsters, sorting them by level, and using\n
421 * the "even" entries in this sorted list for the contents of the pit.\n
422 *\n
423 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",\n
424 * which is handled by requiring a specific "breath" attack for all of the\n
425 * dragons.  This may include "multi-hued" breath.  Note that "wyrms" may\n
426 * be present in many of the dragon pits, if they have the proper breath.\n
427 *\n
428 * Note the use of the "get_mon_num_prep()" function, and the special\n
429 * "get_mon_num_hook()" restriction function, to prepare the "monster\n
430 * allocation table" in such a way as to optimize the selection of\n
431 * "appropriate" non-unique monsters for the pit.\n
432 *\n
433 * Note that the "get_mon_num()" function may (rarely) fail, in which case\n
434 * the pit will be empty.\n
435 *\n
436 * Note that "monster pits" will never contain "unique" monsters.\n
437 */
438 bool build_type6(player_type *player_ptr)
439 {
440         POSITION y, x, y1, x1, y2, x2, xval, yval;
441         int i, j;
442
443         MONRACE_IDX what[16];
444
445         monster_type align;
446
447         grid_type *g_ptr;
448
449         floor_type *floor_ptr = player_ptr->current_floor_ptr;
450         int cur_pit_type = pick_vault_type(floor_ptr, pit_types, d_info[floor_ptr->dungeon_idx].pit);
451         vault_aux_type *n_ptr;
452
453         /* No type available */
454         if (cur_pit_type < 0) return FALSE;
455
456         n_ptr = &pit_types[cur_pit_type];
457
458         /* Process a preparation function if necessary */
459         if (n_ptr->prep_func) (*(n_ptr->prep_func))(player_ptr);
460         get_mon_num_prep(player_ptr, n_ptr->hook_func, NULL);
461
462         align.sub_align = SUB_ALIGN_NEUTRAL;
463
464         /* Pick some monster types */
465         for (i = 0; i < 16; i++)
466         {
467                 MONRACE_IDX r_idx = 0;
468                 int attempts = 100;
469                 monster_race *r_ptr = NULL;
470
471                 while (attempts--)
472                 {
473                         /* Get a (hard) monster type */
474                         r_idx = get_mon_num(player_ptr, floor_ptr->dun_level + 11, 0);
475                         r_ptr = &r_info[r_idx];
476
477                         /* Decline incorrect alignment */
478                         if (monster_has_hostile_align(player_ptr, &align, 0, 0, r_ptr)) continue;
479
480                         /* Accept this monster */
481                         break;
482                 }
483
484                 /* Notice failure */
485                 if (!r_idx || !attempts) return FALSE;
486
487                 /* Note the alignment */
488                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
489                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
490
491                 what[i] = r_idx;
492         }
493
494         /* Find and reserve some space in the dungeon.  Get center of room. */
495         if (!find_space(player_ptr, &yval, &xval, 11, 25)) return FALSE;
496
497         /* Large room */
498         y1 = yval - 4;
499         y2 = yval + 4;
500         x1 = xval - 11;
501         x2 = xval + 11;
502
503         /* Place the floor area */
504         for (y = y1 - 1; y <= y2 + 1; y++)
505         {
506                 for (x = x1 - 1; x <= x2 + 1; x++)
507                 {
508                         g_ptr = &floor_ptr->grid_array[y][x];
509                         place_grid(player_ptr, g_ptr, GB_FLOOR);
510                         g_ptr->info |= (CAVE_ROOM);
511                 }
512         }
513
514         /* Place the outer walls */
515         for (y = y1 - 1; y <= y2 + 1; y++)
516         {
517                 g_ptr = &floor_ptr->grid_array[y][x1 - 1];
518                 place_grid(player_ptr, g_ptr, GB_OUTER);
519                 g_ptr = &floor_ptr->grid_array[y][x2 + 1];
520                 place_grid(player_ptr, g_ptr, GB_OUTER);
521         }
522         for (x = x1 - 1; x <= x2 + 1; x++)
523         {
524                 g_ptr = &floor_ptr->grid_array[y1 - 1][x];
525                 place_grid(player_ptr, g_ptr, GB_OUTER);
526                 g_ptr = &floor_ptr->grid_array[y2 + 1][x];
527                 place_grid(player_ptr, g_ptr, GB_OUTER);
528         }
529
530         /* Advance to the center room */
531         y1 = y1 + 2;
532         y2 = y2 - 2;
533         x1 = x1 + 2;
534         x2 = x2 - 2;
535
536         /* The inner walls */
537         for (y = y1 - 1; y <= y2 + 1; y++)
538         {
539                 g_ptr = &floor_ptr->grid_array[y][x1 - 1];
540                 place_grid(player_ptr, g_ptr, GB_INNER);
541                 g_ptr = &floor_ptr->grid_array[y][x2 + 1];
542                 place_grid(player_ptr, g_ptr, GB_INNER);
543         }
544         for (x = x1 - 1; x <= x2 + 1; x++)
545         {
546                 g_ptr = &floor_ptr->grid_array[y1 - 1][x];
547                 place_grid(player_ptr, g_ptr, GB_INNER);
548                 g_ptr = &floor_ptr->grid_array[y2 + 1][x];
549                 place_grid(player_ptr, g_ptr, GB_INNER);
550         }
551         for (y = y1; y <= y2; y++)
552         {
553                 for (x = x1; x <= x2; x++)
554                 {
555                         add_cave_info(floor_ptr, y, x, CAVE_ICKY);
556                 }
557         }
558
559         /* Place a secret door */
560         switch (randint1(4))
561         {
562         case 1: place_secret_door(player_ptr, y1 - 1, xval, DOOR_DEFAULT); break;
563         case 2: place_secret_door(player_ptr, y2 + 1, xval, DOOR_DEFAULT); break;
564         case 3: place_secret_door(player_ptr, yval, x1 - 1, DOOR_DEFAULT); break;
565         case 4: place_secret_door(player_ptr, yval, x2 + 1, DOOR_DEFAULT); break;
566         }
567
568         /* Sort the entries */
569         for (i = 0; i < 16 - 1; i++)
570         {
571                 /* Sort the entries */
572                 for (j = 0; j < 16 - 1; j++)
573                 {
574                         int i1 = j;
575                         int i2 = j + 1;
576
577                         int p1 = r_info[what[i1]].level;
578                         int p2 = r_info[what[i2]].level;
579
580                         /* Bubble */
581                         if (p1 > p2)
582                         {
583                                 MONRACE_IDX tmp = what[i1];
584                                 what[i1] = what[i2];
585                                 what[i2] = tmp;
586                         }
587                 }
588         }
589
590         msg_format_wizard(player_ptr, CHEAT_DUNGEON, _("モンスター部屋(pit)(%s%s)を生成します。", "Monster pit (%s%s)"), n_ptr->name,
591             pit_subtype_string(cur_pit_type, FALSE));
592
593         /* Select the entries */
594         for (i = 0; i < 8; i++)
595         {
596                 /* Every other entry */
597                 what[i] = what[i * 2];
598                 msg_format_wizard(player_ptr, CHEAT_DUNGEON, _("Nest構成モンスター選択No.%d:%s", "Nest Monster Select No.%d:%s"), i, r_name + r_info[what[i]].name);
599         }
600
601         /* Top and bottom rows */
602         for (x = xval - 9; x <= xval + 9; x++)
603         {
604                 place_monster_aux(player_ptr, 0, yval - 2, x, what[0], PM_NO_KAGE);
605                 place_monster_aux(player_ptr, 0, yval + 2, x, what[0], PM_NO_KAGE);
606         }
607
608         /* Middle columns */
609         for (y = yval - 1; y <= yval + 1; y++)
610         {
611                 place_monster_aux(player_ptr, 0, y, xval - 9, what[0], PM_NO_KAGE);
612                 place_monster_aux(player_ptr, 0, y, xval + 9, what[0], PM_NO_KAGE);
613
614                 place_monster_aux(player_ptr, 0, y, xval - 8, what[1], PM_NO_KAGE);
615                 place_monster_aux(player_ptr, 0, y, xval + 8, what[1], PM_NO_KAGE);
616
617                 place_monster_aux(player_ptr, 0, y, xval - 7, what[1], PM_NO_KAGE);
618                 place_monster_aux(player_ptr, 0, y, xval + 7, what[1], PM_NO_KAGE);
619
620                 place_monster_aux(player_ptr, 0, y, xval - 6, what[2], PM_NO_KAGE);
621                 place_monster_aux(player_ptr, 0, y, xval + 6, what[2], PM_NO_KAGE);
622
623                 place_monster_aux(player_ptr, 0, y, xval - 5, what[2], PM_NO_KAGE);
624                 place_monster_aux(player_ptr, 0, y, xval + 5, what[2], PM_NO_KAGE);
625
626                 place_monster_aux(player_ptr, 0, y, xval - 4, what[3], PM_NO_KAGE);
627                 place_monster_aux(player_ptr, 0, y, xval + 4, what[3], PM_NO_KAGE);
628
629                 place_monster_aux(player_ptr, 0, y, xval - 3, what[3], PM_NO_KAGE);
630                 place_monster_aux(player_ptr, 0, y, xval + 3, what[3], PM_NO_KAGE);
631
632                 place_monster_aux(player_ptr, 0, y, xval - 2, what[4], PM_NO_KAGE);
633                 place_monster_aux(player_ptr, 0, y, xval + 2, what[4], PM_NO_KAGE);
634         }
635
636         /* Above/Below the center monster */
637         for (x = xval - 1; x <= xval + 1; x++)
638         {
639                 place_monster_aux(player_ptr, 0, yval + 1, x, what[5], PM_NO_KAGE);
640                 place_monster_aux(player_ptr, 0, yval - 1, x, what[5], PM_NO_KAGE);
641         }
642
643         /* Next to the center monster */
644         place_monster_aux(player_ptr, 0, yval, xval + 1, what[6], PM_NO_KAGE);
645         place_monster_aux(player_ptr, 0, yval, xval - 1, what[6], PM_NO_KAGE);
646
647         /* Center monster */
648         place_monster_aux(player_ptr, 0, yval, xval, what[7], PM_NO_KAGE);
649
650         return TRUE;
651 }
652
653 /*
654  * Helper function for "trapped monster pit"
655  */
656 static bool vault_aux_trapped_pit(player_type *player_ptr, MONRACE_IDX r_idx)
657 {
658     /* Unused */
659     (void)player_ptr;
660
661     monster_race *r_ptr = &r_info[r_idx];
662
663         if (!vault_monster_okay(player_ptr, r_idx)) return FALSE;
664
665         /* No wall passing monster */
666         if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return FALSE;
667
668         return TRUE;
669 }
670
671
672 /*!
673 * @brief タイプ13の部屋…トラップpitの生成 / Type 13 -- Trapped monster pits
674 * @return なし
675 * @details
676 * A trapped monster pit is a "big" room with a straight corridor in\n
677 * which wall opening traps are placed, and with two "inner" rooms\n
678 * containing a "collection" of monsters of a given type organized in\n
679 * the room.\n
680 *\n
681 * The trapped monster pit appears as shown below, where the actual\n
682 * monsters in each location depend on the type of the pit\n
683 *\n
684 *  XXXXXXXXXXXXXXXXXXXXXXXXX\n
685 *  X                       X\n
686 *  XXXXXXXXXXXXXXXXXXXXXXX X\n
687 *  XXXXX001123454321100XXX X\n
688 *  XXX0012234567654322100X X\n
689 *  XXXXXXXXXXXXXXXXXXXXXXX X\n
690 *  X           ^           X\n
691 *  X XXXXXXXXXXXXXXXXXXXXXXX\n
692 *  X X0012234567654322100XXX\n
693 *  X XXX001123454321100XXXXX\n
694 *  X XXXXXXXXXXXXXXXXXXXXXXX\n
695 *  X                       X\n
696 *  XXXXXXXXXXXXXXXXXXXXXXXXX\n
697 *\n
698 * Note that the monsters in the pit are now chosen by using "get_mon_num()"\n
699 * to request 16 "appropriate" monsters, sorting them by level, and using\n
700 * the "even" entries in this sorted list for the contents of the pit.\n
701 *\n
702 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",\n
703 * which is handled by requiring a specific "breath" attack for all of the\n
704 * dragons.  This may include "multi-hued" breath.  Note that "wyrms" may\n
705 * be present in many of the dragon pits, if they have the proper breath.\n
706 *\n
707 * Note the use of the "get_mon_num_prep()" function, and the special\n
708 * "get_mon_num_hook()" restriction function, to prepare the "monster\n
709 * allocation table" in such a way as to optimize the selection of\n
710 * "appropriate" non-unique monsters for the pit.\n
711 *\n
712 * Note that the "get_mon_num()" function may (rarely) fail, in which case\n
713 * the pit will be empty.\n
714 *\n
715 * Note that "monster pits" will never contain "unique" monsters.\n
716 */
717 bool build_type13(player_type *player_ptr)
718 {
719         POSITION y, x, y1, x1, y2, x2, xval, yval;
720         int i, j;
721
722         MONRACE_IDX what[16];
723
724         monster_type align;
725
726         grid_type *g_ptr;
727
728         floor_type *floor_ptr = player_ptr->current_floor_ptr;
729         int cur_pit_type = pick_vault_type(floor_ptr, pit_types, d_info[floor_ptr->dungeon_idx].pit);
730         vault_aux_type *n_ptr;
731
732         /* Only in Angband */
733         if (floor_ptr->dungeon_idx != DUNGEON_ANGBAND) return FALSE;
734
735         /* No type available */
736         if (cur_pit_type < 0) return FALSE;
737
738         n_ptr = &pit_types[cur_pit_type];
739
740         /* Process a preparation function if necessary */
741         if (n_ptr->prep_func) (*(n_ptr->prep_func))(player_ptr);
742         get_mon_num_prep(player_ptr, n_ptr->hook_func, vault_aux_trapped_pit);
743
744         align.sub_align = SUB_ALIGN_NEUTRAL;
745
746         /* Pick some monster types */
747         for (i = 0; i < 16; i++)
748         {
749                 MONRACE_IDX r_idx = 0;
750                 int attempts = 100;
751                 monster_race *r_ptr = NULL;
752
753                 while (attempts--)
754                 {
755                         /* Get a (hard) monster type */
756                         r_idx = get_mon_num(player_ptr, floor_ptr->dun_level + 0, 0);
757                         r_ptr = &r_info[r_idx];
758
759                         /* Decline incorrect alignment */
760                         if (monster_has_hostile_align(player_ptr, &align, 0, 0, r_ptr)) continue;
761
762                         /* Accept this monster */
763                         break;
764                 }
765
766                 /* Notice failure */
767                 if (!r_idx || !attempts) return FALSE;
768
769                 /* Note the alignment */
770                 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
771                 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
772
773                 what[i] = r_idx;
774         }
775
776         /* Find and reserve some space in the dungeon.  Get center of room. */
777         if (!find_space(player_ptr, &yval, &xval, 13, 25)) return FALSE;
778
779         /* Large room */
780         y1 = yval - 5;
781         y2 = yval + 5;
782         x1 = xval - 11;
783         x2 = xval + 11;
784
785         /* Fill with inner walls */
786         for (y = y1 - 1; y <= y2 + 1; y++)
787         {
788                 for (x = x1 - 1; x <= x2 + 1; x++)
789                 {
790                         g_ptr = &floor_ptr->grid_array[y][x];
791                         place_grid(player_ptr, g_ptr, GB_INNER);
792                         g_ptr->info |= (CAVE_ROOM);
793                 }
794         }
795
796         /* Place the floor area 1 */
797         for (x = x1 + 3; x <= x2 - 3; x++)
798         {
799                 g_ptr = &floor_ptr->grid_array[yval - 2][x];
800                 place_grid(player_ptr, g_ptr, GB_FLOOR);
801                 add_cave_info(floor_ptr, yval - 2, x, CAVE_ICKY);
802
803                 g_ptr = &floor_ptr->grid_array[yval + 2][x];
804                 place_grid(player_ptr, g_ptr, GB_FLOOR);
805                 add_cave_info(floor_ptr, yval + 2, x, CAVE_ICKY);
806         }
807
808         /* Place the floor area 2 */
809         for (x = x1 + 5; x <= x2 - 5; x++)
810         {
811                 g_ptr = &floor_ptr->grid_array[yval - 3][x];
812                 place_grid(player_ptr, g_ptr, GB_FLOOR);
813                 add_cave_info(floor_ptr, yval - 3, x, CAVE_ICKY);
814
815                 g_ptr = &floor_ptr->grid_array[yval + 3][x];
816                 place_grid(player_ptr, g_ptr, GB_FLOOR);
817                 add_cave_info(floor_ptr, yval + 3, x, CAVE_ICKY);
818         }
819
820         /* Corridor */
821         for (x = x1; x <= x2; x++)
822         {
823                 g_ptr = &floor_ptr->grid_array[yval][x];
824                 place_grid(player_ptr, g_ptr, GB_FLOOR);
825                 g_ptr = &floor_ptr->grid_array[y1][x];
826                 place_grid(player_ptr, g_ptr, GB_FLOOR);
827                 g_ptr = &floor_ptr->grid_array[y2][x];
828                 place_grid(player_ptr, g_ptr, GB_FLOOR);
829         }
830
831         /* Place the outer walls */
832         for (y = y1 - 1; y <= y2 + 1; y++)
833         {
834                 g_ptr = &floor_ptr->grid_array[y][x1 - 1];
835                 place_grid(player_ptr, g_ptr, GB_OUTER);
836                 g_ptr = &floor_ptr->grid_array[y][x2 + 1];
837                 place_grid(player_ptr, g_ptr, GB_OUTER);
838         }
839         for (x = x1 - 1; x <= x2 + 1; x++)
840         {
841                 g_ptr = &floor_ptr->grid_array[y1 - 1][x];
842                 place_grid(player_ptr, g_ptr, GB_OUTER);
843                 g_ptr = &floor_ptr->grid_array[y2 + 1][x];
844                 place_grid(player_ptr, g_ptr, GB_OUTER);
845         }
846
847         /* Random corridor */
848         if (one_in_(2))
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                 for (y = yval; y <= y2 + 1; y++)
856                 {
857                         place_bold(player_ptr, y, x1, GB_FLOOR);
858                         place_bold(player_ptr, y, x2 + 1, GB_SOLID);
859                 }
860         }
861         else
862         {
863                 for (y = yval; y <= y2 + 1; y++)
864                 {
865                         place_bold(player_ptr, y, x1, GB_FLOOR);
866                         place_bold(player_ptr, y, x2 + 1, GB_SOLID);
867                 }
868                 for (y = y1; y <= yval; y++)
869                 {
870                         place_bold(player_ptr, y, x2, GB_FLOOR);
871                         place_bold(player_ptr, y, x1 - 1, GB_SOLID);
872                 }
873         }
874
875         /* Place the wall open trap */
876         floor_ptr->grid_array[yval][xval].mimic = floor_ptr->grid_array[yval][xval].feat;
877         floor_ptr->grid_array[yval][xval].feat = feat_trap_open;
878
879         /* Sort the entries */
880         for (i = 0; i < 16 - 1; i++)
881         {
882                 /* Sort the entries */
883                 for (j = 0; j < 16 - 1; j++)
884                 {
885                         int i1 = j;
886                         int i2 = j + 1;
887
888                         int p1 = r_info[what[i1]].level;
889                         int p2 = r_info[what[i2]].level;
890
891                         /* Bubble */
892                         if (p1 > p2)
893                         {
894                                 MONRACE_IDX tmp = what[i1];
895                                 what[i1] = what[i2];
896                                 what[i2] = tmp;
897                         }
898                 }
899         }
900
901         msg_format_wizard(player_ptr, CHEAT_DUNGEON, _("%s%sの罠ピットが生成されました。", "Trapped monster pit (%s%s)"),
902                 n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
903
904         /* Select the entries */
905         for (i = 0; i < 8; i++)
906         {
907                 /* Every other entry */
908                 what[i] = what[i * 2];
909
910                 if (cheat_hear)
911                 {
912                         msg_print(r_name + r_info[what[i]].name);
913                 }
914         }
915
916         for (i = 0; placing[i][2] >= 0; i++)
917         {
918                 y = yval + placing[i][0];
919                 x = xval + placing[i][1];
920                 place_monster_aux(player_ptr, 0, y, x, what[placing[i][2]], PM_NO_KAGE);
921         }
922
923         return TRUE;
924 }