OSDN Git Service

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