OSDN Git Service

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