OSDN Git Service

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