OSDN Git Service

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