OSDN Git Service

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