OSDN Git Service

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