OSDN Git Service

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