OSDN Git Service

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