OSDN Git Service

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