OSDN Git Service

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