OSDN Git Service

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