OSDN Git Service

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