OSDN Git Service

8ce1b4cf79a9bdd2114881e0da3a0dad605697fd
[hengband/hengband.git] / src / monster2.c
1 /*!
2  * @file monster2.c
3  * @brief モンスター処理 / misc code for monsters
4  * @date 2014/07/08
5  * @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7  * This software may be copied and distributed for educational, research,
8  * and not for profit purposes provided that this copyright and statement
9  * are included in all such copies.  Other copyrights may also apply.
10  * 2014 Deskull rearranged comment for Doxygen.
11  */
12
13 #include "angband.h"
14 #include "cmd-pet.h"
15 #include "monster-hook.h"
16 #include "monster-status.h"
17
18 #define HORDE_NOGOOD 0x01 /*!< (未実装フラグ)HORDE生成でGOODなモンスターの生成を禁止する? */
19 #define HORDE_NOEVIL 0x02 /*!< (未実装フラグ)HORDE生成でEVILなモンスターの生成を禁止する? */
20
21
22 /*!
23  * @var horror_desc
24  * @brief ELDRITCH HORROR効果時のモンスターの形容メッセージ(通常時)
25  */
26 cptr horror_desc[MAX_SAN_HORROR] =
27 {
28 #ifdef JP
29         "忌まわしい",
30         "底知れぬ",
31         "ぞっとする",
32         "破滅的な",
33         "冒涜的な",
34
35         "いやな",
36         "恐ろしい",
37         "不潔な",
38         "容赦のない",
39         "おぞましい",
40
41         "地獄の",
42         "身の毛もよだつ",
43         "地獄の",
44         "忌まわしい",
45         "悪夢のような",
46
47         "嫌悪を感じる",
48         "罰当たりな",
49         "恐い",
50         "不浄な",
51         "言うもおぞましい",
52 #else
53         "abominable",
54         "abysmal",
55         "appalling",
56         "baleful",
57         "blasphemous",
58
59         "disgusting",
60         "dreadful",
61         "filthy",
62         "grisly",
63         "hideous",
64
65         "hellish",
66         "horrible",
67         "infernal",
68         "loathsome",
69         "nightmarish",
70
71         "repulsive",
72         "sacrilegious",
73         "terrible",
74         "unclean",
75         "unspeakable",
76 #endif
77
78 };
79
80 /*!
81  * @var funny_desc
82  * @brief ELDRITCH HORROR効果時のモンスターの形容メッセージ(幻覚状態時)
83  */
84 cptr funny_desc[MAX_SAN_FUNNY] =
85 {
86 #ifdef JP
87         "間抜けな",
88         "滑稽な",
89         "ばからしい",
90         "無味乾燥な",
91         "馬鹿げた",
92
93         "笑える",
94         "ばかばかしい",
95         "ぶっとんだ",
96         "いかした",
97         "ポストモダンな",
98
99         "ファンタスティックな",
100         "ダダイズム的な",
101         "キュビズム的な",
102         "宇宙的な",
103         "卓越した",
104
105         "理解不能な",
106         "ものすごい",
107         "驚くべき",
108         "信じられない",
109         "カオティックな",
110
111         "野性的な",
112         "非常識な",
113 #else
114         "silly",
115         "hilarious",
116         "absurd",
117         "insipid",
118         "ridiculous",
119
120         "laughable",
121         "ludicrous",
122         "far-out",
123         "groovy",
124         "postmodern",
125
126         "fantastic",
127         "dadaistic",
128         "cubistic",
129         "cosmic",
130         "awesome",
131
132         "incomprehensible",
133         "fabulous",
134         "amazing",
135         "incredible",
136         "chaotic",
137
138         "wild",
139         "preposterous",
140 #endif
141
142 };
143
144 /*!
145  * @var funny_comments
146  * @brief ELDRITCH HORROR効果時の幻覚時間延長を示す錯乱表現
147  */
148 cptr funny_comments[MAX_SAN_COMMENT] =
149 {
150 #ifdef JP
151   /* nuke me */
152         "最高だぜ!",
153         "うひょー!",
154         "いかすぜ!",
155         "すんばらしい!",
156         "ぶっとびー!"
157 #else
158         "Wow, cosmic, man!",
159         "Rad!",
160         "Groovy!",
161         "Cool!",
162         "Far out!"
163 #endif
164
165 };
166
167
168 /*!
169  * @brief モンスターの目標地点をセットする / Set the target of counter attack
170  * @param m_ptr モンスターの参照ポインタ
171  * @param y 目標y座標
172  * @param x 目標x座標
173  * @return なし
174  */
175 void set_target(monster_type *m_ptr, POSITION y, POSITION x)
176 {
177         m_ptr->target_y = y;
178         m_ptr->target_x = x;
179 }
180
181
182 /*!
183  * @brief モンスターの目標地点をリセットする / Reset the target of counter attack
184  * @param m_ptr モンスターの参照ポインタ
185  * @return なし
186  */
187 void reset_target(monster_type *m_ptr)
188 {
189         set_target(m_ptr, 0, 0);
190 }
191
192
193 /*!
194  * @brief モンスターの真の種族を返す / Extract monster race pointer of a monster's true form
195  * @param m_ptr モンスターの参照ポインタ
196  * @return 本当のモンスター種族参照ポインタ
197  */
198 monster_race *real_r_ptr(monster_type *m_ptr)
199 {
200         monster_race *r_ptr = &r_info[m_ptr->r_idx];
201
202         /* Extract real race */
203         if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
204         {
205                 if (r_ptr->flags1 & RF1_UNIQUE)
206                         return &r_info[MON_CHAMELEON_K];
207                 else
208                         return &r_info[MON_CHAMELEON];
209         }
210         else
211         {
212                 return r_ptr;
213         }
214 }
215
216
217 /*!
218  * @brief モンスター配列からモンスターを消去する / Delete a monster by index.
219  * @param i 消去するモンスターのID
220  * @return なし
221  * @details
222  * モンスターを削除するとそのモンスターが拾っていたアイテムも同時に削除される。 /
223  * When a monster is deleted, all of its objects are deleted.
224  */
225 void delete_monster_idx(MONSTER_IDX i)
226 {
227         POSITION x, y;
228         monster_type *m_ptr = &m_list[i];
229         monster_race *r_ptr = &r_info[m_ptr->r_idx];
230         OBJECT_IDX this_o_idx, next_o_idx = 0;
231
232         /* Get location */
233         y = m_ptr->fy;
234         x = m_ptr->fx;
235
236         /* Hack -- Reduce the racial counter */
237         real_r_ptr(m_ptr)->cur_num--;
238
239         /* Hack -- count the number of "reproducers" */
240         if (r_ptr->flags2 & (RF2_MULTIPLY)) num_repro--;
241
242         if (MON_CSLEEP(m_ptr)) (void)set_monster_csleep(i, 0);
243         if (MON_FAST(m_ptr)) (void)set_monster_fast(i, 0);
244         if (MON_SLOW(m_ptr)) (void)set_monster_slow(i, 0);
245         if (MON_STUNNED(m_ptr)) (void)set_monster_stunned(i, 0);
246         if (MON_CONFUSED(m_ptr)) (void)set_monster_confused(i, 0);
247         if (MON_MONFEAR(m_ptr)) (void)set_monster_monfear(i, 0);
248         if (MON_INVULNER(m_ptr)) (void)set_monster_invulner(i, 0, FALSE);
249
250
251         /* Hack -- remove target monster */
252         if (i == target_who) target_who = 0;
253
254         /* Hack -- remove tracked monster */
255         if (i == p_ptr->health_who) health_track(0);
256
257         if (pet_t_m_idx == i ) pet_t_m_idx = 0;
258         if (riding_t_m_idx == i) riding_t_m_idx = 0;
259         if (p_ptr->riding == i) p_ptr->riding = 0;
260
261         /* Monster is gone */
262         cave[y][x].m_idx = 0;
263
264
265         /* Delete objects */
266         for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
267         {
268                 object_type *o_ptr;
269                 o_ptr = &o_list[this_o_idx];
270
271                 /* Acquire next object */
272                 next_o_idx = o_ptr->next_o_idx;
273
274                 /*
275                  * o_ptr->held_m_idx is needed in delete_object_idx()
276                  * to prevent calling lite_spot()
277                  */
278
279                 delete_object_idx(this_o_idx);
280         }
281
282
283         if (is_pet(m_ptr)) check_pets_num_and_align(m_ptr, FALSE);
284
285
286         /* Wipe the Monster */
287         (void)WIPE(m_ptr, monster_type);
288
289         /* Count monsters */
290         m_cnt--;
291
292         /* Visual update */
293         lite_spot(y, x);
294
295         /* Update some things */
296         if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
297                 p_ptr->update |= (PU_MON_LITE);
298 }
299
300
301 /*!
302  * @brief 指定位置に存在するモンスターを削除する / Delete the monster, if any, at a given location
303  * @param x 削除位置x座標
304  * @param y 削除位置y座標
305  * @return なし
306  */
307 void delete_monster(POSITION y, POSITION x)
308 {
309         cave_type *c_ptr;
310
311         /* Paranoia */
312         if (!in_bounds(y, x)) return;
313
314         /* Check the grid */
315         c_ptr = &cave[y][x];
316
317         /* Delete the monster (if any) */
318         if (c_ptr->m_idx) delete_monster_idx(c_ptr->m_idx);
319 }
320
321
322 /*!
323  * @brief モンスター情報を配列内移動する / Move an object from index i1 to index i2 in the object list
324  * @param i1 配列移動元添字
325  * @param i2 配列移動先添字
326  * @return なし
327  */
328 static void compact_monsters_aux(IDX i1, IDX i2)
329 {
330         POSITION y, x;
331         int i;
332         cave_type *c_ptr;
333         monster_type *m_ptr;
334         OBJECT_IDX this_o_idx, next_o_idx = 0;
335
336         /* Do nothing */
337         if (i1 == i2) return;
338
339         /* Old monster */
340         m_ptr = &m_list[i1];
341
342         y = m_ptr->fy;
343         x = m_ptr->fx;
344
345         /* Cave grid */
346         c_ptr = &cave[y][x];
347
348         /* Update the cave */
349         c_ptr->m_idx = i2;
350
351         /* Repair objects being carried by monster */
352         for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
353         {
354                 object_type *o_ptr;
355                 o_ptr = &o_list[this_o_idx];
356
357                 /* Acquire next object */
358                 next_o_idx = o_ptr->next_o_idx;
359
360                 /* Reset monster pointer */
361                 o_ptr->held_m_idx = i2;
362         }
363
364         /* Hack -- Update the target */
365         if (target_who == i1) target_who = i2;
366
367         /* Hack -- Update the target */
368         if (pet_t_m_idx == i1) pet_t_m_idx = i2;
369         if (riding_t_m_idx == i1) riding_t_m_idx = i2;
370
371         /* Hack -- Update the riding */
372         if (p_ptr->riding == i1) p_ptr->riding = i2;
373
374         /* Hack -- Update the health bar */
375         if (p_ptr->health_who == i1) health_track(i2);
376
377         /* Hack -- Update parent index */
378         if (is_pet(m_ptr))
379         {
380                 for (i = 1; i < m_max; i++)
381                 {
382                         monster_type *m2_ptr = &m_list[i];
383
384                         if (m2_ptr->parent_m_idx == i1)
385                                 m2_ptr->parent_m_idx = i2;
386                 }
387         }
388
389         /* Structure copy */
390         (void)COPY(&m_list[i2], &m_list[i1], monster_type);
391
392         /* Wipe the hole */
393         (void)WIPE(&m_list[i1], monster_type);
394
395         for (i = 0; i < MAX_MTIMED; i++)
396         {
397                 int mproc_idx = get_mproc_idx(i1, i);
398                 if (mproc_idx >= 0) mproc_list[i][mproc_idx] = i2;
399         }
400 }
401
402
403 /*!
404  * @brief モンスター情報配列を圧縮する / Compact and Reorder the monster list
405  * @param size 圧縮後のモンスター件数目標
406  * @return なし
407  * @details
408  * This function can be very dangerous, use with caution!
409  *
410  * When actually "compacting" monsters, we base the saving throw
411  * on a combination of monster level, distance from player, and
412  * current "desperation".
413  *
414  * After "compacting" (if needed), we "reorder" the monsters into a more
415  * compact order, and we reset the allocation info, and the "live" array.
416  */
417 void compact_monsters(int size)
418 {
419         MONSTER_IDX i;
420         int num, cnt;
421         int cur_lev, cur_dis, chance;
422
423         /* Message (only if compacting) */
424         if (size) msg_print(_("モンスター情報を圧縮しています...", "Compacting monsters..."));
425
426
427         /* Compact at least 'size' objects */
428         for (num = 0, cnt = 1; num < size; cnt++)
429         {
430                 /* Get more vicious each iteration */
431                 cur_lev = 5 * cnt;
432
433                 /* Get closer each iteration */
434                 cur_dis = 5 * (20 - cnt);
435
436                 /* Check all the monsters */
437                 for (i = 1; i < m_max; i++)
438                 {
439                         monster_type *m_ptr = &m_list[i];
440
441                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
442
443                         /* Paranoia -- skip "dead" monsters */
444                         if (!m_ptr->r_idx) continue;
445
446                         /* Hack -- High level monsters start out "immune" */
447                         if (r_ptr->level > cur_lev) continue;
448
449                         if (i == p_ptr->riding) continue;
450
451                         /* Ignore nearby monsters */
452                         if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
453
454                         /* Saving throw chance */
455                         chance = 90;
456
457                         /* Only compact "Quest" Monsters in emergencies */
458                         if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
459
460                         /* Try not to compact Unique Monsters */
461                         if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
462
463                         /* All monsters get a saving throw */
464                         if (randint0(100) < chance) continue;
465
466                         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
467                         {
468                                 char m_name[80];
469                                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
470                                 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
471                         }
472
473                         delete_monster_idx(i);
474
475                         /* Count the monster */
476                         num++;
477                 }
478         }
479
480
481         /* Excise dead monsters (backwards!) */
482         for (i = m_max - 1; i >= 1; i--)
483         {
484                 /* Get the i'th monster */
485                 monster_type *m_ptr = &m_list[i];
486
487                 /* Skip real monsters */
488                 if (m_ptr->r_idx) continue;
489
490                 /* Move last monster into open hole */
491                 compact_monsters_aux(m_max - 1, i);
492
493                 /* Compress "m_max" */
494                 m_max--;
495         }
496 }
497
498
499 /*!
500  * @brief プレイヤーのフロア離脱に伴う全モンスター配列の消去 / Delete/Remove all the monsters when the player leaves the level
501  * @return なし
502  * @details
503  * This is an efficient method of simulating multiple calls to the
504  * "delete_monster()" function, with no visual effects.
505  */
506 void wipe_m_list(void)
507 {
508         int i;
509
510         /* Hack -- if Banor or Lupart dies, stay another dead */
511         if (!r_info[MON_BANORLUPART].max_num)
512         {
513                 if (r_info[MON_BANOR].max_num)
514                 {
515                         r_info[MON_BANOR].max_num = 0;
516                         r_info[MON_BANOR].r_pkills++;
517                         r_info[MON_BANOR].r_akills++;
518                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
519                 }
520                 if (r_info[MON_LUPART].max_num)
521                 {
522                         r_info[MON_LUPART].max_num = 0;
523                         r_info[MON_LUPART].r_pkills++;
524                         r_info[MON_LUPART].r_akills++;
525                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
526                 }
527         }
528
529         /* Delete all the monsters */
530         for (i = m_max - 1; i >= 1; i--)
531         {
532                 monster_type *m_ptr = &m_list[i];
533
534                 /* Skip dead monsters */
535                 if (!m_ptr->r_idx) continue;
536
537                 /* Monster is gone */
538                 cave[m_ptr->fy][m_ptr->fx].m_idx = 0;
539
540                 /* Wipe the Monster */
541                 (void)WIPE(m_ptr, monster_type);
542
543         }
544
545         /*
546          * Wiping racial counters of all monsters and incrementing of racial
547          * counters of monsters in party_mon[] are required to prevent multiple
548          * generation of unique monster who is the minion of player.
549          */
550
551         /* Hack -- Wipe the racial counter of all monster races */
552         for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
553
554         /* Reset "m_max" */
555         m_max = 1;
556
557         /* Reset "m_cnt" */
558         m_cnt = 0;
559
560         /* Reset "mproc_max[]" */
561         for (i = 0; i < MAX_MTIMED; i++) mproc_max[i] = 0;
562
563         /* Hack -- reset "reproducer" count */
564         num_repro = 0;
565
566         /* Hack -- no more target */
567         target_who = 0;
568         pet_t_m_idx = 0;
569         riding_t_m_idx = 0;
570
571         /* Hack -- no more tracking */
572         health_track(0);
573 }
574
575
576 /*!
577  * @brief モンスター配列の空きを探す / Acquires and returns the index of a "free" monster.
578  * @return 利用可能なモンスター配列の添字
579  * @details
580  * This routine should almost never fail, but it *can* happen.
581  */
582 MONSTER_IDX m_pop(void)
583 {
584         MONSTER_IDX i;
585
586         /* Normal allocation */
587         if (m_max < max_m_idx)
588         {
589                 /* Access the next hole */
590                 i = m_max;
591
592                 /* Expand the array */
593                 m_max++;
594
595                 /* Count monsters */
596                 m_cnt++;
597
598                 /* Return the index */
599                 return (i);
600         }
601
602         /* Recycle dead monsters */
603         for (i = 1; i < m_max; i++)
604         {
605                 monster_type *m_ptr;
606
607                 /* Acquire monster */
608                 m_ptr = &m_list[i];
609
610                 /* Skip live monsters */
611                 if (m_ptr->r_idx) continue;
612
613                 /* Count monsters */
614                 m_cnt++;
615
616                 /* Use this monster */
617                 return (i);
618         }
619
620         /* Warn the player (except during dungeon creation) */
621         if (character_dungeon) msg_print(_("モンスターが多すぎる!", "Too many monsters!"));
622
623         /* Try not to crash */
624         return (0);
625 }
626
627
628
629
630 /*!
631  * @var summon_specific_type
632  * @brief 召喚条件を指定するグローバル変数 / Hack -- the "type" of the current "summon specific"
633  * @todo summon_specific_typeグローバル変数の除去と関数引数への代替を行う
634  */
635 static int summon_specific_type = 0;
636
637
638 /*!
639  * @var summon_specific_who
640  * @brief 召喚を行ったプレイヤーあるいはモンスターのIDを示すグローバル変数 / Hack -- the index of the summoning monster
641  * @todo summon_specific_who グローバル変数の除去と関数引数への代替を行う
642  */
643 static int summon_specific_who = -1;
644
645 /*!
646  * @var summon_unique_okay
647  * @brief 召喚対象にユニークを含めるかを示すグローバル変数 / summoning unique enable
648  * @todo summon_unique_okay グローバル変数の除去と関数引数への代替を行う
649  */
650 static bool summon_unique_okay = FALSE;
651
652 /*!
653  * @brief 指定されたモンスター種族がsummon_specific_typeで指定された召喚条件に合うかどうかを返す
654  * @return 召喚条件が一致するならtrue
655  * @details
656  */
657 static bool summon_specific_aux(MONRACE_IDX r_idx)
658 {
659         monster_race *r_ptr = &r_info[r_idx];
660         int okay = FALSE;
661
662         /* Check our requirements */
663         switch (summon_specific_type)
664         {
665                 case SUMMON_ANT:
666                 {
667                         okay = (r_ptr->d_char == 'a');
668                         break;
669                 }
670
671                 case SUMMON_SPIDER:
672                 {
673                         okay = (r_ptr->d_char == 'S');
674                         break;
675                 }
676
677                 case SUMMON_HOUND:
678                 {
679                         okay = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z'));
680                         break;
681                 }
682
683                 case SUMMON_HYDRA:
684                 {
685                         okay = (r_ptr->d_char == 'M');
686                         break;
687                 }
688
689                 case SUMMON_ANGEL:
690                 {
691                         okay = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD)));
692                         break;
693                 }
694
695                 case SUMMON_DEMON:
696                 {
697                         okay = (r_ptr->flags3 & RF3_DEMON);
698                         break;
699                 }
700
701                 case SUMMON_UNDEAD:
702                 {
703                         okay = (r_ptr->flags3 & RF3_UNDEAD);
704                         break;
705                 }
706
707                 case SUMMON_DRAGON:
708                 {
709                         okay = (r_ptr->flags3 & RF3_DRAGON);
710                         break;
711                 }
712
713                 case SUMMON_HI_UNDEAD:
714                 {
715                         okay = ((r_ptr->d_char == 'L') ||
716                                 (r_ptr->d_char == 'V') ||
717                                 (r_ptr->d_char == 'W'));
718                         break;
719                 }
720
721                 case SUMMON_HI_DRAGON:
722                 {
723                         okay = (r_ptr->d_char == 'D');
724                         break;
725                 }
726
727                 case SUMMON_HI_DEMON:
728                 {
729                         okay = (((r_ptr->d_char == 'U') ||
730                                  (r_ptr->d_char == 'H') ||
731                                  (r_ptr->d_char == 'B')) &&
732                                 (r_ptr->flags3 & RF3_DEMON)) ? TRUE : FALSE;
733                         break;
734                 }
735
736                 case SUMMON_AMBERITES:
737                 {
738                         okay = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE;
739                         break;
740                 }
741
742                 case SUMMON_UNIQUE:
743                 {
744                         okay = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE;
745                         break;
746                 }
747
748                 case SUMMON_MOLD:
749                 {
750                         okay = (r_ptr->d_char == 'm');
751                         break;
752                 }
753                 case SUMMON_BAT:
754                 {
755                         okay = (r_ptr->d_char == 'b');
756                         break;
757                 }
758                 case SUMMON_QUYLTHULG:
759                 {
760                         okay = (r_ptr->d_char == 'Q');
761                         break;
762                 }
763
764                 case SUMMON_COIN_MIMIC:
765                 {
766                         okay = (r_ptr->d_char == '$');
767                         break;
768                 }
769
770                 case SUMMON_MIMIC:
771                 {
772                         okay = ((r_ptr->d_char == '!') ||
773                                  (r_ptr->d_char == '?') ||
774                                  (r_ptr->d_char == '=') ||
775                                  (r_ptr->d_char == '$') ||
776                                  (r_ptr->d_char == '|'));
777                         break;
778                 }
779
780                 case SUMMON_GOLEM:
781                 {
782                         okay = (r_ptr->d_char == 'g');
783                         break;
784                 }
785
786                 case SUMMON_CYBER:
787                 {
788                         okay = ((r_ptr->d_char == 'U') &&
789                                 (r_ptr->flags4 & RF4_ROCKET));
790                         break;
791                 }
792
793
794                 case SUMMON_KIN:
795                 {
796                         okay = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE));
797                         break;
798                 }
799
800                 case SUMMON_DAWN:
801                 {
802                         okay = (r_idx == MON_DAWN);
803                         break;
804                 }
805
806                 case SUMMON_ANIMAL:
807                 {
808                         okay = (r_ptr->flags3 & (RF3_ANIMAL));
809                         break;
810                 }
811
812                 case SUMMON_ANIMAL_RANGER:
813                 {
814                         okay = ((r_ptr->flags3 & (RF3_ANIMAL)) &&
815                                (my_strchr("abcflqrwBCHIJKMRS", r_ptr->d_char)) &&
816                                !(r_ptr->flags3 & (RF3_DRAGON)) &&
817                                !(r_ptr->flags3 & (RF3_EVIL)) &&
818                                !(r_ptr->flags3 & (RF3_UNDEAD)) &&
819                                !(r_ptr->flags3 & (RF3_DEMON)) &&
820                                !(r_ptr->flags2 & (RF2_MULTIPLY)) &&
821                                !(r_ptr->flags4 || r_ptr->a_ability_flags1 || r_ptr->a_ability_flags2));
822                         break;
823                 }
824
825                 case SUMMON_HI_DRAGON_LIVING:
826                 {
827                         okay = ((r_ptr->d_char == 'D') && monster_living(r_ptr));
828                         break;
829                 }
830
831                 case SUMMON_LIVING:
832                 {
833                         okay = monster_living(r_ptr);
834                         break;
835                 }
836
837                 case SUMMON_PHANTOM:
838                 {
839                         okay = (r_idx == MON_PHANTOM_B || r_idx == MON_PHANTOM_W);
840                         break;
841                 }
842
843                 case SUMMON_BLUE_HORROR:
844                 {
845                         okay = (r_idx == MON_BLUE_HORROR);
846                         break;
847                 }
848
849                 case SUMMON_ELEMENTAL:
850                 {
851                         okay = (r_ptr->d_char == 'E');
852                         break;
853                 }
854
855                 case SUMMON_VORTEX:
856                 {
857                         okay = (r_ptr->d_char == 'v');
858                         break;
859                 }
860
861                 case SUMMON_HYBRID:
862                 {
863                         okay = (r_ptr->d_char == 'H');
864                         break;
865                 }
866
867                 case SUMMON_BIRD:
868                 {
869                         okay = (r_ptr->d_char == 'B');
870                         break;
871                 }
872
873                 case SUMMON_KAMIKAZE:
874                 {
875                         int i;
876                         for (i = 0; i < 4; i++)
877                                 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
878                         break;
879                 }
880
881                 case SUMMON_KAMIKAZE_LIVING:
882                 {
883                         int i;
884
885                         for (i = 0; i < 4; i++)
886                                 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
887                         okay = (okay && monster_living(r_ptr));
888                         break;
889                 }
890
891                 case SUMMON_MANES:
892                 {
893                         okay = (r_idx == MON_MANES);
894                         break;
895                 }
896
897                 case SUMMON_LOUSE:
898                 {
899                         okay = (r_idx == MON_LOUSE);
900                         break;
901                 }
902
903                 case SUMMON_GUARDIANS:
904                 {
905                         okay = (r_ptr->flags7 & RF7_GUARDIAN);
906                         break;
907                 }
908
909                 case SUMMON_KNIGHTS:
910                 {
911                         okay = ((r_idx == MON_NOV_PALADIN) ||
912                                 (r_idx == MON_NOV_PALADIN_G) ||
913                                 (r_idx == MON_PALADIN) ||
914                                 (r_idx == MON_W_KNIGHT) ||
915                                 (r_idx == MON_ULTRA_PALADIN) ||
916                                 (r_idx == MON_KNI_TEMPLAR));
917                         break;
918                 }
919
920                 case SUMMON_EAGLES:
921                 {
922                         okay = (r_ptr->d_char == 'B' &&
923                                 (r_ptr->flags8 & RF8_WILD_MOUNTAIN) &&
924                                 (r_ptr->flags8 & RF8_WILD_ONLY));
925                         break;
926                 }
927
928                 case SUMMON_PIRANHAS:
929                 {
930                         okay = (r_idx == MON_PIRANHA);
931                         break;
932                 }
933
934                 case SUMMON_ARMAGE_GOOD:
935                 {
936                         okay = (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_GOOD));
937                         break;
938                 }
939
940                 case SUMMON_ARMAGE_EVIL:
941                 {
942                         okay = ((r_ptr->flags3 & RF3_DEMON) ||
943                                 (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_EVIL)));
944                         break;
945                 }
946         }
947         /* Since okay is int, "return (okay);" is not correct. */
948         return (bool)(okay ? TRUE : FALSE);
949 }
950
951 /*!
952  * @var chameleon_change_m_idx
953  * @brief カメレオンの変身先モンスターIDを受け渡すためのグローバル変数
954  * @todo 変数渡しの問題などもあるができればchameleon_change_m_idxのグローバル変数を除去し、関数引き渡しに移行すること
955  */
956 static int chameleon_change_m_idx = 0;
957
958
959 /*!
960  * @brief 指定されたモンスター種族がダンジョンの制限にかかるかどうかをチェックする / Some dungeon types restrict the possible monsters.
961  * @param r_idx チェックするモンスター種族ID
962  * @return 召喚条件が一致するならtrue / Return TRUE is the monster is OK and FALSE otherwise
963  */
964 static bool restrict_monster_to_dungeon(MONRACE_IDX r_idx)
965 {
966         dungeon_info_type *d_ptr = &d_info[dungeon_type];
967         monster_race *r_ptr = &r_info[r_idx];
968         byte a;
969
970         if (d_ptr->flags1 & DF1_CHAMELEON)
971         {
972                 if (chameleon_change_m_idx) return TRUE;
973         }
974         if (d_ptr->flags1 & DF1_NO_MAGIC)
975         {
976                 if (r_idx != MON_CHAMELEON &&
977                     r_ptr->freq_spell && 
978                     !(r_ptr->flags4 & RF4_NOMAGIC_MASK) &&
979                     !(r_ptr->a_ability_flags1 & RF5_NOMAGIC_MASK) &&
980                     !(r_ptr->a_ability_flags2 & RF6_NOMAGIC_MASK))
981                         return FALSE;
982         }
983         if (d_ptr->flags1 & DF1_NO_MELEE)
984         {
985                 if (r_idx == MON_CHAMELEON) return TRUE;
986                 if (!(r_ptr->flags4 & (RF4_BOLT_MASK | RF4_BEAM_MASK | RF4_BALL_MASK)) &&
987                     !(r_ptr->a_ability_flags1 & (RF5_BOLT_MASK | RF5_BEAM_MASK | RF5_BALL_MASK | RF5_CAUSE_1 | RF5_CAUSE_2 | RF5_CAUSE_3 | RF5_CAUSE_4 | RF5_MIND_BLAST | RF5_BRAIN_SMASH)) &&
988                     !(r_ptr->a_ability_flags2 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
989                         return FALSE;
990         }
991         if (d_ptr->flags1 & DF1_BEGINNER)
992         {
993                 if (r_ptr->level > dun_level)
994                         return FALSE;
995         }
996
997         if (d_ptr->special_div >= 64) return TRUE;
998         if (summon_specific_type && !(d_ptr->flags1 & DF1_CHAMELEON)) return TRUE;
999
1000         switch (d_ptr->mode)
1001         {
1002         case DUNGEON_MODE_AND:
1003                 if (d_ptr->mflags1)
1004                 {
1005                         if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
1006                                 return FALSE;
1007                 }
1008                 if (d_ptr->mflags2)
1009                 {
1010                         if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
1011                                 return FALSE;
1012                 }
1013                 if (d_ptr->mflags3)
1014                 {
1015                         if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
1016                                 return FALSE;
1017                 }
1018                 if (d_ptr->mflags4)
1019                 {
1020                         if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
1021                                 return FALSE;
1022                 }
1023                 if (d_ptr->m_a_ability_flags1)
1024                 {
1025                         if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
1026                                 return FALSE;
1027                 }
1028                 if (d_ptr->m_a_ability_flags2)
1029                 {
1030                         if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
1031                                 return FALSE;
1032                 }
1033                 if (d_ptr->mflags7)
1034                 {
1035                         if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
1036                                 return FALSE;
1037                 }
1038                 if (d_ptr->mflags8)
1039                 {
1040                         if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
1041                                 return FALSE;
1042                 }
1043                 if (d_ptr->mflags9)
1044                 {
1045                         if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
1046                                 return FALSE;
1047                 }
1048                 if (d_ptr->mflagsr)
1049                 {
1050                         if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
1051                                 return FALSE;
1052                 }
1053                 for (a = 0; a < 5; a++)
1054                         if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE;
1055
1056                 return TRUE;
1057
1058         case DUNGEON_MODE_NAND:
1059                 if (d_ptr->mflags1)
1060                 {
1061                         if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
1062                                 return TRUE;
1063                 }
1064                 if (d_ptr->mflags2)
1065                 {
1066                         if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
1067                                 return TRUE;
1068                 }
1069                 if (d_ptr->mflags3)
1070                 {
1071                         if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
1072                                 return TRUE;
1073                 }
1074                 if (d_ptr->mflags4)
1075                 {
1076                         if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
1077                                 return TRUE;
1078                 }
1079                 if (d_ptr->m_a_ability_flags1)
1080                 {
1081                         if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
1082                                 return TRUE;
1083                 }
1084                 if (d_ptr->m_a_ability_flags2)
1085                 {
1086                         if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
1087                                 return TRUE;
1088                 }
1089                 if (d_ptr->mflags7)
1090                 {
1091                         if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
1092                                 return TRUE;
1093                 }
1094                 if (d_ptr->mflags8)
1095                 {
1096                         if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
1097                                 return TRUE;
1098                 }
1099                 if (d_ptr->mflags9)
1100                 {
1101                         if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
1102                                 return TRUE;
1103                 }
1104                 if (d_ptr->mflagsr)
1105                 {
1106                         if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
1107                                 return TRUE;
1108                 }
1109                 for (a = 0; a < 5; a++)
1110                         if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return TRUE;
1111
1112                 return FALSE;
1113
1114         case DUNGEON_MODE_OR:
1115                 if (r_ptr->flags1 & d_ptr->mflags1) return TRUE;
1116                 if (r_ptr->flags2 & d_ptr->mflags2) return TRUE;
1117                 if (r_ptr->flags3 & d_ptr->mflags3) return TRUE;
1118                 if (r_ptr->flags4 & d_ptr->mflags4) return TRUE;
1119                 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return TRUE;
1120                 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return TRUE;
1121                 if (r_ptr->flags7 & d_ptr->mflags7) return TRUE;
1122                 if (r_ptr->flags8 & d_ptr->mflags8) return TRUE;
1123                 if (r_ptr->flags9 & d_ptr->mflags9) return TRUE;
1124                 if (r_ptr->flagsr & d_ptr->mflagsr) return TRUE;
1125                 for (a = 0; a < 5; a++)
1126                         if (d_ptr->r_char[a] == r_ptr->d_char) return TRUE;
1127
1128                 return FALSE;
1129
1130         case DUNGEON_MODE_NOR:
1131                 if (r_ptr->flags1 & d_ptr->mflags1) return FALSE;
1132                 if (r_ptr->flags2 & d_ptr->mflags2) return FALSE;
1133                 if (r_ptr->flags3 & d_ptr->mflags3) return FALSE;
1134                 if (r_ptr->flags4 & d_ptr->mflags4) return FALSE;
1135                 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return FALSE;
1136                 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return FALSE;
1137                 if (r_ptr->flags7 & d_ptr->mflags7) return FALSE;
1138                 if (r_ptr->flags8 & d_ptr->mflags8) return FALSE;
1139                 if (r_ptr->flags9 & d_ptr->mflags9) return FALSE;
1140                 if (r_ptr->flagsr & d_ptr->mflagsr) return FALSE;
1141                 for (a = 0; a < 5; a++)
1142                         if (d_ptr->r_char[a] == r_ptr->d_char) return FALSE;
1143
1144                 return TRUE;
1145         }
1146
1147         return TRUE;
1148 }
1149
1150 /*!
1151  * @brief モンスター生成制限関数最大2つから / Apply a "monster restriction function" to the "monster allocation table"
1152  * @param monster_hook 制限関数1
1153  * @param monster_hook2 制限関数2
1154  * @return エラーコード
1155  */
1156 errr get_mon_num_prep(monster_hook_type monster_hook,
1157                                           monster_hook_type monster_hook2)
1158 {
1159         int i;
1160
1161         /* Todo: Check the hooks for non-changes */
1162
1163         /* Set the new hooks */
1164         get_mon_num_hook = monster_hook;
1165         get_mon_num2_hook = monster_hook2;
1166
1167         /* Scan the allocation table */
1168         for (i = 0; i < alloc_race_size; i++)
1169         {
1170                 monster_race    *r_ptr;
1171                 
1172                 /* Get the entry */
1173                 alloc_entry *entry = &alloc_race_table[i];
1174
1175                 entry->prob2 = 0;
1176                 r_ptr = &r_info[entry->index];
1177
1178                 /* Skip monsters which don't pass the restriction */
1179                 if ((get_mon_num_hook && !((*get_mon_num_hook)(entry->index))) ||
1180                     (get_mon_num2_hook && !((*get_mon_num2_hook)(entry->index))))
1181                         continue;
1182
1183                 if (!p_ptr->inside_battle && !chameleon_change_m_idx &&
1184                     summon_specific_type != SUMMON_GUARDIANS)
1185                 {
1186                         /* Hack -- don't create questors */
1187                         if (r_ptr->flags1 & RF1_QUESTOR)
1188                                 continue;
1189
1190                         if (r_ptr->flags7 & RF7_GUARDIAN)
1191                                 continue;
1192
1193                         /* Depth Monsters never appear out of depth */
1194                         if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) &&
1195                             (r_ptr->level > dun_level))
1196                                 continue;
1197                 }
1198
1199                 /* Accept this monster */
1200                 entry->prob2 = entry->prob1;
1201
1202                 if (dun_level && (!p_ptr->inside_quest || is_fixed_quest_idx(p_ptr->inside_quest)) && !restrict_monster_to_dungeon(entry->index) && !p_ptr->inside_battle)
1203                 {
1204                         int hoge = entry->prob2 * d_info[dungeon_type].special_div;
1205                         entry->prob2 = hoge / 64;
1206                         if (randint0(64) < (hoge & 0x3f)) entry->prob2++;
1207                 }
1208         }
1209
1210         /* Success */
1211         return (0);
1212 }
1213
1214 /*!
1215  * @brief 平方根を切り捨て整数で返す
1216  * @param n 数値
1217  * @return 平方根
1218  */
1219 static int mysqrt(int n)
1220 {
1221         int tmp = n>>1;
1222         int tasu = 10;
1223         int kaeriti = 1;
1224
1225         if (!tmp)
1226         {
1227                 if (n) return 1;
1228                 else return 0;
1229         }
1230
1231         while(tmp)
1232         {
1233                 if ((n/tmp) < tmp)
1234                 {
1235                         tmp >>= 1;
1236                 }
1237                 else break;
1238         }
1239         kaeriti = tmp;
1240         while(tasu)
1241         {
1242                 if ((n/tmp) < tmp)
1243                 {
1244                         tasu--;
1245                         tmp = kaeriti;
1246                 }
1247                 else
1248                 {
1249                         kaeriti = tmp;
1250                         tmp += tasu;
1251                 }
1252         }
1253         return kaeriti;
1254 }
1255
1256 /*!
1257  * @brief 生成モンスター種族を1種生成テーブルから選択する
1258  * @param level 生成階
1259  * @return 選択されたモンスター生成種族
1260  * @details
1261  * Choose a monster race that seems "appropriate" to the given level
1262  *
1263  * This function uses the "prob2" field of the "monster allocation table",
1264  * and various local information, to calculate the "prob3" field of the
1265  * same table, which is then used to choose an "appropriate" monster, in
1266  * a relatively efficient manner.
1267  *
1268  * Note that "town" monsters will *only* be created in the town, and
1269  * "normal" monsters will *never* be created in the town, unless the
1270  * "level" is "modified", for example, by polymorph or summoning.
1271  *
1272  * There is a small chance (1/50) of "boosting" the given depth by
1273  * a small amount (up to four levels), except in the town.
1274  *
1275  * It is (slightly) more likely to acquire a monster of the given level
1276  * than one of a lower level.  This is done by choosing several monsters
1277  * appropriate to the given level and keeping the "hardest" one.
1278  *
1279  * Note that if no monsters are "appropriate", then this function will
1280  * fail, and return zero, but this should *almost* never happen.
1281  */
1282 MONRACE_IDX get_mon_num(DEPTH level)
1283 {
1284         int                     i, j, p;
1285         int                     r_idx;
1286         long            value, total;
1287         monster_race    *r_ptr;
1288         alloc_entry             *table = alloc_race_table;
1289
1290         int pls_kakuritu, pls_level;
1291         int delay = mysqrt(level * 10000L) + 400L;
1292
1293         if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
1294
1295         pls_kakuritu = MAX(NASTY_MON_MAX, NASTY_MON_BASE - ((dungeon_turn / (TURNS_PER_TICK * 5000L) - delay / 10)));
1296         pls_level    = MIN(NASTY_MON_PLUS_MAX, 3 + dungeon_turn / (TURNS_PER_TICK * 40000L) - delay / 40 + MIN(5, level / 10)) ;
1297
1298         if (d_info[dungeon_type].flags1 & DF1_MAZE)
1299         {
1300                 pls_kakuritu = MIN(pls_kakuritu / 2, pls_kakuritu - 10);
1301                 if (pls_kakuritu < 2) pls_kakuritu = 2;
1302                 pls_level += 2;
1303                 level += 3;
1304         }
1305
1306         /* Boost the level */
1307         if (!p_ptr->inside_battle && !(d_info[dungeon_type].flags1 & DF1_BEGINNER))
1308         {
1309                 /* Nightmare mode allows more out-of depth monsters */
1310                 if (ironman_nightmare && !randint0(pls_kakuritu))
1311                 {
1312                         /* What a bizarre calculation */
1313                         level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
1314                 }
1315                 else
1316                 {
1317                         /* Occasional "nasty" monster */
1318                         if (!randint0(pls_kakuritu))
1319                         {
1320                                 /* Pick a level bonus */
1321                                 level += pls_level;
1322                         }
1323                 }
1324         }
1325
1326         /* Reset total */
1327         total = 0L;
1328
1329         /* Process probabilities */
1330         for (i = 0; i < alloc_race_size; i++)
1331         {
1332                 /* Monsters are sorted by depth */
1333                 if (table[i].level > level) break;
1334
1335                 /* Default */
1336                 table[i].prob3 = 0;
1337
1338                 /* Access the "r_idx" of the chosen monster */
1339                 r_idx = table[i].index;
1340
1341                 /* Access the actual race */
1342                 r_ptr = &r_info[r_idx];
1343
1344                 if (!p_ptr->inside_battle && !chameleon_change_m_idx)
1345                 {
1346                         /* Hack -- "unique" monsters must be "unique" */
1347                         if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
1348                              (r_ptr->flags7 & (RF7_NAZGUL))) &&
1349                             (r_ptr->cur_num >= r_ptr->max_num))
1350                         {
1351                                 continue;
1352                         }
1353
1354                         if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
1355                             (r_ptr->cur_num >= 1))
1356                         {
1357                                 continue;
1358                         }
1359
1360                         if (r_idx == MON_BANORLUPART)
1361                         {
1362                                 if (r_info[MON_BANOR].cur_num > 0) continue;
1363                                 if (r_info[MON_LUPART].cur_num > 0) continue;
1364                         }
1365                 }
1366
1367                 /* Accept */
1368                 table[i].prob3 = table[i].prob2;
1369
1370                 /* Total */
1371                 total += table[i].prob3;
1372         }
1373
1374         /* No legal monsters */
1375         if (total <= 0) return (0);
1376
1377         /* Pick a monster */
1378         value = randint0(total);
1379
1380         /* Find the monster */
1381         for (i = 0; i < alloc_race_size; i++)
1382         {
1383                 /* Found the entry */
1384                 if (value < table[i].prob3) break;
1385
1386                 /* Decrement */
1387                 value = value - table[i].prob3;
1388         }
1389
1390         /* Power boost */
1391         p = randint0(100);
1392
1393         /* Try for a "harder" monster once (50%) or twice (10%) */
1394         if (p < 60)
1395         {
1396                 /* Save old */
1397                 j = i;
1398
1399                 /* Pick a monster */
1400                 value = randint0(total);
1401
1402                 /* Find the monster */
1403                 for (i = 0; i < alloc_race_size; i++)
1404                 {
1405                         /* Found the entry */
1406                         if (value < table[i].prob3) break;
1407
1408                         /* Decrement */
1409                         value = value - table[i].prob3;
1410                 }
1411
1412                 /* Keep the "best" one */
1413                 if (table[i].level < table[j].level) i = j;
1414         }
1415
1416         /* Try for a "harder" monster twice (10%) */
1417         if (p < 10)
1418         {
1419                 /* Save old */
1420                 j = i;
1421
1422                 /* Pick a monster */
1423                 value = randint0(total);
1424
1425                 /* Find the monster */
1426                 for (i = 0; i < alloc_race_size; i++)
1427                 {
1428                         /* Found the entry */
1429                         if (value < table[i].prob3) break;
1430
1431                         /* Decrement */
1432                         value = value - table[i].prob3;
1433                 }
1434
1435                 /* Keep the "best" one */
1436                 if (table[i].level < table[j].level) i = j;
1437         }
1438         return (table[i].index);
1439 }
1440
1441
1442 /*!
1443  * @brief モンスターの呼称を作成する / Build a string describing a monster in some way.
1444  * @param desc 記述出力先の文字列参照ポインタ
1445  * @param m_ptr モンスターの参照ポインタ
1446  * @param mode 呼称オプション
1447  * @return なし
1448  * @details
1449  * We can correctly describe monsters based on their visibility.
1450  * We can force all monsters to be treated as visible or invisible.
1451  * We can build nominatives, objectives, possessives, or reflexives.
1452  * We can selectively pronominalize hidden, visible, or all monsters.
1453  * We can use definite or indefinite descriptions for hidden monsters.
1454  * We can use definite or indefinite descriptions for visible monsters.
1455  *
1456  * Pronominalization involves the gender whenever possible and allowed,
1457  * so that by cleverly requesting pronominalization / visibility, you
1458  * can get messages like "You hit someone.  She screams in agony!".
1459  *
1460  * Reflexives are acquired by requesting Objective plus Possessive.
1461  *
1462  * If no m_ptr arg is given (?), the monster is assumed to be hidden,
1463  * unless the "Assume Visible" mode is requested.
1464  *
1465  * If no r_ptr arg is given, it is extracted from m_ptr and r_info
1466  * If neither m_ptr nor r_ptr is given, the monster is assumed to
1467  * be neuter, singular, and hidden (unless "Assume Visible" is set),
1468  * in which case you may be in trouble... :-)
1469  *
1470  * I am assuming that no monster name is more than 70 characters long,
1471  * so that "char desc[80];" is sufficiently large for any result.
1472  *
1473  * Mode Flags:
1474  *  MD_OBJECTIVE      --> Objective (or Reflexive)
1475  *  MD_POSSESSIVE     --> Possessive (or Reflexive)
1476  *  MD_INDEF_HIDDEN   --> Use indefinites for hidden monsters ("something")
1477  *  MD_INDEF_VISIBLE  --> Use indefinites for visible monsters ("a kobold")
1478  *  MD_PRON_HIDDEN    --> Pronominalize hidden monsters
1479  *  MD_PRON_VISIBLE   --> Pronominalize visible monsters
1480  *  MD_ASSUME_HIDDEN  --> Assume the monster is hidden
1481  *  MD_ASSUME_VISIBLE --> Assume the monster is visible
1482  *  MD_TRUE_NAME      --> Chameleon's true name
1483  *  MD_IGNORE_HALLU   --> Ignore hallucination, and penetrate shape change
1484  *
1485  * Useful Modes:
1486  *  0x00 --> Full nominative name ("the kobold") or "it"
1487  *  MD_INDEF_HIDDEN --> Full nominative name ("the kobold") or "something"
1488  *  MD_ASSUME_VISIBLE --> Genocide resistance name ("the kobold")
1489  *  MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE --> Killing name ("a kobold")
1490  *  MD_PRON_VISIBLE | MD_POSSESSIVE
1491  *    --> Possessive, genderized if visable ("his") or "its"
1492  *  MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE
1493  *    --> Reflexive, genderized if visable ("himself") or "itself"
1494  */
1495 void monster_desc(char *desc, monster_type *m_ptr, BIT_FLAGS mode)
1496 {
1497         cptr            res;
1498         monster_race    *r_ptr;
1499
1500         cptr            name;
1501         char            buf[128];
1502         char            silly_name[1024];
1503         bool            seen, pron;
1504         bool            named = FALSE;
1505
1506         r_ptr = &r_info[m_ptr->ap_r_idx];
1507
1508         /* Mode of MD_TRUE_NAME will reveal Chameleon's true name */
1509         if (mode & MD_TRUE_NAME) name = (r_name + real_r_ptr(m_ptr)->name);
1510         else name = (r_name + r_ptr->name);
1511
1512         /* Are we hallucinating? (Idea from Nethack...) */
1513         if (p_ptr->image && !(mode & MD_IGNORE_HALLU))
1514         {
1515                 if (one_in_(2))
1516                 {
1517                         if (!get_rnd_line(_("silly_j.txt", "silly.txt"), m_ptr->r_idx, silly_name))
1518                                 named = TRUE;
1519                 }
1520
1521                 if (!named)
1522                 {
1523                         monster_race *hallu_race;
1524
1525                         do
1526                         {
1527                                 hallu_race = &r_info[randint1(max_r_idx - 1)];
1528                         }
1529                         while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
1530
1531                         strcpy(silly_name, (r_name + hallu_race->name));
1532                 }
1533
1534                 /* Better not strcpy it, or we could corrupt r_info... */
1535                 name = silly_name;
1536         }
1537
1538         /* Can we "see" it (exists + forced, or visible + not unforced) */
1539         seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml)));
1540
1541         /* Sexed Pronouns (seen and allowed, or unseen and allowed) */
1542         pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN))));
1543
1544
1545         /* First, try using pronouns, or describing hidden monsters */
1546         if (!seen || pron)
1547         {
1548                 /* an encoding of the monster "sex" */
1549                 int kind = 0x00;
1550
1551                 /* Extract the gender (if applicable) */
1552                 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1553                 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1554
1555                 /* Ignore the gender (if desired) */
1556                 if (!m_ptr || !pron) kind = 0x00;
1557
1558
1559                 /* Assume simple result */
1560                 res = _("何か", "it");
1561
1562                 /* Brute force: split on the possibilities */
1563                 switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE)))
1564                 {
1565                         /* Neuter, or unknown */
1566 #ifdef JP
1567                         case 0x00:                                                    res = "何か"; break;
1568                         case 0x00 + (MD_OBJECTIVE):                                   res = "何か"; break;
1569                         case 0x00 + (MD_POSSESSIVE):                                  res = "何かの"; break;
1570                         case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "何か自身"; break;
1571                         case 0x00 + (MD_INDEF_HIDDEN):                                res = "何か"; break;
1572                         case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "何か"; break;
1573                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "何か"; break;
1574                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "それ自身"; break;
1575 #else
1576                         case 0x00:                                                    res = "it"; break;
1577                         case 0x00 + (MD_OBJECTIVE):                                   res = "it"; break;
1578                         case 0x00 + (MD_POSSESSIVE):                                  res = "its"; break;
1579                         case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "itself"; break;
1580                         case 0x00 + (MD_INDEF_HIDDEN):                                res = "something"; break;
1581                         case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "something"; break;
1582                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "something's"; break;
1583                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1584 #endif
1585
1586
1587                         /* Male (assume human if vague) */
1588 #ifdef JP
1589                         case 0x10:                                                    res = "彼"; break;
1590                         case 0x10 + (MD_OBJECTIVE):                                   res = "彼"; break;
1591                         case 0x10 + (MD_POSSESSIVE):                                  res = "彼の"; break;
1592                         case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "彼自身"; break;
1593                         case 0x10 + (MD_INDEF_HIDDEN):                                res = "誰か"; break;
1594                         case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "誰か"; break;
1595                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "誰かの"; break;
1596                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "彼自身"; break;
1597 #else
1598                         case 0x10:                                                    res = "he"; break;
1599                         case 0x10 + (MD_OBJECTIVE):                                   res = "him"; break;
1600                         case 0x10 + (MD_POSSESSIVE):                                  res = "his"; break;
1601                         case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "himself"; break;
1602                         case 0x10 + (MD_INDEF_HIDDEN):                                res = "someone"; break;
1603                         case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "someone"; break;
1604                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "someone's"; break;
1605                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1606 #endif
1607
1608
1609                         /* Female (assume human if vague) */
1610 #ifdef JP
1611                         case 0x20:                                                    res = "彼女"; break;
1612                         case 0x20 + (MD_OBJECTIVE):                                   res = "彼女"; break;
1613                         case 0x20 + (MD_POSSESSIVE):                                  res = "彼女の"; break;
1614                         case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "彼女自身"; break;
1615                         case 0x20 + (MD_INDEF_HIDDEN):                                res = "誰か"; break;
1616                         case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "誰か"; break;
1617                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "誰かの"; break;
1618                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "彼女自身"; break;
1619 #else
1620                         case 0x20:                                                    res = "she"; break;
1621                         case 0x20 + (MD_OBJECTIVE):                                   res = "her"; break;
1622                         case 0x20 + (MD_POSSESSIVE):                                  res = "her"; break;
1623                         case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "herself"; break;
1624                         case 0x20 + (MD_INDEF_HIDDEN):                                res = "someone"; break;
1625                         case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "someone"; break;
1626                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "someone's"; break;
1627                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1628 #endif
1629                 }
1630
1631                 /* Copy the result */
1632                 (void)strcpy(desc, res);
1633         }
1634
1635
1636         /* Handle visible monsters, "reflexive" request */
1637         else if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE))
1638         {
1639                 /* The monster is visible, so use its gender */
1640 #ifdef JP
1641                 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, "彼女自身");
1642                 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, "彼自身");
1643                 else strcpy(desc, "それ自身");
1644 #else
1645                 if (r_ptr->flags1 & RF1_FEMALE) strcpy(desc, "herself");
1646                 else if (r_ptr->flags1 & RF1_MALE) strcpy(desc, "himself");
1647                 else strcpy(desc, "itself");
1648 #endif
1649         }
1650
1651
1652         /* Handle all other visible monster requests */
1653         else
1654         {
1655                 /* Tanuki? */
1656                 if (is_pet(m_ptr) && !is_original_ap(m_ptr))
1657                 {
1658 #ifdef JP
1659                         char *t;
1660                         strcpy(buf, name);
1661                         t = buf;
1662                         while(strncmp(t, "』", 2) && *t) t++;
1663                         if (*t)
1664                         {
1665                                 *t = '\0';
1666                                 (void)sprintf(desc, "%s?』", buf);
1667                         }
1668                         else
1669                                 (void)sprintf(desc, "%s?", name);
1670 #else
1671                         (void)sprintf(desc, "%s?", name);
1672 #endif
1673                 }
1674                 else
1675
1676                 /* It could be a Unique */
1677                 if ((r_ptr->flags1 & RF1_UNIQUE) && !(p_ptr->image && !(mode & MD_IGNORE_HALLU)))
1678                 {
1679                         /* Start with the name (thus nominative and objective) */
1680                         if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME))
1681                         {
1682 #ifdef JP
1683                                 char *t;
1684                                 strcpy(buf, name);
1685                                 t = buf;
1686                                 while (strncmp(t, "』", 2) && *t) t++;
1687                                 if (*t)
1688                                 {
1689                                         *t = '\0';
1690                                         (void)sprintf(desc, "%s?』", buf);
1691                                 }
1692                                 else
1693                                         (void)sprintf(desc, "%s?", name);
1694 #else
1695                                 (void)sprintf(desc, "%s?", name);
1696 #endif
1697                         }
1698
1699                         /* Inside monster arena, and it is not your mount */
1700                         else if (p_ptr->inside_battle &&
1701                                  !(p_ptr->riding && (&m_list[p_ptr->riding] == m_ptr)))
1702                         {
1703                                 /* It is a fake unique monster */
1704                                 (void)sprintf(desc, _("%sもどき", "fake %s"), name);
1705                         }
1706
1707                         else
1708                         {
1709                                 (void)strcpy(desc, name);
1710                         }
1711                 }
1712
1713                 /* It could be an indefinite monster */
1714                 else if (mode & MD_INDEF_VISIBLE)
1715                 {
1716                         /* XXX Check plurality for "some" */
1717
1718                         /* Indefinite monsters need an indefinite article */
1719 #ifdef JP
1720                         (void)strcpy(desc, "");
1721 #else
1722                         (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1723 #endif
1724
1725                         (void)strcat(desc, name);
1726                 }
1727
1728                 /* It could be a normal, definite, monster */
1729                 else
1730                 {
1731                         /* Definite monsters need a definite article */
1732                         if (is_pet(m_ptr))
1733                                 (void)strcpy(desc, _("あなたの", "your "));
1734                         else
1735                                 (void)strcpy(desc, _("", "the "));
1736
1737                         (void)strcat(desc, name);
1738                 }
1739
1740                 if (m_ptr->nickname)
1741                 {
1742                         sprintf(buf,_("「%s」", " called %s"),quark_str(m_ptr->nickname));
1743                         strcat(desc,buf);
1744                 }
1745
1746                 if (p_ptr->riding && (&m_list[p_ptr->riding] == m_ptr))
1747                 {
1748                         strcat(desc,_("(乗馬中)", "(riding)"));
1749                 }
1750
1751                 if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1752                 {
1753                         if (r_ptr->flags1 & RF1_UNIQUE)
1754                         {
1755                                 strcat(desc,_("(カメレオンの王)", "(Chameleon Lord)"));
1756                         }
1757                         else
1758                         {
1759                                 strcat(desc,_("(カメレオン)", "(Chameleon)"));
1760                         }
1761                 }
1762
1763                 if ((mode & MD_IGNORE_HALLU) && !is_original_ap(m_ptr))
1764                 {
1765                         strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1766                 }
1767
1768                 /* Handle the Possessive as a special afterthought */
1769                 if (mode & MD_POSSESSIVE)
1770                 {
1771                         /* XXX Check for trailing "s" */
1772                         
1773                         /* Simply append "apostrophe" and "s" */
1774                         (void)strcat(desc, _("の", "'s"));
1775                 }
1776         }
1777 }
1778
1779
1780
1781 /*!
1782  * @brief モンスターの調査による思い出補完処理 / Learn about a monster (by "probing" it)
1783  * @param r_idx 補完されるモンスター種族ID
1784  * @return 明らかになった情報の度数
1785  * @details
1786  * Return the number of new flags learnt.  -Mogami-
1787  */
1788 int lore_do_probe(MONRACE_IDX r_idx)
1789 {
1790         monster_race *r_ptr = &r_info[r_idx];
1791         int i, n = 0;
1792         byte tmp_byte;
1793
1794         /* Maximal info about awareness */
1795         if (r_ptr->r_wake != MAX_UCHAR) n++;
1796         if (r_ptr->r_ignore != MAX_UCHAR) n++;
1797         r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1798
1799         /* Observe "maximal" attacks */
1800         for (i = 0; i < 4; i++)
1801         {
1802                 /* Examine "actual" blows */
1803                 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1804                 {
1805                         /* Maximal observations */
1806                         if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1807                         r_ptr->r_blows[i] = MAX_UCHAR;
1808                 }
1809         }
1810
1811         /* Maximal drops */
1812         tmp_byte =
1813                 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1814                  ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1815                  ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1816                  ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1817                  ((r_ptr->flags1 & RF1_DROP_90)  ? 1 : 0) +
1818                  ((r_ptr->flags1 & RF1_DROP_60)  ? 1 : 0));
1819
1820         /* Only "valid" drops */
1821         if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1822         {
1823                 if (r_ptr->r_drop_item != tmp_byte) n++;
1824                 r_ptr->r_drop_item = tmp_byte;
1825         }
1826         if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1827         {
1828                 if (r_ptr->r_drop_gold != tmp_byte) n++;
1829                 r_ptr->r_drop_gold = tmp_byte;
1830         }
1831
1832         /* Observe many spells */
1833         if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1834         r_ptr->r_cast_spell = MAX_UCHAR;
1835
1836         /* Count unknown flags */
1837         for (i = 0; i < 32; i++)
1838         {
1839                 if (!(r_ptr->r_flags1 & (1L << i)) &&
1840                     (r_ptr->flags1 & (1L << i))) n++;
1841                 if (!(r_ptr->r_flags2 & (1L << i)) &&
1842                     (r_ptr->flags2 & (1L << i))) n++;
1843                 if (!(r_ptr->r_flags3 & (1L << i)) &&
1844                     (r_ptr->flags3 & (1L << i))) n++;
1845                 if (!(r_ptr->r_flags4 & (1L << i)) &&
1846                     (r_ptr->flags4 & (1L << i))) n++;
1847                 if (!(r_ptr->r_flags5 & (1L << i)) &&
1848                     (r_ptr->a_ability_flags1 & (1L << i))) n++;
1849                 if (!(r_ptr->r_flags6 & (1L << i)) &&
1850                     (r_ptr->a_ability_flags2 & (1L << i))) n++;
1851                 if (!(r_ptr->r_flagsr & (1L << i)) &&
1852                     (r_ptr->flagsr & (1L << i))) n++;
1853
1854                 /* r_flags7 is actually unused */
1855 #if 0
1856                 if (!(r_ptr->r_flags7 & (1L << i)) &&
1857                     (r_ptr->flags7 & (1L << i))) n++;
1858 #endif
1859         }
1860
1861         /* Know all the flags */
1862         r_ptr->r_flags1 = r_ptr->flags1;
1863         r_ptr->r_flags2 = r_ptr->flags2;
1864         r_ptr->r_flags3 = r_ptr->flags3;
1865         r_ptr->r_flags4 = r_ptr->flags4;
1866         r_ptr->r_flags5 = r_ptr->a_ability_flags1;
1867         r_ptr->r_flags6 = r_ptr->a_ability_flags2;
1868         r_ptr->r_flagsr = r_ptr->flagsr;
1869
1870         /* r_flags7 is actually unused */
1871         /* r_ptr->r_flags7 = r_ptr->flags7; */
1872
1873         /* Know about evolution */
1874         if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1875         r_ptr->r_xtra1 |= MR1_SINKA;
1876
1877         /* Update monster recall window */
1878         if (p_ptr->monster_race_idx == r_idx)
1879         {
1880                 p_ptr->window |= (PW_MONSTER);
1881         }
1882
1883         /* Return the number of new flags learnt */
1884         return n;
1885 }
1886
1887
1888 /*!
1889  * @brief モンスターの撃破に伴うドロップ情報の保管処理 / Take note that the given monster just dropped some treasure
1890  * @param m_idx モンスター情報のID
1891  * @param num_item 手に入れたアイテム数
1892  * @param num_gold 手に入れた財宝の単位数
1893  * @return なし
1894  * @details
1895  * Note that learning the "GOOD"/"GREAT" flags gives information
1896  * about the treasure (even when the monster is killed for the first
1897  * time, such as uniques, and the treasure has not been examined yet).
1898  *
1899  * This "indirect" method is used to prevent the player from learning
1900  * exactly how much treasure a monster can drop from observing only
1901  * a single example of a drop.  This method actually observes how much
1902  * gold and items are dropped, and remembers that information to be
1903  * described later by the monster recall code.
1904  */
1905 void lore_treasure(MONSTER_IDX m_idx, ITEM_NUMBER num_item, ITEM_NUMBER num_gold)
1906 {
1907         monster_type *m_ptr = &m_list[m_idx];
1908
1909         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1910
1911         /* If the monster doesn't have original appearance, don't note */
1912         if (!is_original_ap(m_ptr)) return;
1913
1914         /* Note the number of things dropped */
1915         if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1916         if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1917
1918         /* Hack -- memorize the good/great flags */
1919         if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1920         if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1921
1922         /* Update monster recall window */
1923         if (p_ptr->monster_race_idx == m_ptr->r_idx)
1924         {
1925                 p_ptr->window |= (PW_MONSTER);
1926         }
1927 }
1928
1929
1930 /*!
1931  * @brief ELDRITCH_HORRORによるプレイヤーの精神破壊処理
1932  * @param m_ptr ELDRITCH_HORRORを引き起こしたモンスターの参照ポインタ
1933  * @param necro 暗黒領域魔法の詠唱失敗によるものならばTRUEを返す
1934  * @return なし
1935  */
1936 void sanity_blast(monster_type *m_ptr, bool necro)
1937 {
1938         int power = 100;
1939
1940         if (p_ptr->inside_battle || !character_dungeon) return;
1941
1942         if (!necro && m_ptr)
1943         {
1944                 char m_name[80];
1945                 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1946
1947                 power = r_ptr->level / 2;
1948
1949                 monster_desc(m_name, m_ptr, 0);
1950
1951                 if (!(r_ptr->flags1 & RF1_UNIQUE))
1952                 {
1953                         if (r_ptr->flags1 & RF1_FRIENDS)
1954                         power /= 2;
1955                 }
1956                 else power *= 2;
1957
1958                 if (!is_loading_now)
1959                         return; /* No effect yet, just loaded... */
1960
1961                 if (!m_ptr->ml)
1962                         return; /* Cannot see it for some reason */
1963
1964                 if (!(r_ptr->flags2 & RF2_ELDRITCH_HORROR))
1965                         return;
1966
1967                 if (is_pet(m_ptr))
1968                         return; /* Pet eldritch horrors are safe most of the time */
1969
1970                 if (randint1(100) > power) return;
1971
1972                 if (saving_throw(p_ptr->skill_sav - power))
1973                 {
1974                         return; /* Save, no adverse effects */
1975                 }
1976
1977                 if (p_ptr->image)
1978                 {
1979                         /* Something silly happens... */
1980 #ifdef JP
1981                         msg_format("%s%sの顔を見てしまった!",
1982                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
1983 #else
1984                         msg_format("You behold the %s visage of %s!",
1985                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
1986 #endif
1987
1988                         if (one_in_(3))
1989                         {
1990                                 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
1991                                 p_ptr->image = p_ptr->image + randint1(r_ptr->level);
1992                         }
1993
1994                         return; /* Never mind; we can't see it clearly enough */
1995                 }
1996
1997                 /* Something frightening happens... */
1998 #ifdef JP
1999                 msg_format("%s%sの顔を見てしまった!",
2000                         horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2001 #else
2002                 msg_format("You behold the %s visage of %s!",
2003                         horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2004 #endif
2005
2006                 r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
2007
2008                 /* Demon characters are unaffected */
2009                 if (prace_is_(RACE_IMP) || prace_is_(RACE_DEMON) || (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) return;
2010                 if (p_ptr->wizard) return;
2011
2012                 /* Undead characters are 50% likely to be unaffected */
2013                 if (prace_is_(RACE_SKELETON) || prace_is_(RACE_ZOMBIE)
2014                         || prace_is_(RACE_VAMPIRE) || prace_is_(RACE_SPECTRE) ||
2015                     (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD))
2016                 {
2017                         if (saving_throw(25 + p_ptr->lev)) return;
2018                 }
2019         }
2020         else if(!necro)
2021         {
2022                 monster_race *r_ptr;
2023                 char m_name[80];
2024                 cptr desc;
2025
2026                 get_mon_num_prep(get_nightmare, NULL);
2027
2028                 r_ptr = &r_info[get_mon_num(MAX_DEPTH)];
2029                 power = r_ptr->level + 10;
2030                 desc = r_name + r_ptr->name;
2031
2032                 get_mon_num_prep(NULL, NULL);
2033
2034                 /* Describe it */
2035 #ifndef JP
2036                 if (!(r_ptr->flags1 & RF1_UNIQUE))
2037                         sprintf(m_name, "%s %s", (is_a_vowel(desc[0]) ? "an" : "a"), desc);
2038                 else
2039 #endif
2040                 sprintf(m_name, "%s", desc);
2041
2042                 if (!(r_ptr->flags1 & RF1_UNIQUE))
2043                 {
2044                         if (r_ptr->flags1 & RF1_FRIENDS) power /= 2;
2045                 }
2046                 else power *= 2;
2047
2048                 if (saving_throw(p_ptr->skill_sav * 100 / power))
2049                 {
2050                         msg_format(_("夢の中で%sに追いかけられた。", "%^s chases you through your dreams."), m_name);
2051                         /* Safe */
2052                         return;
2053                 }
2054
2055                 if (p_ptr->image)
2056                 {
2057                         /* Something silly happens... */
2058                         msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"),
2059                                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2060
2061                         if (one_in_(3))
2062                         {
2063                                 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
2064                                 p_ptr->image = p_ptr->image + randint1(r_ptr->level);
2065                         }
2066
2067                         /* Never mind; we can't see it clearly enough */
2068                         return;
2069                 }
2070
2071                 /* Something frightening happens... */
2072                 msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"),
2073                                   horror_desc[randint0(MAX_SAN_HORROR)], desc);
2074
2075                 r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
2076
2077                 if (!p_ptr->mimic_form)
2078                 {
2079                         switch (p_ptr->prace)
2080                         {
2081                         /* Demons may make a saving throw */
2082                         case RACE_IMP:
2083                         case RACE_DEMON:
2084                                 if (saving_throw(20 + p_ptr->lev)) return;
2085                                 break;
2086                         /* Undead may make a saving throw */
2087                         case RACE_SKELETON:
2088                         case RACE_ZOMBIE:
2089                         case RACE_SPECTRE:
2090                         case RACE_VAMPIRE:
2091                                 if (saving_throw(10 + p_ptr->lev)) return;
2092                                 break;
2093                         }
2094                 }
2095                 else
2096                 {
2097                         /* Demons may make a saving throw */
2098                         if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)
2099                         {
2100                                 if (saving_throw(20 + p_ptr->lev)) return;
2101                         }
2102                         /* Undead may make a saving throw */
2103                         else if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD)
2104                         {
2105                                 if (saving_throw(10 + p_ptr->lev)) return;
2106                         }
2107                 }
2108         }
2109         else
2110         {
2111                 msg_print(_("ネクロノミコンを読んで正気を失った!", "Your sanity is shaken by reading the Necronomicon!"));
2112         }
2113
2114         if (saving_throw(p_ptr->skill_sav - power))
2115         {
2116                 return;
2117         }
2118
2119         do {
2120                 (void)do_dec_stat(A_INT);
2121         } while (randint0(100) > p_ptr->skill_sav && one_in_(2));
2122
2123         do {
2124                 (void)do_dec_stat(A_WIS);
2125         } while (randint0(100) > p_ptr->skill_sav && one_in_(2));
2126
2127         switch (randint1(21))
2128         {
2129         case 1:
2130                 if (!(p_ptr->muta3 & MUT3_MORONIC) && one_in_(5))
2131                 {
2132                         if ((p_ptr->stat_use[A_INT] < 4) && (p_ptr->stat_use[A_WIS] < 4))
2133                         {
2134                                 msg_print(_("あなたは完璧な馬鹿になったような気がした。しかしそれは元々だった。", "You turn into an utter moron!"));
2135                         }
2136                         else
2137                         {
2138                                 msg_print(_("あなたは完璧な馬鹿になった!", "You turn into an utter moron!"));
2139                         }
2140
2141                         if (p_ptr->muta3 & MUT3_HYPER_INT)
2142                         {
2143                                 msg_print(_("あなたの脳は生体コンピュータではなくなった。", "Your brain is no longer a living computer."));
2144                                 p_ptr->muta3 &= ~(MUT3_HYPER_INT);
2145                         }
2146                         p_ptr->muta3 |= MUT3_MORONIC;
2147                 }
2148                 break;
2149         case 2:
2150         case 3:
2151         case 4:
2152                 if (!(p_ptr->muta2 & MUT2_COWARDICE) && !p_ptr->resist_fear)
2153                 {
2154                         msg_print(_("あなたはパラノイアになった!", "You become paranoid!"));
2155
2156                         /* Duh, the following should never happen, but anyway... */
2157                         if (p_ptr->muta3 & MUT3_FEARLESS)
2158                         {
2159                                 msg_print(_("あなたはもう恐れ知らずではなくなった。", "You are no longer fearless."));
2160                                 p_ptr->muta3 &= ~(MUT3_FEARLESS);
2161                         }
2162
2163                         p_ptr->muta2 |= MUT2_COWARDICE;
2164                 }
2165                 break;
2166         case 5:
2167         case 6:
2168         case 7:
2169                 if (!(p_ptr->muta2 & MUT2_HALLU) && !p_ptr->resist_chaos)
2170                 {
2171                         msg_print(_("幻覚をひき起こす精神錯乱に陥った!", "You are afflicted by a hallucinatory insanity!"));
2172                         p_ptr->muta2 |= MUT2_HALLU;
2173                 }
2174                 break;
2175         case 8:
2176         case 9:
2177         case 10:
2178                 if (!(p_ptr->muta2 & MUT2_BERS_RAGE))
2179                 {
2180                         msg_print(_("激烈な感情の発作におそわれるようになった!", "You become subject to fits of berserk rage!"));
2181                         p_ptr->muta2 |= MUT2_BERS_RAGE;
2182                 }
2183                 break;
2184         case 11:
2185         case 12:
2186         case 13:
2187         case 14:
2188         case 15:
2189         case 16:
2190                 /* Brain smash */
2191                 if (!p_ptr->resist_conf)
2192                 {
2193                         (void)set_confused(p_ptr->confused + randint0(4) + 4);
2194                 }
2195                 if (!p_ptr->free_act)
2196                 {
2197                         (void)set_paralyzed(p_ptr->paralyzed + randint0(4) + 4);
2198                 }
2199                 if (!p_ptr->resist_chaos)
2200                 {
2201                         (void)set_image(p_ptr->image + randint0(250) + 150);
2202                 }
2203                 break;
2204         case 17:
2205         case 18:
2206         case 19:
2207         case 20:
2208         case 21:
2209                 /* Amnesia */
2210                 if (lose_all_info())
2211                         msg_print(_("あまりの恐怖に全てのことを忘れてしまった!", "You forget everything in your utmost terror!"));
2212                 break;
2213         }
2214
2215         p_ptr->update |= PU_BONUS;
2216         handle_stuff();
2217 }
2218
2219 /*!
2220  * @brief モンスターの各情報を更新する / This function updates the monster record of the given monster
2221  * @param m_idx 更新するモンスター情報のID
2222  * @param full プレイヤーとの距離更新を行うならばtrue
2223  * @return なし
2224  * @details
2225  * This involves extracting the distance to the player (if requested),
2226  * and then checking for visibility (natural, infravision, see-invis,
2227  * telepathy), updating the monster visibility flag, redrawing (or
2228  * erasing) the monster when its visibility changes, and taking note
2229  * of any interesting monster flags (cold-blooded, invisible, etc).
2230  *
2231  * Note the new "mflag" field which encodes several monster state flags,
2232  * including "view" for when the monster is currently in line of sight,
2233  * and "mark" for when the monster is currently visible via detection.
2234  *
2235  * The only monster fields that are changed here are "cdis" (the
2236  * distance from the player), "ml" (visible to the player), and
2237  * "mflag" (to maintain the "MFLAG_VIEW" flag).
2238  *
2239  * Note the special "update_monsters()" function which can be used to
2240  * call this function once for every monster.
2241  *
2242  * Note the "full" flag which requests that the "cdis" field be updated,
2243  * this is only needed when the monster (or the player) has moved.
2244  *
2245  * Every time a monster moves, we must call this function for that
2246  * monster, and update the distance, and the visibility.  Every time
2247  * the player moves, we must call this function for every monster, and
2248  * update the distance, and the visibility.  Whenever the player "state"
2249  * changes in certain ways ("blindness", "infravision", "telepathy",
2250  * and "see invisible"), we must call this function for every monster,
2251  * and update the visibility.
2252  *
2253  * Routines that change the "illumination" of a grid must also call this
2254  * function for any monster in that grid, since the "visibility" of some
2255  * monsters may be based on the illumination of their grid.
2256  *
2257  * Note that this function is called once per monster every time the
2258  * player moves.  When the player is running, this function is one
2259  * of the primary bottlenecks, along with "update_view()" and the
2260  * "process_monsters()" code, so efficiency is important.
2261  *
2262  * Note the optimized "inline" version of the "distance()" function.
2263  *
2264  * A monster is "visible" to the player if (1) it has been detected
2265  * by the player, (2) it is close to the player and the player has
2266  * telepathy, or (3) it is close to the player, and in line of sight
2267  * of the player, and it is "illuminated" by some combination of
2268  * infravision, torch light, or permanent light (invisible monsters
2269  * are only affected by "light" if the player can see invisible).
2270  *
2271  * Monsters which are not on the current panel may be "visible" to
2272  * the player, and their descriptions will include an "offscreen"
2273  * reference.  Currently, offscreen monsters cannot be targetted
2274  * or viewed directly, but old targets will remain set.  XXX XXX
2275  *
2276  * The player can choose to be disturbed by several things, including
2277  * "disturb_move" (monster which is viewable moves in some way), and
2278  * "disturb_near" (monster which is "easily" viewable moves in some
2279  * way).  Note that "moves" includes "appears" and "disappears".
2280  */
2281 void update_monster(MONSTER_IDX m_idx, bool full)
2282 {
2283         monster_type *m_ptr = &m_list[m_idx];
2284
2285         monster_race *r_ptr = &r_info[m_ptr->r_idx];
2286
2287         bool do_disturb = disturb_move;
2288
2289         int d;
2290
2291         /* Current location */
2292         int fy = m_ptr->fy;
2293         int fx = m_ptr->fx;
2294
2295         /* Seen at all */
2296         bool flag = FALSE;
2297
2298         /* Seen by vision */
2299         bool easy = FALSE;
2300
2301         /* Non-Ninja player in the darkness */
2302         bool in_darkness = (d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto;
2303
2304         /* Do disturb? */
2305         if (disturb_high)
2306         {
2307                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2308
2309                 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
2310                         do_disturb = TRUE;
2311         }
2312
2313         /* Compute distance */
2314         if (full)
2315         {
2316                 /* Distance components */
2317                 int dy = (p_ptr->y > fy) ? (p_ptr->y - fy) : (fy - p_ptr->y);
2318                 int dx = (p_ptr->x > fx) ? (p_ptr->x - fx) : (fx - p_ptr->x);
2319
2320                 /* Approximate distance */
2321                 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2322
2323                 /* Restrict distance */
2324                 if (d > 255) d = 255;
2325
2326                 if (!d) d = 1;
2327
2328                 /* Save the distance */
2329                 m_ptr->cdis = d;
2330         }
2331
2332         /* Extract distance */
2333         else
2334         {
2335                 /* Extract the distance */
2336                 d = m_ptr->cdis;
2337         }
2338
2339
2340         /* Detected */
2341         if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
2342
2343
2344         /* Nearby */
2345         if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
2346         {
2347                 if (!in_darkness || (d <= MAX_SIGHT / 4))
2348                 {
2349                         if (p_ptr->special_defense & KATA_MUSOU)
2350                         {
2351                                 /* Detectable */
2352                                 flag = TRUE;
2353
2354                                 if (is_original_ap(m_ptr) && !p_ptr->image)
2355                                 {
2356                                         /* Hack -- Memorize mental flags */
2357                                         if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2358                                         if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2359                                 }
2360                         }
2361
2362                         /* Basic telepathy */
2363                         /* Snipers get telepathy when they concentrate deeper */
2364                         else if (p_ptr->telepathy)
2365                         {
2366                                 /* Empty mind, no telepathy */
2367                                 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
2368                                 {
2369                                         /* Memorize flags */
2370                                         if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
2371                                 }
2372
2373                                 /* Weird mind, occasional telepathy */
2374                                 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
2375                                 {
2376                                         /* One in ten individuals are detectable */
2377                                         if ((m_idx % 10) == 5)
2378                                         {
2379                                                 /* Detectable */
2380                                                 flag = TRUE;
2381
2382                                                 if (is_original_ap(m_ptr) && !p_ptr->image)
2383                                                 {
2384                                                         /* Memorize flags */
2385                                                         r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
2386
2387                                                         /* Hack -- Memorize mental flags */
2388                                                         if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2389                                                         if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2390                                                 }
2391                                         }
2392                                 }
2393
2394                                 /* Normal mind, allow telepathy */
2395                                 else
2396                                 {
2397                                         /* Detectable */
2398                                         flag = TRUE;
2399
2400                                         if (is_original_ap(m_ptr) && !p_ptr->image)
2401                                         {
2402                                                 /* Hack -- Memorize mental flags */
2403                                                 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2404                                                 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2405                                         }
2406                                 }
2407                         }
2408
2409                         /* Magical sensing */
2410                         if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
2411                         {
2412                                 flag = TRUE;
2413                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ANIMAL);
2414                         }
2415
2416                         /* Magical sensing */
2417                         if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
2418                         {
2419                                 flag = TRUE;
2420                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_UNDEAD);
2421                         }
2422
2423                         /* Magical sensing */
2424                         if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
2425                         {
2426                                 flag = TRUE;
2427                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DEMON);
2428                         }
2429
2430                         /* Magical sensing */
2431                         if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
2432                         {
2433                                 flag = TRUE;
2434                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ORC);
2435                         }
2436
2437                         /* Magical sensing */
2438                         if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
2439                         {
2440                                 flag = TRUE;
2441                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_TROLL);
2442                         }
2443
2444                         /* Magical sensing */
2445                         if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
2446                         {
2447                                 flag = TRUE;
2448                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GIANT);
2449                         }
2450
2451                         /* Magical sensing */
2452                         if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
2453                         {
2454                                 flag = TRUE;
2455                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DRAGON);
2456                         }
2457
2458                         /* Magical sensing */
2459                         if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
2460                         {
2461                                 flag = TRUE;
2462                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_HUMAN);
2463                         }
2464
2465                         /* Magical sensing */
2466                         if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
2467                         {
2468                                 flag = TRUE;
2469                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_EVIL);
2470                         }
2471
2472                         /* Magical sensing */
2473                         if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
2474                         {
2475                                 flag = TRUE;
2476                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GOOD);
2477                         }
2478
2479                         /* Magical sensing */
2480                         if ((p_ptr->esp_nonliving) &&
2481                             ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
2482                         {
2483                                 flag = TRUE;
2484                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_NONLIVING);
2485                         }
2486
2487                         /* Magical sensing */
2488                         if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
2489                         {
2490                                 flag = TRUE;
2491                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags1 |= (RF1_UNIQUE);
2492                         }
2493                 }
2494
2495                 /* Normal line of sight, and not blind */
2496                 if (player_has_los_bold(fy, fx) && !p_ptr->blind)
2497                 {
2498                         bool do_invisible = FALSE;
2499                         bool do_cold_blood = FALSE;
2500
2501                         /* Snipers can see targets in darkness when they concentrate deeper */
2502                         if (p_ptr->concent >= CONCENT_RADAR_THRESHOLD)
2503                         {
2504                                 /* Easy to see */
2505                                 easy = flag = TRUE;
2506                         }
2507
2508                         /* Use "infravision" */
2509                         if (d <= p_ptr->see_infra)
2510                         {
2511                                 /* Handle "cold blooded" monsters */
2512                                 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
2513                                 {
2514                                         /* Take note */
2515                                         do_cold_blood = TRUE;
2516                                 }
2517
2518                                 /* Handle "warm blooded" monsters */
2519                                 else
2520                                 {
2521                                         /* Easy to see */
2522                                         easy = flag = TRUE;
2523                                 }
2524                         }
2525
2526                         /* Use "illumination" */
2527                         if (player_can_see_bold(fy, fx))
2528                         {
2529                                 /* Handle "invisible" monsters */
2530                                 if (r_ptr->flags2 & (RF2_INVISIBLE))
2531                                 {
2532                                         /* Take note */
2533                                         do_invisible = TRUE;
2534
2535                                         /* See invisible */
2536                                         if (p_ptr->see_inv)
2537                                         {
2538                                                 /* Easy to see */
2539                                                 easy = flag = TRUE;
2540                                         }
2541                                 }
2542
2543                                 /* Handle "normal" monsters */
2544                                 else
2545                                 {
2546                                         /* Easy to see */
2547                                         easy = flag = TRUE;
2548                                 }
2549                         }
2550
2551                         /* Visible */
2552                         if (flag)
2553                         {
2554                                 if (is_original_ap(m_ptr) && !p_ptr->image)
2555                                 {
2556                                         /* Memorize flags */
2557                                         if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2558                                         if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2559                                 }
2560                         }
2561                 }
2562         }
2563
2564
2565         /* The monster is now visible */
2566         if (flag)
2567         {
2568                 /* It was previously unseen */
2569                 if (!m_ptr->ml)
2570                 {
2571                         /* Mark as visible */
2572                         m_ptr->ml = TRUE;
2573
2574                         /* Draw the monster */
2575                         lite_spot(fy, fx);
2576
2577                         /* Update health bar as needed */
2578                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2579                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2580
2581                         /* Hack -- Count "fresh" sightings */
2582                         if (!p_ptr->image)
2583                         {
2584                                 if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2585                                         r_info[MON_KAGE].r_sights++;
2586                                 else if (is_original_ap(m_ptr) && (r_ptr->r_sights < MAX_SHORT))
2587                                         r_ptr->r_sights++;
2588                         }
2589
2590                         /* Eldritch Horror */
2591                         if (r_info[m_ptr->ap_r_idx].flags2 & RF2_ELDRITCH_HORROR)
2592                         {
2593                                 sanity_blast(m_ptr, FALSE);
2594                         }
2595
2596                         /* Disturb on appearance */
2597                         if (disturb_near && (projectable(m_ptr->fy, m_ptr->fx, p_ptr->y, p_ptr->x) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)))
2598                         {
2599                                 if (disturb_pets || is_hostile(m_ptr))
2600                                         disturb(TRUE, TRUE);
2601                         }
2602                 }
2603         }
2604
2605         /* The monster is not visible */
2606         else
2607         {
2608                 /* It was previously seen */
2609                 if (m_ptr->ml)
2610                 {
2611                         /* Mark as not visible */
2612                         m_ptr->ml = FALSE;
2613
2614                         /* Erase the monster */
2615                         lite_spot(fy, fx);
2616
2617                         /* Update health bar as needed */
2618                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2619                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2620
2621                         /* Disturb on disappearance */
2622                         if (do_disturb)
2623                         {
2624                                 if (disturb_pets || is_hostile(m_ptr))
2625                                         disturb(TRUE, TRUE);
2626                         }
2627                 }
2628         }
2629
2630
2631         /* The monster is now easily visible */
2632         if (easy)
2633         {
2634                 /* Change */
2635                 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2636                 {
2637                         /* Mark as easily visible */
2638                         m_ptr->mflag |= (MFLAG_VIEW);
2639
2640                         /* Disturb on appearance */
2641                         if (do_disturb)
2642                         {
2643                                 if (disturb_pets || is_hostile(m_ptr))
2644                                         disturb(TRUE, TRUE);
2645                         }
2646                 }
2647         }
2648
2649         /* The monster is not easily visible */
2650         else
2651         {
2652                 /* Change */
2653                 if (m_ptr->mflag & (MFLAG_VIEW))
2654                 {
2655                         /* Mark as not easily visible */
2656                         m_ptr->mflag &= ~(MFLAG_VIEW);
2657
2658                         /* Disturb on disappearance */
2659                         if (do_disturb)
2660                         {
2661                                 if (disturb_pets || is_hostile(m_ptr))
2662                                         disturb(TRUE, TRUE);
2663                         }
2664                 }
2665         }
2666 }
2667
2668
2669 /*!
2670  * @brief 単純に生存している全モンスターの更新処理を行う / This function simply updates all the (non-dead) monsters (see above).
2671  * @param full 距離更新を行うならtrue
2672  * @return なし
2673  */
2674 void update_monsters(bool full)
2675 {
2676         IDX i;
2677
2678         /* Update each (live) monster */
2679         for (i = 1; i < m_max; i++)
2680         {
2681                 monster_type *m_ptr = &m_list[i];
2682
2683                 /* Skip dead monsters */
2684                 if (!m_ptr->r_idx) continue;
2685                 update_monster(i, full);
2686         }
2687 }
2688
2689
2690 /*!
2691  * @brief カメレオンの王の変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2692  * @param r_idx モンスター種族ID
2693  * @return 対象にできるならtrueを返す
2694  */
2695 static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx)
2696 {
2697         monster_race *r_ptr = &r_info[r_idx];
2698         monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2699         monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2700
2701         if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2702         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2703
2704         if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2705
2706         if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
2707                 return FALSE;
2708
2709         if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2710
2711         /* Not born */
2712         if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2713         {
2714                 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
2715         }
2716
2717         /* Born now */
2718         else if (summon_specific_who > 0)
2719         {
2720                 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2721         }
2722
2723         return TRUE;
2724 }
2725
2726 /*!
2727  * @brief カメレオンの変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2728  * @param r_idx モンスター種族ID
2729  * @return 対象にできるならtrueを返す
2730  */
2731 static bool monster_hook_chameleon(MONRACE_IDX r_idx)
2732 {
2733         monster_race *r_ptr = &r_info[r_idx];
2734         monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2735         monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2736
2737         if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2738         if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2739         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2740         
2741         if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
2742                 return FALSE;
2743
2744         if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2745
2746         /* Not born */
2747         if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2748         {
2749                 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2750                 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2751                 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2752         }
2753
2754         /* Born now */
2755         else if (summon_specific_who > 0)
2756         {
2757                 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2758         }
2759
2760         return (*(get_monster_hook()))(r_idx);
2761 }
2762
2763 /*!
2764  * @brief モンスターの変身処理
2765  * @param m_idx 変身処理を受けるモンスター情報のID
2766  * @param born 生成時の初変身先指定ならばtrue
2767  * @param r_idx 旧モンスター種族のID
2768  * @return なし
2769  */
2770 void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
2771 {
2772         int oldmaxhp;
2773         monster_type *m_ptr = &m_list[m_idx];
2774         monster_race *r_ptr;
2775         char old_m_name[80];
2776         bool old_unique = FALSE;
2777         int old_r_idx = m_ptr->r_idx;
2778
2779         if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2780                 old_unique = TRUE;
2781         if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2782         r_ptr = &r_info[r_idx];
2783
2784         monster_desc(old_m_name, m_ptr, 0);
2785
2786         if (!r_idx)
2787         {
2788                 DEPTH level;
2789
2790                 chameleon_change_m_idx = m_idx;
2791                 if (old_unique)
2792                         get_mon_num_prep(monster_hook_chameleon_lord, NULL);
2793                 else
2794                         get_mon_num_prep(monster_hook_chameleon, NULL);
2795
2796                 if (old_unique)
2797                         level = r_info[MON_CHAMELEON_K].level;
2798                 else if (!dun_level)
2799                         level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
2800                 else
2801                         level = dun_level;
2802
2803                 if (d_info[dungeon_type].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
2804
2805                 r_idx = get_mon_num(level);
2806                 r_ptr = &r_info[r_idx];
2807
2808                 chameleon_change_m_idx = 0;
2809
2810                 /* Paranoia */
2811                 if (!r_idx) return;
2812         }
2813
2814         if (is_pet(m_ptr)) check_pets_num_and_align(m_ptr, FALSE);
2815
2816         m_ptr->r_idx = r_idx;
2817         m_ptr->ap_r_idx = r_idx;
2818         update_monster(m_idx, FALSE);
2819         lite_spot(m_ptr->fy, m_ptr->fx);
2820
2821         if ((r_info[old_r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) ||
2822             (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)))
2823                 p_ptr->update |= (PU_MON_LITE);
2824
2825         if (is_pet(m_ptr)) check_pets_num_and_align(m_ptr, TRUE);
2826
2827         if (born)
2828         {
2829                 /* Sub-alignment of a chameleon */
2830                 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2831                 {
2832                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2833                         if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2834                         if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2835                 }
2836                 return;
2837         }
2838
2839         if (m_idx == p_ptr->riding)
2840         {
2841                 char m_name[80];
2842                 monster_desc(m_name, m_ptr, 0);
2843                 msg_format(_("突然%sが変身した。", "Suddenly, %s transforms!"), old_m_name);
2844                 if (!(r_ptr->flags7 & RF7_RIDING))
2845                         if (rakuba(0, TRUE)) msg_format(_("地面に落とされた。", "You have fallen from %s."), m_name);
2846         }
2847
2848         /* Extract the monster base speed */
2849         m_ptr->mspeed = get_mspeed(r_ptr);
2850
2851         oldmaxhp = m_ptr->max_maxhp;
2852         /* Assign maximal hitpoints */
2853         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2854         {
2855                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2856         }
2857         else
2858         {
2859                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2860         }
2861
2862         /* Monsters have double hitpoints in Nightmare mode */
2863         if (ironman_nightmare)
2864         {
2865                 u32b hp = m_ptr->max_maxhp * 2L;
2866                 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2867         }
2868
2869         m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2870         if (m_ptr->maxhp < 1) m_ptr->maxhp = 1;
2871         m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2872         
2873         /* reset dealt_damage */
2874         m_ptr->dealt_damage = 0;
2875 }
2876
2877
2878 /*!
2879  * @brief たぬきの変身対象となるモンスターかどうか判定する / Hook for Tanuki
2880  * @param r_idx モンスター種族ID
2881  * @return 対象にできるならtrueを返す
2882  */
2883 static bool monster_hook_tanuki(MONRACE_IDX r_idx)
2884 {
2885         monster_race *r_ptr = &r_info[r_idx];
2886
2887         if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2888         if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2889         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2890         if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2891         
2892         if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
2893                 return FALSE;
2894
2895         return (*(get_monster_hook()))(r_idx);
2896 }
2897
2898
2899 /*!
2900  * @brief モンスターの表層IDを設定する / Set initial racial appearance of a monster
2901  * @param r_idx モンスター種族ID
2902  * @return モンスター種族の表層ID
2903  */
2904 static IDX initial_r_appearance(MONRACE_IDX r_idx)
2905 {
2906         int attempts = 1000;
2907
2908         IDX ap_r_idx;
2909         DEPTH min = MIN(base_level-5, 50);
2910
2911         if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2912                 return r_idx;
2913
2914         get_mon_num_prep(monster_hook_tanuki, NULL);
2915
2916         while (--attempts)
2917         {
2918                 ap_r_idx = get_mon_num(base_level + 10);
2919                 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2920         }
2921
2922         return r_idx;
2923 }
2924
2925
2926 /*!
2927  * @brief モンスターの個体加速を設定する / Get initial monster speed
2928  * @param r_ptr モンスター種族の参照ポインタ
2929  * @return 加速値
2930  */
2931 byte get_mspeed(monster_race *r_ptr)
2932 {
2933         /* Extract the monster base speed */
2934         int mspeed = r_ptr->speed;
2935
2936         /* Hack -- small racial variety */
2937         if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
2938         {
2939                 /* Allow some small variation per monster */
2940                 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2941                 if (i) mspeed += rand_spread(0, i);
2942         }
2943
2944         if (mspeed > 199) mspeed = 199;
2945
2946         return (byte)mspeed;
2947 }
2948
2949
2950 /*!
2951  * @brief モンスターを一体生成する / Attempt to place a monster of the given race at the given location.
2952  * @param who 召喚を行ったモンスターID
2953  * @param y 生成位置y座標
2954  * @param x 生成位置x座標
2955  * @param r_idx 生成モンスター種族
2956  * @param mode 生成オプション
2957  * @return 成功したらtrue
2958  * @details 
2959  * To give the player a sporting chance, any monster that appears in
2960  * line-of-sight and is extremely dangerous can be marked as
2961  * "FORCE_SLEEP", which will cause them to be placed with low energy,
2962  * which often (but not always) lets the player move before they do.
2963  *
2964  * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2965  *
2966  * Use special "here" and "dead" flags for unique monsters,
2967  * remove old "cur_num" and "max_num" fields.
2968  *
2969  * Actually, do something similar for artifacts, to simplify
2970  * the "preserve" mode, and to make the "what artifacts" flag more useful.
2971  *
2972  * This is the only function which may place a monster in the dungeon,
2973  * except for the savefile loading code.
2974  */
2975 static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2976 {
2977         /* Access the location */
2978         cave_type               *c_ptr = &cave[y][x];
2979         monster_type    *m_ptr;
2980         monster_race    *r_ptr = &r_info[r_idx];
2981         cptr            name = (r_name + r_ptr->name);
2982
2983         int cmi;
2984
2985         /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
2986         if (p_ptr->wild_mode) return FALSE;
2987
2988         /* Verify location */
2989         if (!in_bounds(y, x)) return (FALSE);
2990
2991         /* Paranoia */
2992         if (!r_idx) return (FALSE);
2993
2994         /* Paranoia */
2995         if (!r_ptr->name) return (FALSE);
2996
2997         if (!(mode & PM_IGNORE_TERRAIN))
2998         {
2999                 /* Not on the Pattern */
3000                 if (pattern_tile(y, x)) return FALSE;
3001
3002                 /* Require empty space (if not ghostly) */
3003                 if (!monster_can_enter(y, x, r_ptr, 0)) return FALSE;
3004         }
3005
3006         if (!p_ptr->inside_battle)
3007         {
3008                 /* Hack -- "unique" monsters must be "unique" */
3009                 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
3010                      (r_ptr->flags7 & (RF7_NAZGUL))) &&
3011                     (r_ptr->cur_num >= r_ptr->max_num))
3012                 {
3013                         /* Cannot create */
3014                         return (FALSE);
3015                 }
3016
3017                 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
3018                     (r_ptr->cur_num >= 1))
3019                 {
3020                         return (FALSE);
3021                 }
3022
3023                 if (r_idx == MON_BANORLUPART)
3024                 {
3025                         if (r_info[MON_BANOR].cur_num > 0) return FALSE;
3026                         if (r_info[MON_LUPART].cur_num > 0) return FALSE;
3027                 }
3028
3029                 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
3030                 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (dun_level < r_ptr->level) &&
3031                     (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
3032                 {
3033                         /* Cannot create */
3034                         return (FALSE);
3035                 }
3036         }
3037
3038         if (quest_number(dun_level))
3039         {
3040                 int hoge = quest_number(dun_level);
3041                 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
3042                 {
3043                         if(r_idx == quest[hoge].r_idx)
3044                         {
3045                                 int number_mon, i2, j2;
3046                                 number_mon = 0;
3047
3048                                 /* Count all quest monsters */
3049                                 for (i2 = 0; i2 < cur_wid; ++i2)
3050                                         for (j2 = 0; j2 < cur_hgt; j2++)
3051                                                 if (cave[j2][i2].m_idx > 0)
3052                                                         if (m_list[cave[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
3053                                                                 number_mon++;
3054                                 if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
3055                                         return FALSE;
3056                         }
3057                 }
3058         }
3059
3060         if (is_glyph_grid(c_ptr))
3061         {
3062                 if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
3063                 {
3064                         /* Describe observable breakage */
3065                         if (c_ptr->info & CAVE_MARK)
3066                         {
3067                                 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
3068                         }
3069
3070                         /* Forget the rune */
3071                         c_ptr->info &= ~(CAVE_MARK);
3072
3073                         /* Break the rune */
3074                         c_ptr->info &= ~(CAVE_OBJECT);
3075                         c_ptr->mimic = 0;
3076
3077                         note_spot(y, x);
3078                 }
3079                 else return FALSE;
3080         }
3081
3082         msg_format_wizard(CHEAT_MONSTER, _("%s(Lv%d)を生成しました。", "%s(Lv%d) was generated."), name, r_ptr->level);
3083
3084         if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL) || (r_ptr->level < 10)) mode &= ~PM_KAGE;
3085
3086         /* Make a new monster */
3087         c_ptr->m_idx = m_pop();
3088         hack_m_idx_ii = c_ptr->m_idx;
3089
3090         /* Mega-Hack -- catch "failure" */
3091         if (!c_ptr->m_idx) return (FALSE);
3092
3093
3094         /* Get a new monster record */
3095         m_ptr = &m_list[c_ptr->m_idx];
3096
3097         /* Save the race */
3098         m_ptr->r_idx = r_idx;
3099         m_ptr->ap_r_idx = initial_r_appearance(r_idx);
3100
3101         /* No flags */
3102         m_ptr->mflag = 0;
3103         m_ptr->mflag2 = 0;
3104
3105         /* Hack -- Appearance transfer */
3106         if ((mode & PM_MULTIPLY) && (who > 0) && !is_original_ap(&m_list[who]))
3107         {
3108                 m_ptr->ap_r_idx = m_list[who].ap_r_idx;
3109
3110                 /* Hack -- Shadower spawns Shadower */
3111                 if (m_list[who].mflag2 & MFLAG2_KAGE) m_ptr->mflag2 |= MFLAG2_KAGE;
3112         }
3113
3114         /* Sub-alignment of a monster */
3115         if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
3116                 m_ptr->sub_align = m_list[who].sub_align;
3117         else
3118         {
3119                 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3120                 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
3121                 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
3122         }
3123
3124         /* Place the monster at the location */
3125         m_ptr->fy = y;
3126         m_ptr->fx = x;
3127
3128
3129         /* No "timed status" yet */
3130         for (cmi = 0; cmi < MAX_MTIMED; cmi++) m_ptr->mtimed[cmi] = 0;
3131
3132         /* Unknown distance */
3133         m_ptr->cdis = 0;
3134
3135         reset_target(m_ptr);
3136
3137         m_ptr->nickname = 0;
3138
3139         m_ptr->exp = 0;
3140
3141
3142         /* Your pet summons its pet. */
3143         if (who > 0 && is_pet(&m_list[who]))
3144         {
3145                 mode |= PM_FORCE_PET;
3146                 m_ptr->parent_m_idx = who;
3147         }
3148         else
3149         {
3150                 m_ptr->parent_m_idx = 0;
3151         }
3152
3153         if (r_ptr->flags7 & RF7_CHAMELEON)
3154         {
3155                 choose_new_monster(c_ptr->m_idx, TRUE, 0);
3156                 r_ptr = &r_info[m_ptr->r_idx];
3157                 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
3158
3159                 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
3160                 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
3161                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3162         }
3163         else if ((mode & PM_KAGE) && !(mode & PM_FORCE_PET))
3164         {
3165                 m_ptr->ap_r_idx = MON_KAGE;
3166                 m_ptr->mflag2 |= MFLAG2_KAGE;
3167         }
3168
3169         if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
3170
3171         /* Not visible */
3172         m_ptr->ml = FALSE;
3173
3174         /* Pet? */
3175         if (mode & PM_FORCE_PET)
3176         {
3177                 set_pet(m_ptr);
3178         }
3179         /* Friendly? */
3180         else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
3181                  (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
3182         {
3183                 if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
3184         }
3185
3186         /* Assume no sleeping */
3187         m_ptr->mtimed[MTIMED_CSLEEP] = 0;
3188
3189         /* Enforce sleeping if needed */
3190         if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
3191         {
3192                 int val = r_ptr->sleep;
3193                 (void)set_monster_csleep(c_ptr->m_idx, (val * 2) + randint1(val * 10));
3194         }
3195
3196         /* Assign maximal hitpoints */
3197         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
3198         {
3199                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
3200         }
3201         else
3202         {
3203                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
3204         }
3205
3206         /* Monsters have double hitpoints in Nightmare mode */
3207         if (ironman_nightmare)
3208         {
3209                 u32b hp = m_ptr->max_maxhp * 2L;
3210
3211                 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
3212         }
3213
3214         m_ptr->maxhp = m_ptr->max_maxhp;
3215
3216         /* And start out fully healthy */
3217         if (m_ptr->r_idx == MON_WOUNDED_BEAR)
3218                 m_ptr->hp = m_ptr->maxhp / 2;
3219         else m_ptr->hp = m_ptr->maxhp;
3220         
3221         
3222         /* dealt damage is 0 at initial*/
3223         m_ptr->dealt_damage = 0;
3224
3225
3226         /* Extract the monster base speed */
3227         m_ptr->mspeed = get_mspeed(r_ptr);
3228
3229         if (mode & PM_HASTE) (void)set_monster_fast(c_ptr->m_idx, 100);
3230
3231         /* Give a random starting energy */
3232         if (!ironman_nightmare)
3233         {
3234                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
3235         }
3236         else
3237         {
3238                 /* Nightmare monsters are more prepared */
3239                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
3240         }
3241
3242         /* Force monster to wait for player, unless in Nightmare mode */
3243         if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
3244         {
3245                 /* Monster is still being nice */
3246                 m_ptr->mflag |= (MFLAG_NICE);
3247
3248                 /* Must repair monsters */
3249                 repair_monsters = TRUE;
3250         }
3251
3252         /* Hack -- see "process_monsters()" */
3253         if (c_ptr->m_idx < hack_m_idx)
3254         {
3255                 /* Monster is still being born */
3256                 m_ptr->mflag |= (MFLAG_BORN);
3257         }
3258
3259
3260         if (r_ptr->flags7 & RF7_SELF_LD_MASK)
3261                 p_ptr->update |= (PU_MON_LITE);
3262         else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !MON_CSLEEP(m_ptr))
3263                 p_ptr->update |= (PU_MON_LITE);
3264         update_monster(c_ptr->m_idx, TRUE);
3265
3266
3267         /* Count the monsters on the level */
3268         real_r_ptr(m_ptr)->cur_num++;
3269
3270         /*
3271          * Memorize location of the unique monster in saved floors.
3272          * A unique monster move from old saved floor.
3273          */
3274         if (character_dungeon &&
3275             ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)))
3276                 real_r_ptr(m_ptr)->floor_id = p_ptr->floor_id;
3277
3278         /* Hack -- Count the number of "reproducers" */
3279         if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
3280
3281         /* Hack -- Notice new multi-hued monsters */
3282         {
3283                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3284                 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
3285                         shimmer_monsters = TRUE;
3286         }
3287
3288         if (p_ptr->warning && character_dungeon)
3289         {
3290                 if (r_ptr->flags1 & RF1_UNIQUE)
3291                 {
3292                         cptr color;
3293                         object_type *o_ptr;
3294                         char o_name[MAX_NLEN];
3295
3296                         if (r_ptr->level > p_ptr->lev + 30)
3297                                 color = _("黒く", "black");
3298                         else if (r_ptr->level > p_ptr->lev + 15)
3299                                 color = _("紫色に", "purple");
3300                         else if (r_ptr->level > p_ptr->lev + 5)
3301                                 color = _("ルビー色に", "deep red");
3302                         else if (r_ptr->level > p_ptr->lev - 5)
3303                                 color = _("赤く", "red");
3304                         else if (r_ptr->level > p_ptr->lev - 15)
3305                                 color = _("ピンク色に", "pink");
3306                         else
3307                                 color = _("白く", "white");
3308
3309                         o_ptr = choose_warning_item();
3310                         if (o_ptr)
3311                         {
3312                                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3313                                 msg_format(_("%sは%s光った。", "%s glows %s."), o_name, color);
3314                         }
3315                         else
3316                         {
3317                                 msg_format(_("%s光る物が頭に浮かんだ。", "An %s image forms in your mind."), color);
3318                         }
3319                 }
3320         }
3321
3322         if (is_explosive_rune_grid(c_ptr))
3323         {
3324                 /* Break the ward */
3325                 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3326                 {
3327                         /* Describe observable breakage */
3328                         if (c_ptr->info & CAVE_MARK)
3329                         {
3330                                 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
3331                                 project(0, 2, y, x, 2 * (p_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
3332                         }
3333                 }
3334                 else
3335                 {
3336                         msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
3337                 }
3338
3339                 /* Forget the rune */
3340                 c_ptr->info &= ~(CAVE_MARK);
3341
3342                 /* Break the rune */
3343                 c_ptr->info &= ~(CAVE_OBJECT);
3344                 c_ptr->mimic = 0;
3345
3346                 note_spot(y, x);
3347                 lite_spot(y, x);
3348         }
3349
3350         /* Success */
3351         return (TRUE);
3352 }
3353
3354
3355
3356 #define MON_SCAT_MAXD 10 /*!< mon_scatter()関数によるモンスター配置で許される中心からの最大距離 */
3357
3358 /*!
3359  * @brief モンスター1体を目標地点に可能ながり近い位置に生成する / improved version of scatter() for place monster
3360  * @param r_idx 生成モンスター種族
3361  * @param yp 結果生成位置y座標
3362  * @param xp 結果生成位置x座標
3363  * @param y 中心生成位置y座標
3364  * @param x 中心生成位置x座標
3365  * @param max_dist 生成位置の最大半径
3366  * @return 成功したらtrue
3367  *  
3368  */
3369 static bool mon_scatter(MONRACE_IDX r_idx, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION max_dist)
3370 {
3371         int place_x[MON_SCAT_MAXD];
3372         int place_y[MON_SCAT_MAXD];
3373         int num[MON_SCAT_MAXD];
3374         int i;
3375         int nx, ny;
3376
3377         if (max_dist >= MON_SCAT_MAXD)
3378                 return FALSE;
3379
3380         for (i = 0; i < MON_SCAT_MAXD; i++)
3381                 num[i] = 0;
3382
3383         for (nx = x - max_dist; nx <= x + max_dist; nx++)
3384         {
3385                 for (ny = y - max_dist; ny <= y + max_dist; ny++)
3386                 {
3387                         /* Ignore annoying locations */
3388                         if (!in_bounds(ny, nx)) continue;
3389
3390                         /* Require "line of projection" */
3391                         if (!projectable(y, x, ny, nx)) continue;
3392
3393                         if (r_idx > 0)
3394                         {
3395                                 monster_race *r_ptr = &r_info[r_idx];
3396
3397                                 /* Require empty space (if not ghostly) */
3398                                 if (!monster_can_enter(ny, nx, r_ptr, 0))
3399                                         continue;
3400                         }
3401                         else
3402                         {
3403                                 /* Walls and Monsters block flow */
3404                                 if (!cave_empty_bold2(ny, nx)) continue;
3405
3406                                 /* ... nor on the Pattern */
3407                                 if (pattern_tile(ny, nx)) continue;
3408                         }
3409
3410                         i = distance(y, x, ny, nx);
3411
3412                         if (i > max_dist)
3413                                 continue;
3414
3415                         num[i]++;
3416
3417                         /* random swap */
3418                         if (one_in_(num[i]))
3419                         {
3420                                 place_x[i] = nx;
3421                                 place_y[i] = ny;
3422                         }
3423                 }
3424         }
3425
3426         i = 0;
3427         while (i < MON_SCAT_MAXD && 0 == num[i])
3428                 i++;
3429         if (i >= MON_SCAT_MAXD)
3430                 return FALSE;
3431
3432         *xp = place_x[i];
3433         *yp = place_y[i];
3434
3435         return TRUE;
3436 }
3437
3438 /*!
3439  * @brief モンスターを目標地点に集団生成する / Attempt to place a "group" of monsters around the given location
3440  * @param who 召喚主のモンスター情報ID
3441  * @param y 中心生成位置y座標
3442  * @param x 中心生成位置x座標
3443  * @param r_idx 生成モンスター種族
3444  * @param mode 生成オプション
3445  * @return 成功したらtrue
3446  */
3447 static bool place_monster_group(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
3448 {
3449         monster_race *r_ptr = &r_info[r_idx];
3450
3451         int n, i;
3452         int total = 0, extra = 0;
3453
3454         int hack_n = 0;
3455
3456         POSITION hack_y[GROUP_MAX];
3457         POSITION hack_x[GROUP_MAX];
3458
3459
3460         /* Pick a group size */
3461         total = randint1(10);
3462
3463         /* Hard monsters, small groups */
3464         if (r_ptr->level > dun_level)
3465         {
3466                 extra = r_ptr->level - dun_level;
3467                 extra = 0 - randint1(extra);
3468         }
3469
3470         /* Easy monsters, large groups */
3471         else if (r_ptr->level < dun_level)
3472         {
3473                 extra = dun_level - r_ptr->level;
3474                 extra = randint1(extra);
3475         }
3476
3477         /* Hack -- limit group reduction */
3478         if (extra > 9) extra = 9;
3479
3480         /* Modify the group size */
3481         total += extra;
3482
3483         /* Minimum size */
3484         if (total < 1) total = 1;
3485
3486         /* Maximum size */
3487         if (total > GROUP_MAX) total = GROUP_MAX;
3488
3489
3490         /* Start on the monster */
3491         hack_n = 1;
3492         hack_x[0] = x;
3493         hack_y[0] = y;
3494
3495         /* Puddle monsters, breadth first, up to total */
3496         for (n = 0; (n < hack_n) && (hack_n < total); n++)
3497         {
3498                 /* Grab the location */
3499                 POSITION hx = hack_x[n];
3500                 POSITION hy = hack_y[n];
3501
3502                 /* Check each direction, up to total */
3503                 for (i = 0; (i < 8) && (hack_n < total); i++)
3504                 {
3505                         POSITION mx, my;
3506
3507                         scatter(&my, &mx, hy, hx, 4, 0);
3508
3509                         /* Walls and Monsters block flow */
3510                         if (!cave_empty_bold2(my, mx)) continue;
3511
3512                         /* Attempt to place another monster */
3513                         if (place_monster_one(who, my, mx, r_idx, mode))
3514                         {
3515                                 /* Add it to the "hack" set */
3516                                 hack_y[hack_n] = my;
3517                                 hack_x[hack_n] = mx;
3518                                 hack_n++;
3519                         }
3520                 }
3521         }
3522
3523
3524         /* Success */
3525         return (TRUE);
3526 }
3527
3528 /*!
3529  * @var place_monster_idx
3530  * @brief 護衛対象となるモンスター種族IDを渡すグローバル変数 / Hack -- help pick an escort type
3531  * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_idxを除去し、関数引数化する
3532  */
3533 static MONSTER_IDX place_monster_idx = 0;
3534
3535 /*!
3536  * @var place_monster_m_idx
3537  * @brief 護衛対象となるモンスターIDを渡すグローバル変数 / Hack -- help pick an escort type
3538  * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_m_idxを除去し、関数引数化する
3539  */
3540 static MONSTER_IDX place_monster_m_idx = 0;
3541
3542 /*!
3543  * @brief モンスター種族が召喚主の護衛となれるかどうかをチェックする / Hack -- help pick an escort type
3544  * @param r_idx チェックするモンスター種族のID
3545  * @return 護衛にできるならばtrue
3546  */
3547 static bool place_monster_can_escort(MONRACE_IDX r_idx)
3548 {
3549         monster_race *r_ptr = &r_info[place_monster_idx];
3550         monster_type *m_ptr = &m_list[place_monster_m_idx];
3551
3552         monster_race *z_ptr = &r_info[r_idx];
3553
3554         /* Hack - Escorts have to have the same dungeon flag */
3555         if (mon_hook_dungeon(place_monster_idx) != mon_hook_dungeon(r_idx)) return (FALSE);
3556
3557         /* Require similar "race" */
3558         if (z_ptr->d_char != r_ptr->d_char) return (FALSE);
3559
3560         /* Skip more advanced monsters */
3561         if (z_ptr->level > r_ptr->level) return (FALSE);
3562
3563         /* Skip unique monsters */
3564         if (z_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3565
3566         /* Paranoia -- Skip identical monsters */
3567         if (place_monster_idx == r_idx) return (FALSE);
3568
3569         /* Skip different alignment */
3570         if (monster_has_hostile_align(m_ptr, 0, 0, z_ptr)) return FALSE;
3571
3572         if (r_ptr->flags7 & RF7_FRIENDLY)
3573         {
3574                 if (monster_has_hostile_align(NULL, 1, -1, z_ptr)) return FALSE;
3575         }
3576
3577         if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3578                 return FALSE;
3579
3580         return (TRUE);
3581 }
3582
3583
3584 /*!
3585  * @brief 一般的なモンスター生成処理のサブルーチン / Attempt to place a monster of the given race at the given location
3586  * @param who 召喚主のモンスター情報ID
3587  * @param y 生成地点y座標
3588  * @param x 生成地点x座標
3589  * @param r_idx 生成するモンスターの種族ID
3590  * @param mode 生成オプション
3591  * @return 生成に成功したらtrue
3592  * @details
3593  * Note that certain monsters are now marked as requiring "friends".
3594  * These monsters, if successfully placed, and if the "grp" parameter
3595  * is TRUE, will be surrounded by a "group" of identical monsters.
3596  *
3597  * Note that certain monsters are now marked as requiring an "escort",
3598  * which is a collection of monsters with similar "race" but lower level.
3599  *
3600  * Some monsters induce a fake "group" flag on their escorts.
3601  *
3602  * Note the "bizarre" use of non-recursion to prevent annoying output
3603  * when running a code profiler.
3604  *
3605  * Note the use of the new "monster allocation table" code to restrict
3606  * the "get_mon_num()" function to "legal" escort types.
3607  */
3608 bool place_monster_aux(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
3609 {
3610         int             i, j, n;
3611         monster_race    *r_ptr = &r_info[r_idx];
3612
3613         if (!(mode & PM_NO_KAGE) && one_in_(333))
3614                 mode |= PM_KAGE;
3615
3616         /* Place one monster, or fail */
3617         if (!place_monster_one(who, y, x, r_idx, mode)) return (FALSE);
3618
3619         /* Require the "group" flag */
3620         if (!(mode & PM_ALLOW_GROUP)) return (TRUE);
3621
3622         place_monster_m_idx = hack_m_idx_ii;
3623
3624         /* Reinforcement */
3625         for(i = 0; i < 6; i++)
3626         {
3627                 if(!r_ptr->reinforce_id[i]) break;
3628                 n = damroll(r_ptr->reinforce_dd[i], r_ptr->reinforce_ds[i]);
3629                 for(j = 0; j < n; j++)
3630                 {
3631                         POSITION nx, ny, d = 7;
3632                         scatter(&ny, &nx, y, x, d, 0);
3633                         (void)place_monster_one(place_monster_m_idx, ny, nx, r_ptr->reinforce_id[i], mode);
3634                 }
3635         }
3636
3637         /* Friends for certain monsters */
3638         if (r_ptr->flags1 & (RF1_FRIENDS))
3639         {
3640                 /* Attempt to place a group */
3641                 (void)place_monster_group(who, y, x, r_idx, mode);
3642         }
3643
3644         /* Escorts for certain monsters */
3645         if (r_ptr->flags1 & (RF1_ESCORT))
3646         {
3647                 /* Set the escort index */
3648                 place_monster_idx = r_idx;
3649
3650                 /* Try to place several "escorts" */
3651                 for (i = 0; i < 32; i++)
3652                 {
3653                         POSITION nx, ny, d = 3;
3654                         MONRACE_IDX z; 
3655
3656                         /* Pick a location */
3657                         scatter(&ny, &nx, y, x, d, 0);
3658
3659                         /* Require empty grids */
3660                         if (!cave_empty_bold2(ny, nx)) continue;
3661
3662                         /* Prepare allocation table */
3663                         get_mon_num_prep(place_monster_can_escort, get_monster_hook2(ny, nx));
3664
3665                         /* Pick a random race */
3666                         z = get_mon_num(r_ptr->level);
3667
3668                         /* Handle failure */
3669                         if (!z) break;
3670
3671                         /* Place a single escort */
3672                         (void)place_monster_one(place_monster_m_idx, ny, nx, z, mode);
3673
3674                         /* Place a "group" of escorts if needed */
3675                         if ((r_info[z].flags1 & RF1_FRIENDS) ||
3676                             (r_ptr->flags1 & RF1_ESCORTS))
3677                         {
3678                                 /* Place a group of monsters */
3679                                 (void)place_monster_group(place_monster_m_idx, ny, nx, z, mode);
3680                         }
3681                 }
3682         }
3683
3684         /* Success */
3685         return (TRUE);
3686 }
3687
3688 /*!
3689  * @brief 一般的なモンスター生成処理のメインルーチン / Attempt to place a monster of the given race at the given location
3690  * @param y 生成地点y座標
3691  * @param x 生成地点x座標
3692  * @param mode 生成オプション
3693  * @return 生成に成功したらtrue
3694  */
3695 bool place_monster(POSITION y, POSITION x, BIT_FLAGS mode)
3696 {
3697         MONRACE_IDX r_idx;
3698
3699         /* Prepare allocation table */
3700         get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3701
3702         /* Pick a monster */
3703         r_idx = get_mon_num(monster_level);
3704
3705         /* Handle failure */
3706         if (!r_idx) return (FALSE);
3707
3708         /* Attempt to place the monster */
3709         if (place_monster_aux(0, y, x, r_idx, mode)) return (TRUE);
3710
3711         return (FALSE);
3712 }
3713
3714 /*!
3715  * @brief 指定地点に1種類のモンスター種族による群れを生成する
3716  * @param y 生成地点y座標
3717  * @param x 生成地点x座標
3718  * @return 生成に成功したらtrue
3719  */
3720 bool alloc_horde(POSITION y, POSITION x)
3721 {
3722         monster_race *r_ptr = NULL;
3723         MONRACE_IDX r_idx = 0;
3724         MONSTER_IDX m_idx;
3725         int attempts = 1000;
3726         POSITION cy = y;
3727         POSITION cx = x;
3728
3729         /* Prepare allocation table */
3730         get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3731
3732         while (--attempts)
3733         {
3734                 /* Pick a monster */
3735                 r_idx = get_mon_num(monster_level);
3736
3737                 /* Handle failure */
3738                 if (!r_idx) return (FALSE);
3739
3740                 r_ptr = &r_info[r_idx];
3741
3742                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3743
3744                 if (r_idx == MON_HAGURE) continue;
3745                 break;
3746         }
3747         if (attempts < 1) return FALSE;
3748
3749         attempts = 1000;
3750
3751         while (--attempts)
3752         {
3753                 /* Attempt to place the monster */
3754                 if (place_monster_aux(0, y, x, r_idx, 0L)) break;
3755         }
3756
3757         if (attempts < 1) return FALSE;
3758
3759         m_idx = cave[y][x].m_idx;
3760
3761         if (m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[m_list[m_idx].r_idx];
3762         summon_kin_type = r_ptr->d_char;
3763
3764         for (attempts = randint1(10) + 5; attempts; attempts--)
3765         {
3766                 scatter(&cy, &cx, y, x, 5, 0);
3767
3768                 (void)summon_specific(m_idx, cy, cx, dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
3769
3770                 y = cy;
3771                 x = cx;
3772         }
3773
3774         return TRUE;
3775 }
3776
3777 /*!
3778  * @brief ダンジョンの主生成を試みる / Put the Guardian
3779  * @param def_val 現在の主の生成状態
3780  * @return 生成に成功したらtrue
3781  */
3782 bool alloc_guardian(bool def_val)
3783 {
3784         MONRACE_IDX guardian = d_info[dungeon_type].final_guardian;
3785
3786         if (guardian && (d_info[dungeon_type].maxdepth == dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
3787         {
3788                 int oy;
3789                 int ox;
3790                 int try_count = 4000;
3791
3792                 /* Find a good position */
3793                 while (try_count)
3794                 {
3795                         /* Get a random spot */
3796                         oy = randint1(cur_hgt - 4) + 2;
3797                         ox = randint1(cur_wid - 4) + 2;
3798
3799                         /* Is it a good spot ? */
3800                         if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(cave[oy][ox].feat, &r_info[guardian], 0))
3801                         {
3802                                 /* Place the guardian */
3803                                 if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE;
3804                         }
3805
3806                         /* One less try count */
3807                         try_count--;
3808                 }
3809
3810                 return FALSE;
3811         }
3812
3813         return def_val;
3814 }
3815
3816
3817 /*!
3818  * @brief ダンジョンの初期配置モンスターを生成1回生成する / Attempt to allocate a random monster in the dungeon.
3819  * @param dis プレイヤーから離れるべき最低距離
3820  * @param mode 生成オプション
3821  * @return 生成に成功したらtrue
3822  * @details
3823  * Place the monster at least "dis" distance from the player.
3824  * Use "slp" to choose the initial "sleep" status
3825  * Use "monster_level" for the monster level
3826  */
3827 bool alloc_monster(POSITION dis, BIT_FLAGS mode)
3828 {
3829         int y = 0, x = 0;
3830         int attempts_left = 10000;
3831
3832         /* Put the Guardian */
3833         if (alloc_guardian(FALSE)) return TRUE;
3834
3835         /* Find a legal, distant, unoccupied, space */
3836         while (attempts_left--)
3837         {
3838                 /* Pick a location */
3839                 y = randint0(cur_hgt);
3840                 x = randint0(cur_wid);
3841
3842                 /* Require empty floor grid (was "naked") */
3843                 if (dun_level)
3844                 {
3845                         if (!cave_empty_bold2(y, x)) continue;
3846                 }
3847                 else
3848                 {
3849                         if (!cave_empty_bold(y, x)) continue;
3850                 }
3851
3852                 /* Accept far away grids */
3853                 if (distance(y, x, p_ptr->y, p_ptr->x) > dis) break;
3854         }
3855
3856         if (!attempts_left)
3857         {
3858                 if (cheat_xtra || cheat_hear)
3859                 {
3860                         msg_print(_("警告!新たなモンスターを配置できません。小さい階ですか?", "Warning! Could not allocate a new monster. Small level?"));
3861                 }
3862
3863                 return (FALSE);
3864         }
3865
3866
3867         if (randint1(5000) <= dun_level)
3868         {
3869                 if (alloc_horde(y, x))
3870                 {
3871                         if (cheat_hear) msg_format(_("モンスターの大群(%c)", "Monster horde (%c)."), summon_kin_type);
3872                         return (TRUE);
3873                 }
3874         }
3875         else
3876         {
3877                 /* Attempt to place the monster, allow groups */
3878                 if (place_monster(y, x, (mode | PM_ALLOW_GROUP))) return (TRUE);
3879         }
3880
3881         return (FALSE);
3882 }
3883
3884
3885 /*!
3886  * @brief モンスターが召喚の基本条件に合っているかをチェックする / Hack -- help decide if a monster race is "okay" to summon
3887  * @param r_idx チェックするモンスター種族ID
3888  * @return 召喚対象にできるならばTRUE
3889  */
3890 static bool summon_specific_okay(MONRACE_IDX r_idx)
3891 {
3892         monster_race *r_ptr = &r_info[r_idx];
3893
3894         /* Hack - Only summon dungeon monsters */
3895         if (!mon_hook_dungeon(r_idx)) return (FALSE);
3896
3897         /* Hack -- identify the summoning monster */
3898         if (summon_specific_who > 0)
3899         {
3900                 monster_type *m_ptr = &m_list[summon_specific_who];
3901
3902                 /* Do not summon enemies */
3903
3904                 /* Friendly vs. opposite aligned normal or pet */
3905                 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
3906         }
3907         /* Use the player's alignment */
3908         else if (summon_specific_who < 0)
3909         {
3910                 /* Do not summon enemies of the pets */
3911                 if (monster_has_hostile_align(NULL, 10, -10, r_ptr))
3912                 {
3913                         if (!one_in_(ABS(p_ptr->align) / 2 + 1)) return FALSE;
3914                 }
3915         }
3916
3917         if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL))) return FALSE;
3918
3919         /* Hack -- no specific type specified */
3920         if (!summon_specific_type) return (TRUE);
3921
3922         if ((summon_specific_who < 0) &&
3923             ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
3924             monster_has_hostile_align(NULL, 10, -10, r_ptr))
3925                 return FALSE;
3926
3927         if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[dungeon_type].flags1 & DF1_CHAMELEON)) return TRUE;
3928
3929         return (summon_specific_aux(r_idx));
3930 }
3931
3932
3933 /*!
3934  * @brief モンスターを召喚により配置する / Place a monster (of the specified "type") near the given location. Return TRUE if a monster was actually summoned.
3935  * @param who 召喚主のモンスター情報ID
3936  * @param y1 目標地点y座標
3937  * @param x1 目標地点x座標
3938  * @param lev 相当生成階
3939  * @param type 召喚種別
3940  * @param mode 生成オプション 
3941  * @return 召喚できたらtrueを返す
3942  * @details
3943  *
3944  * We will attempt to place the monster up to 10 times before giving up.
3945  *
3946  * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
3947  * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
3948  * Note: None of the other summon codes will ever summon Unique's.
3949  *
3950  * This function has been changed.  We now take the "monster level"
3951  * of the summoning monster as a parameter, and use that, along with
3952  * the current dungeon level, to help determine the level of the
3953  * desired monster.  Note that this is an upper bound, and also
3954  * tends to "prefer" monsters of that level.  Currently, we use
3955  * the average of the dungeon and monster levels, and then add
3956  * five to allow slight increases in monster power.
3957  *
3958  * Note that we use the new "monster allocation table" creation code
3959  * to restrict the "get_mon_num()" function to the set of "legal"
3960  * monsters, making this function much faster and more reliable.
3961  *
3962  * Note that this function may not succeed, though this is very rare.
3963  */
3964 bool summon_specific(MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int type, BIT_FLAGS mode)
3965 {
3966         POSITION x, y;
3967         MONRACE_IDX r_idx;
3968
3969         if (p_ptr->inside_arena) return (FALSE);
3970
3971         if (!mon_scatter(0, &y, &x, y1, x1, 2)) return FALSE;
3972
3973         /* Save the summoner */
3974         summon_specific_who = who;
3975
3976         /* Save the "summon" type */
3977         summon_specific_type = type;
3978
3979         summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
3980
3981         /* Prepare allocation table */
3982         get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
3983
3984         /* Pick a monster, using the level calculation */
3985         r_idx = get_mon_num((dun_level + lev) / 2 + 5);
3986
3987         /* Handle failure */
3988         if (!r_idx)
3989         {
3990                 summon_specific_type = 0;
3991                 return (FALSE);
3992         }
3993
3994         if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
3995
3996         /* Attempt to place the monster (awake, allow groups) */
3997         if (!place_monster_aux(who, y, x, r_idx, mode))
3998         {
3999                 summon_specific_type = 0;
4000                 return (FALSE);
4001         }
4002
4003         summon_specific_type = 0;
4004         /* Success */
4005         sound(SOUND_SUMMON);
4006         return (TRUE);
4007 }
4008
4009
4010 /*!
4011  * @brief 特定モンスター種族を召喚により生成する / A "dangerous" function, creates a pet of the specified type
4012  * @param who 召喚主のモンスター情報ID
4013  * @param oy 目標地点y座標
4014  * @param ox 目標地点x座標
4015  * @param r_idx 生成するモンスター種族ID
4016  * @param mode 生成オプション 
4017  * @return 召喚できたらtrueを返す
4018  */
4019 bool summon_named_creature (MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_IDX r_idx, BIT_FLAGS mode)
4020 {
4021         POSITION x, y;
4022
4023         /* Paranoia */
4024         /* if (!r_idx) return; */
4025
4026         /* Prevent illegal monsters */
4027         if (r_idx >= max_r_idx) return FALSE;
4028
4029         if (p_ptr->inside_arena) return FALSE;
4030
4031         if (!mon_scatter(r_idx, &y, &x, oy, ox, 2)) return FALSE;
4032
4033         /* Place it (allow groups) */
4034         return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
4035 }
4036
4037
4038 /*!
4039  * @brief モンスターを増殖生成する / Let the given monster attempt to reproduce.
4040  * @param m_idx 増殖するモンスター情報ID
4041  * @param clone クローン・モンスター処理ならばtrue
4042  * @param mode 生成オプション 
4043  * @return 生成できたらtrueを返す
4044  * @details
4045  * Note that "reproduction" REQUIRES empty space.
4046  */
4047 bool multiply_monster(MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
4048 {
4049         monster_type    *m_ptr = &m_list[m_idx];
4050
4051         POSITION y, x;
4052
4053         if (!mon_scatter(m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
4054                 return FALSE;
4055
4056         if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
4057
4058         /* Create a new monster (awake, no groups) */
4059         if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
4060                 return FALSE;
4061
4062         /* Hack -- Transfer "clone" flag */
4063         if (clone || (m_ptr->smart & SM_CLONED))
4064         {
4065                 m_list[hack_m_idx_ii].smart |= SM_CLONED;
4066                 m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
4067         }
4068
4069         return TRUE;
4070 }
4071
4072
4073
4074 /*!
4075  * @brief ダメージを受けたモンスターの様子を記述する / Dump a message describing a monster's reaction to damage
4076  * @param m_idx モンスター情報ID
4077  * @param dam 与えたダメージ
4078  * @return なし
4079  * @details
4080  * Technically should attempt to treat "Beholder"'s as jelly's
4081  */
4082 void message_pain(MONSTER_IDX m_idx, HIT_POINT dam)
4083 {
4084         long oldhp, newhp, tmp;
4085         int percentage;
4086
4087         monster_type *m_ptr = &m_list[m_idx];
4088         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4089
4090         char m_name[80];
4091
4092         /* Get the monster name */
4093         monster_desc(m_name, m_ptr, 0);
4094
4095         if(dam == 0) // Notice non-damage
4096         {
4097                 msg_format(_("%^sはダメージを受けていない。", "%^s is unharmed."), m_name);
4098                 return;
4099         }
4100
4101         /* Note -- subtle fix -CFT */
4102         newhp = (long)(m_ptr->hp);
4103         oldhp = newhp + (long)(dam);
4104         tmp = (newhp * 100L) / oldhp;
4105         percentage = (int)(tmp);
4106
4107         if(my_strchr(",ejmvwQ", r_ptr->d_char)) // Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs
4108         {
4109 #ifdef JP
4110                 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
4111                 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
4112                 else if(percentage > 50) msg_format("%^sは縮こまった。", m_name);
4113                 else if(percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
4114                 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
4115                 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
4116                 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
4117 #else
4118                 if(percentage > 95) msg_format("%^s barely notices.", m_name);
4119                 else if(percentage > 75) msg_format("%^s flinches.", m_name);
4120                 else if(percentage > 50) msg_format("%^s squelches.", m_name);
4121                 else if(percentage > 35) msg_format("%^s quivers in pain.", m_name);
4122                 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
4123                 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
4124                 else msg_format("%^s jerks limply.", m_name);
4125 #endif
4126         }
4127
4128         else if(my_strchr("l", r_ptr->d_char)) // Fish
4129         {
4130 #ifdef JP
4131                 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
4132                 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
4133                 else if(percentage > 50) msg_format("%^sは躊躇した。", m_name);
4134                 else if(percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
4135                 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
4136                 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
4137                 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
4138 #else
4139                 if(percentage > 95) msg_format("%^s barely notices.", m_name);
4140                 else if(percentage > 75) msg_format("%^s flinches.", m_name);
4141                 else if(percentage > 50) msg_format("%^s hesitates.", m_name);
4142                 else if(percentage > 35) msg_format("%^s quivers in pain.", m_name);
4143                 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
4144                 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
4145                 else msg_format("%^s jerks limply.", m_name);
4146 #endif          
4147         }
4148
4149         else if(my_strchr("g#+<>", r_ptr->d_char)) // Golems, Walls, Doors, Stairs
4150         {       
4151 #ifdef JP
4152                 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
4153                 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
4154                 else if(percentage > 50) msg_format("%^sは雷鳴のように吠えた。", m_name);
4155                 else if(percentage > 35) msg_format("%^sは苦しげに吠えた。", m_name);
4156                 else if(percentage > 20) msg_format("%^sはうめいた。", m_name);
4157                 else if(percentage > 10) msg_format("%^sは躊躇した。", m_name);
4158                 else msg_format("%^sはくしゃくしゃになった。", m_name);
4159 #else
4160                 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
4161                 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
4162                 else if(percentage > 50) msg_format("%^s roars thunderously.", m_name);
4163                 else if(percentage > 35) msg_format("%^s rumbles.", m_name);
4164                 else if(percentage > 20) msg_format("%^s grunts.", m_name);
4165                 else if(percentage > 10) msg_format("%^s hesitates.", m_name);
4166                 else msg_format("%^s crumples.", m_name);
4167 #endif
4168         }
4169
4170         else if(my_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char)) // Snakes, Hydrae, Reptiles, Mimics
4171         {
4172 #ifdef JP
4173                 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
4174                 else if(percentage > 75) msg_format("%^sはシーッと鳴いた。", m_name);
4175                 else if(percentage > 50) msg_format("%^sは怒って頭を上げた。", m_name);
4176                 else if(percentage > 35) msg_format("%^sは猛然と威嚇した。", m_name);
4177                 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
4178                 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
4179                 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
4180 #else
4181                 if(percentage > 95) msg_format("%^s barely notices.", m_name);
4182                 else if(percentage > 75) msg_format("%^s hisses.", m_name);
4183                 else if(percentage > 50) msg_format("%^s rears up in anger.", m_name);
4184                 else if(percentage > 35) msg_format("%^s hisses furiously.", m_name);
4185                 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
4186                 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
4187                 else msg_format("%^s jerks limply.", m_name);
4188 #endif
4189         }
4190
4191         else if(my_strchr("f", r_ptr->d_char))
4192         {
4193 #ifdef JP
4194                 if(percentage > 95) msg_format("%sは攻撃に肩をすくめた。", m_name);
4195                 else if(percentage > 75) msg_format("%^sは吠えた。", m_name);
4196                 else if(percentage > 50) msg_format("%^sは怒って吠えた。", m_name);
4197                 else if(percentage > 35) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
4198                 else if(percentage > 20) msg_format("%^sは痛みで弱々しく鳴いた。", m_name);
4199                 else if(percentage > 10) msg_format("%^sは苦痛にうめいた。", m_name);
4200                 else msg_format("%sは哀れな鳴き声を出した。", m_name);
4201 #else
4202                 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
4203                 else if(percentage > 75) msg_format("%^s roars.", m_name);
4204                 else if(percentage > 50) msg_format("%^s growls angrily.", m_name);
4205                 else if(percentage > 35) msg_format("%^s hisses with pain.", m_name);
4206                 else if(percentage > 20) msg_format("%^s mewls in pain.", m_name);
4207                 else if(percentage > 10) msg_format("%^s hisses in agony.", m_name);
4208                 else msg_format("%^s mewls pitifully.", m_name);
4209 #endif
4210         }
4211
4212         else if(my_strchr("acFIKS", r_ptr->d_char)) // Ants, Centipedes, Flies, Insects, Beetles, Spiders
4213         {
4214 #ifdef JP
4215                 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
4216                 else if(percentage > 75) msg_format("%^sはキーキー鳴いた。", m_name);
4217                 else if(percentage > 50) msg_format("%^sはヨロヨロ逃げ回った。", m_name);
4218                 else if(percentage > 35) msg_format("%^sはうるさく鳴いた。", m_name);
4219                 else if(percentage > 20) msg_format("%^sは痛みに痙攣した。", m_name);
4220                 else if(percentage > 10) msg_format("%^sは苦痛で痙攣した。", m_name);
4221                 else msg_format("%^sはピクピクひきつった。", m_name);
4222 #else
4223                 if(percentage > 95)     msg_format("%^s ignores the attack.", m_name);
4224                 else if(percentage > 75) msg_format("%^s chitters.", m_name);
4225                 else if(percentage > 50) msg_format("%^s scuttles about.", m_name);
4226                 else if(percentage > 35) msg_format("%^s twitters.", m_name);
4227                 else if(percentage > 20) msg_format("%^s jerks in pain.", m_name);
4228                 else if(percentage > 10) msg_format("%^s jerks in agony.", m_name);
4229                 else msg_format("%^s twitches.", m_name);
4230 #endif
4231         }
4232
4233         else if(my_strchr("B", r_ptr->d_char)) // Birds
4234         {               
4235 #ifdef JP
4236                 if(percentage > 95) msg_format("%^sはさえずった。", m_name);
4237                 else if(percentage > 75) msg_format("%^sはピーピー鳴いた。", m_name);
4238                 else if(percentage > 50) msg_format("%^sはギャーギャー鳴いた。", m_name);
4239                 else if(percentage > 35) msg_format("%^sはギャーギャー鳴きわめいた。", m_name);
4240                 else if(percentage > 20) msg_format("%^sは苦しんだ。", m_name);
4241                 else if(percentage > 10) msg_format("%^sはのたうち回った。", m_name);
4242                 else msg_format("%^sはキーキーと鳴き叫んだ。", m_name);
4243 #else
4244                 if(percentage > 95)     msg_format("%^s chirps.", m_name);
4245                 else if(percentage > 75) msg_format("%^s twitters.", m_name);
4246                 else if(percentage > 50) msg_format("%^s squawks.", m_name);
4247                 else if(percentage > 35) msg_format("%^s chatters.", m_name);
4248                 else if(percentage > 20) msg_format("%^s jeers.", m_name);
4249                 else if(percentage > 10) msg_format("%^s flutters about.", m_name);
4250                 else msg_format("%^s squeaks.", m_name);
4251 #endif
4252         }
4253
4254         else if(my_strchr("duDLUW", r_ptr->d_char)) // Dragons, Demons, High Undead
4255         {       
4256 #ifdef JP
4257                 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
4258                 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
4259                 else if(percentage > 50) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
4260                 else if(percentage > 35) msg_format("%^sは痛みでうなった。", m_name);
4261                 else if(percentage > 20) msg_format("%^sは痛みに吠えた。", m_name);
4262                 else if(percentage > 10) msg_format("%^sは苦しげに叫んだ。", m_name);
4263                 else msg_format("%^sは弱々しくうなった。", m_name);
4264 #else
4265                 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
4266                 else if(percentage > 75) msg_format("%^s flinches.", m_name);
4267                 else if(percentage > 50) msg_format("%^s hisses in pain.", m_name);
4268                 else if(percentage > 35) msg_format("%^s snarls with pain.", m_name);
4269                 else if(percentage > 20) msg_format("%^s roars with pain.", m_name);
4270                 else if(percentage > 10) msg_format("%^s gasps.", m_name);
4271                 else msg_format("%^s snarls feebly.", m_name);
4272 #endif
4273         }
4274
4275         else if(my_strchr("s", r_ptr->d_char)) // Skeletons
4276         {
4277 #ifdef JP
4278                 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
4279                 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
4280                 else if(percentage > 50) msg_format("%^sはカタカタと笑った。", m_name);
4281                 else if(percentage > 35) msg_format("%^sはよろめいた。", m_name);
4282                 else if(percentage > 20) msg_format("%^sはカタカタ言った。", m_name);
4283                 else if(percentage > 10) msg_format("%^sはよろめいた。", m_name);
4284                 else msg_format("%^sはガタガタ言った。", m_name);
4285 #else
4286                 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
4287                 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
4288                 else if(percentage > 50) msg_format("%^s rattles.", m_name);
4289                 else if(percentage > 35) msg_format("%^s stumbles.", m_name);
4290                 else if(percentage > 20) msg_format("%^s rattles.", m_name);
4291                 else if(percentage > 10) msg_format("%^s staggers.", m_name);
4292                 else msg_format("%^s clatters.", m_name);
4293 #endif
4294         }
4295
4296         else if(my_strchr("z", r_ptr->d_char)) // Zombies
4297         {               
4298 #ifdef JP
4299                 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
4300                 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
4301                 else if(percentage > 50) msg_format("%^sはうめいた。", m_name);
4302                 else if(percentage > 35) msg_format("%sは苦しげにうめいた。", m_name);
4303                 else if(percentage > 20) msg_format("%^sは躊躇した。", m_name);
4304                 else if(percentage > 10) msg_format("%^sはうなった。", m_name);
4305                 else msg_format("%^sはよろめいた。", m_name);
4306 #else
4307                 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
4308                 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
4309                 else if(percentage > 50) msg_format("%^s groans.", m_name);
4310                 else if(percentage > 35) msg_format("%^s moans.", m_name);
4311                 else if(percentage > 20) msg_format("%^s hesitates.", m_name);
4312                 else if(percentage > 10) msg_format("%^s grunts.", m_name);
4313                 else msg_format("%^s staggers.", m_name);
4314 #endif
4315         }
4316
4317         else if(my_strchr("G", r_ptr->d_char)) // Ghosts
4318         {
4319 #ifdef JP
4320                 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
4321                 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
4322                 else if(percentage > 50) msg_format("%sはうめいた。", m_name);
4323                 else if(percentage > 35) msg_format("%^sは泣きわめいた。", m_name);
4324                 else if(percentage > 20) msg_format("%^sは吠えた。", m_name);
4325                 else if(percentage > 10) msg_format("%sは弱々しくうめいた。", m_name);
4326                 else msg_format("%^sはかすかにうめいた。", m_name);
4327 #else
4328                 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
4329                 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
4330                 else if(percentage > 50)  msg_format("%^s moans.", m_name);
4331                 else if(percentage > 35) msg_format("%^s wails.", m_name);
4332                 else if(percentage > 20) msg_format("%^s howls.", m_name);
4333                 else if(percentage > 10) msg_format("%^s moans softly.", m_name);
4334                 else msg_format("%^s sighs.", m_name);
4335 #endif
4336         }
4337
4338         else if(my_strchr("CZ", r_ptr->d_char)) // Dogs and Hounds
4339         {
4340 #ifdef JP
4341                 if(percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
4342                 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
4343                 else if(percentage > 50) msg_format("%^sは痛みでキャンキャン吠えた。", m_name);
4344                 else if(percentage > 35) msg_format("%^sは痛みで鳴きわめいた。", m_name);
4345                 else if(percentage > 20) msg_format("%^sは苦痛のあまり鳴きわめいた。", m_name);
4346                 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
4347                 else msg_format("%^sは弱々しく吠えた。", m_name);
4348 #else
4349                 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
4350                 else if(percentage > 75) msg_format("%^s snarls with pain.", m_name);
4351                 else if(percentage > 50) msg_format("%^s yelps in pain.", m_name);
4352                 else if(percentage > 35) msg_format("%^s howls in pain.", m_name);
4353                 else if(percentage > 20) msg_format("%^s howls in agony.", m_name);
4354                 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
4355                 else msg_format("%^s yelps feebly.", m_name);
4356 #endif
4357         }
4358
4359         else if(my_strchr("Xbilqrt", r_ptr->d_char)) // One type of creatures (ignore,squeal,shriek)
4360         {
4361 #ifdef JP
4362                 if(percentage > 95) msg_format("%^sは攻撃を気にとめていない。", m_name);
4363                 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
4364                 else if(percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
4365                 else if(percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
4366                 else if(percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
4367                 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
4368                 else msg_format("%^sは弱々しく叫んだ。", m_name);
4369 #else
4370                 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
4371                 else if(percentage > 75) msg_format("%^s grunts with pain.", m_name);
4372                 else if(percentage > 50) msg_format("%^s squeals in pain.", m_name);
4373                 else if(percentage > 35) msg_format("%^s shrieks in pain.", m_name);
4374                 else if(percentage > 20) msg_format("%^s shrieks in agony.", m_name);
4375                 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
4376                 else msg_format("%^s cries out feebly.", m_name);
4377 #endif
4378         }
4379
4380         else // Another type of creatures (shrug,cry,scream)
4381         {
4382 #ifdef JP
4383                 if(percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
4384                 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
4385                 else if(percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
4386                 else if(percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
4387                 else if(percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
4388                 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
4389                 else msg_format("%^sは弱々しく叫んだ。", m_name);
4390 #else
4391                 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
4392                 else if(percentage > 75) msg_format("%^s grunts with pain.", m_name);
4393                 else if(percentage > 50) msg_format("%^s cries out in pain.", m_name);
4394                 else if(percentage > 35) msg_format("%^s screams in pain.", m_name);
4395                 else if(percentage > 20) msg_format("%^s screams in agony.", m_name);
4396                 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
4397                 else msg_format("%^s cries out feebly.", m_name);
4398 #endif
4399         }
4400 }
4401
4402
4403
4404 /*!
4405  * @brief SMART(適格に攻撃を行う)モンスターの学習状況を更新する / Learn about an "observed" resistance.
4406  * @param m_idx 更新を行う「モンスター情報ID
4407  * @param what 学習対象ID
4408  * @return なし
4409  */
4410 void update_smart_learn(MONSTER_IDX m_idx, int what)
4411 {
4412         monster_type *m_ptr = &m_list[m_idx];
4413
4414         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4415
4416
4417         /* Not allowed to learn */
4418         if (!smart_learn) return;
4419
4420         /* Too stupid to learn anything */
4421         if (r_ptr->flags2 & (RF2_STUPID)) return;
4422
4423         /* Not intelligent, only learn sometimes */
4424         if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
4425
4426
4427
4428         /* Analyze the knowledge */
4429         switch (what)
4430         {
4431         case DRS_ACID:
4432                 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
4433                 if (IS_OPPOSE_ACID()) m_ptr->smart |= (SM_OPP_ACID);
4434                 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
4435                 break;
4436
4437         case DRS_ELEC:
4438                 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
4439                 if (IS_OPPOSE_ELEC()) m_ptr->smart |= (SM_OPP_ELEC);
4440                 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
4441                 break;
4442
4443         case DRS_FIRE:
4444                 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
4445                 if (IS_OPPOSE_FIRE()) m_ptr->smart |= (SM_OPP_FIRE);
4446                 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
4447                 break;
4448
4449         case DRS_COLD:
4450                 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
4451                 if (IS_OPPOSE_COLD()) m_ptr->smart |= (SM_OPP_COLD);
4452                 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
4453                 break;
4454
4455         case DRS_POIS:
4456                 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
4457                 if (IS_OPPOSE_POIS()) m_ptr->smart |= (SM_OPP_POIS);
4458                 break;
4459
4460
4461         case DRS_NETH:
4462                 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
4463                 break;
4464
4465         case DRS_LITE:
4466                 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
4467                 break;
4468
4469         case DRS_DARK:
4470                 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
4471                 break;
4472
4473         case DRS_FEAR:
4474                 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
4475                 break;
4476
4477         case DRS_CONF:
4478                 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
4479                 break;
4480
4481         case DRS_CHAOS:
4482                 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
4483                 break;
4484
4485         case DRS_DISEN:
4486                 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
4487                 break;
4488
4489         case DRS_BLIND:
4490                 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
4491                 break;
4492
4493         case DRS_NEXUS:
4494                 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
4495                 break;
4496
4497         case DRS_SOUND:
4498                 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
4499                 break;
4500
4501         case DRS_SHARD:
4502                 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
4503                 break;
4504
4505         case DRS_FREE:
4506                 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
4507                 break;
4508
4509         case DRS_MANA:
4510                 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
4511                 break;
4512
4513         case DRS_REFLECT:
4514                 if (p_ptr->reflect) m_ptr-> smart |= (SM_IMM_REFLECT);
4515                 break;
4516         }
4517 }
4518
4519
4520 /*!
4521  * @brief プレイヤーを指定座標に配置する / Place the player in the dungeon XXX XXX
4522  * @param x 配置先X座標
4523  * @param y 配置先Y座標
4524  * @return 配置に成功したらTRUE
4525  */
4526 bool player_place(POSITION y, POSITION x)
4527 {
4528         /* Paranoia XXX XXX */
4529         if (cave[y][x].m_idx != 0) return FALSE;
4530
4531         /* Save player location */
4532         p_ptr->y = y;
4533         p_ptr->x = x;
4534
4535         /* Success */
4536         return TRUE;
4537 }
4538
4539
4540 /*!
4541  * @brief モンスターが盗みや拾いで確保していたアイテムを全てドロップさせる / Drop all items carried by a monster
4542  * @param m_ptr モンスター参照ポインタ
4543  * @return なし
4544  */
4545 void monster_drop_carried_objects(monster_type *m_ptr)
4546 {
4547         OBJECT_IDX this_o_idx, next_o_idx = 0;
4548         object_type forge;
4549         object_type *o_ptr;
4550         object_type *q_ptr;
4551
4552
4553         /* Drop objects being carried */
4554         for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4555         {
4556                 o_ptr = &o_list[this_o_idx];
4557
4558                 /* Acquire next object */
4559                 next_o_idx = o_ptr->next_o_idx;
4560                 q_ptr = &forge;
4561
4562                 /* Copy the object */
4563                 object_copy(q_ptr, o_ptr);
4564
4565                 /* Forget monster */
4566                 q_ptr->held_m_idx = 0;
4567
4568                 delete_object_idx(this_o_idx);
4569
4570                 /* Drop it */
4571                 (void)drop_near(q_ptr, -1, m_ptr->fy, m_ptr->fx);
4572         }
4573
4574         /* Forget objects */
4575         m_ptr->hold_o_idx = 0;
4576 }