OSDN Git Service

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