OSDN Git Service

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