OSDN Git Service

v3.0.0 Alpha5 OSDN最終版
[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         cave[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         cave_type *c_ptr;
315
316         /* Paranoia */
317         if (!in_bounds(y, x)) return;
318
319         /* Check the grid */
320         c_ptr = &cave[y][x];
321
322         /* Delete the monster (if any) */
323         if (c_ptr->m_idx) delete_monster_idx(c_ptr->m_idx);
324 }
325
326
327 /*!
328  * @brief モンスター情報を配列内移動する / Move an object from index i1 to index i2 in the object list
329  * @param i1 配列移動元添字
330  * @param i2 配列移動先添字
331  * @return なし
332  */
333 static void compact_monsters_aux(IDX i1, IDX i2)
334 {
335         POSITION y, x;
336         int i;
337         cave_type *c_ptr;
338         monster_type *m_ptr;
339         OBJECT_IDX this_o_idx, next_o_idx = 0;
340
341         /* Do nothing */
342         if (i1 == i2) return;
343
344         /* Old monster */
345         m_ptr = &m_list[i1];
346
347         y = m_ptr->fy;
348         x = m_ptr->fx;
349
350         /* Cave grid */
351         c_ptr = &cave[y][x];
352
353         /* Update the cave */
354         c_ptr->m_idx = i2;
355
356         /* Repair objects being carried by monster */
357         for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
358         {
359                 object_type *o_ptr;
360                 o_ptr = &o_list[this_o_idx];
361
362                 /* Acquire next object */
363                 next_o_idx = o_ptr->next_o_idx;
364
365                 /* Reset monster pointer */
366                 o_ptr->held_m_idx = i2;
367         }
368
369         /* Hack -- Update the target */
370         if (target_who == i1) target_who = i2;
371
372         /* Hack -- Update the target */
373         if (pet_t_m_idx == i1) pet_t_m_idx = i2;
374         if (riding_t_m_idx == i1) riding_t_m_idx = i2;
375
376         /* Hack -- Update the riding */
377         if (p_ptr->riding == i1) p_ptr->riding = i2;
378
379         /* Hack -- Update the health bar */
380         if (p_ptr->health_who == i1) health_track(i2);
381
382         /* Hack -- Update parent index */
383         if (is_pet(m_ptr))
384         {
385                 for (i = 1; i < m_max; i++)
386                 {
387                         monster_type *m2_ptr = &m_list[i];
388
389                         if (m2_ptr->parent_m_idx == i1)
390                                 m2_ptr->parent_m_idx = i2;
391                 }
392         }
393
394         /* Structure copy */
395         (void)COPY(&m_list[i2], &m_list[i1], monster_type);
396
397         /* Wipe the hole */
398         (void)WIPE(&m_list[i1], monster_type);
399
400         for (i = 0; i < MAX_MTIMED; i++)
401         {
402                 int mproc_idx = get_mproc_idx(i1, i);
403                 if (mproc_idx >= 0) mproc_list[i][mproc_idx] = i2;
404         }
405 }
406
407
408 /*!
409  * @brief モンスター情報配列を圧縮する / Compact and Reorder the monster list
410  * @param size 圧縮後のモンスター件数目標
411  * @return なし
412  * @details
413  * This function can be very dangerous, use with caution!
414  *
415  * When actually "compacting" monsters, we base the saving throw
416  * on a combination of monster level, distance from player, and
417  * current "desperation".
418  *
419  * After "compacting" (if needed), we "reorder" the monsters into a more
420  * compact order, and we reset the allocation info, and the "live" array.
421  */
422 void compact_monsters(int size)
423 {
424         MONSTER_IDX i;
425         int num, cnt;
426         int cur_lev, cur_dis, chance;
427
428         /* Message (only if compacting) */
429         if (size) msg_print(_("モンスター情報を圧縮しています...", "Compacting monsters..."));
430
431
432         /* Compact at least 'size' objects */
433         for (num = 0, cnt = 1; num < size; cnt++)
434         {
435                 /* Get more vicious each iteration */
436                 cur_lev = 5 * cnt;
437
438                 /* Get closer each iteration */
439                 cur_dis = 5 * (20 - cnt);
440
441                 /* Check all the monsters */
442                 for (i = 1; i < m_max; i++)
443                 {
444                         monster_type *m_ptr = &m_list[i];
445
446                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
447
448                         /* Paranoia -- skip "dead" monsters */
449                         if (!m_ptr->r_idx) continue;
450
451                         /* Hack -- High level monsters start out "immune" */
452                         if (r_ptr->level > cur_lev) continue;
453
454                         if (i == p_ptr->riding) continue;
455
456                         /* Ignore nearby monsters */
457                         if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
458
459                         /* Saving throw chance */
460                         chance = 90;
461
462                         /* Only compact "Quest" Monsters in emergencies */
463                         if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
464
465                         /* Try not to compact Unique Monsters */
466                         if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
467
468                         /* All monsters get a saving throw */
469                         if (randint0(100) < chance) continue;
470
471                         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
472                         {
473                                 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                 cave[m_ptr->fy][m_ptr->fx].m_idx = 0;
544
545                 /* Wipe the Monster */
546                 (void)WIPE(m_ptr, monster_type);
547
548         }
549
550         /*
551          * Wiping racial counters of all monsters and incrementing of racial
552          * counters of monsters in party_mon[] are required to prevent multiple
553          * generation of unique monster who is the minion of player.
554          */
555
556         /* Hack -- Wipe the racial counter of all monster races */
557         for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
558
559         /* Reset "m_max" */
560         m_max = 1;
561
562         /* Reset "m_cnt" */
563         m_cnt = 0;
564
565         /* Reset "mproc_max[]" */
566         for (i = 0; i < MAX_MTIMED; i++) mproc_max[i] = 0;
567
568         /* Hack -- reset "reproducer" count */
569         num_repro = 0;
570
571         /* Hack -- no more target */
572         target_who = 0;
573         pet_t_m_idx = 0;
574         riding_t_m_idx = 0;
575
576         /* Hack -- no more tracking */
577         health_track(0);
578 }
579
580
581 /*!
582  * @brief モンスター配列の空きを探す / Acquires and returns the index of a "free" monster.
583  * @return 利用可能なモンスター配列の添字
584  * @details
585  * This routine should almost never fail, but it *can* happen.
586  */
587 MONSTER_IDX m_pop(void)
588 {
589         MONSTER_IDX i;
590
591         /* Normal allocation */
592         if (m_max < max_m_idx)
593         {
594                 /* Access the next hole */
595                 i = m_max;
596
597                 /* Expand the array */
598                 m_max++;
599
600                 /* Count monsters */
601                 m_cnt++;
602
603                 /* Return the index */
604                 return (i);
605         }
606
607         /* Recycle dead monsters */
608         for (i = 1; i < m_max; i++)
609         {
610                 monster_type *m_ptr;
611
612                 /* Acquire monster */
613                 m_ptr = &m_list[i];
614
615                 /* Skip live monsters */
616                 if (m_ptr->r_idx) continue;
617
618                 /* Count monsters */
619                 m_cnt++;
620
621                 /* Use this monster */
622                 return (i);
623         }
624
625         /* Warn the player (except during dungeon creation) */
626         if (character_dungeon) msg_print(_("モンスターが多すぎる!", "Too many monsters!"));
627
628         /* Try not to crash */
629         return (0);
630 }
631
632
633
634
635 /*!
636  * @var summon_specific_type
637  * @brief 召喚条件を指定するグローバル変数 / Hack -- the "type" of the current "summon specific"
638  * @todo summon_specific_typeグローバル変数の除去と関数引数への代替を行う
639  */
640 static int summon_specific_type = 0;
641
642
643 /*!
644  * @var summon_specific_who
645  * @brief 召喚を行ったプレイヤーあるいはモンスターのIDを示すグローバル変数 / Hack -- the index of the summoning monster
646  * @todo summon_specific_who グローバル変数の除去と関数引数への代替を行う
647  */
648 static int summon_specific_who = -1;
649
650 /*!
651  * @var summon_unique_okay
652  * @brief 召喚対象にユニークを含めるかを示すグローバル変数 / summoning unique enable
653  * @todo summon_unique_okay グローバル変数の除去と関数引数への代替を行う
654  */
655 static bool summon_unique_okay = FALSE;
656
657 /*!
658  * @brief 指定されたモンスター種族がsummon_specific_typeで指定された召喚条件に合うかどうかを返す
659  * @return 召喚条件が一致するならtrue
660  * @details
661  */
662 static bool summon_specific_aux(MONRACE_IDX r_idx)
663 {
664         monster_race *r_ptr = &r_info[r_idx];
665         int okay = FALSE;
666
667         /* Check our requirements */
668         switch (summon_specific_type)
669         {
670                 case SUMMON_ANT:
671                 {
672                         okay = (r_ptr->d_char == 'a');
673                         break;
674                 }
675
676                 case SUMMON_SPIDER:
677                 {
678                         okay = (r_ptr->d_char == 'S');
679                         break;
680                 }
681
682                 case SUMMON_HOUND:
683                 {
684                         okay = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z'));
685                         break;
686                 }
687
688                 case SUMMON_HYDRA:
689                 {
690                         okay = (r_ptr->d_char == 'M');
691                         break;
692                 }
693
694                 case SUMMON_ANGEL:
695                 {
696                         okay = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD)));
697                         break;
698                 }
699
700                 case SUMMON_DEMON:
701                 {
702                         okay = (r_ptr->flags3 & RF3_DEMON);
703                         break;
704                 }
705
706                 case SUMMON_UNDEAD:
707                 {
708                         okay = (r_ptr->flags3 & RF3_UNDEAD);
709                         break;
710                 }
711
712                 case SUMMON_DRAGON:
713                 {
714                         okay = (r_ptr->flags3 & RF3_DRAGON);
715                         break;
716                 }
717
718                 case SUMMON_HI_UNDEAD:
719                 {
720                         okay = ((r_ptr->d_char == 'L') ||
721                                 (r_ptr->d_char == 'V') ||
722                                 (r_ptr->d_char == 'W'));
723                         break;
724                 }
725
726                 case SUMMON_HI_DRAGON:
727                 {
728                         okay = (r_ptr->d_char == 'D');
729                         break;
730                 }
731
732                 case SUMMON_HI_DEMON:
733                 {
734                         okay = (((r_ptr->d_char == 'U') ||
735                                  (r_ptr->d_char == 'H') ||
736                                  (r_ptr->d_char == 'B')) &&
737                                 (r_ptr->flags3 & RF3_DEMON)) ? TRUE : FALSE;
738                         break;
739                 }
740
741                 case SUMMON_AMBERITES:
742                 {
743                         okay = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE;
744                         break;
745                 }
746
747                 case SUMMON_UNIQUE:
748                 {
749                         okay = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE;
750                         break;
751                 }
752
753                 case SUMMON_MOLD:
754                 {
755                         okay = (r_ptr->d_char == 'm');
756                         break;
757                 }
758                 case SUMMON_BAT:
759                 {
760                         okay = (r_ptr->d_char == 'b');
761                         break;
762                 }
763                 case SUMMON_QUYLTHULG:
764                 {
765                         okay = (r_ptr->d_char == 'Q');
766                         break;
767                 }
768
769                 case SUMMON_COIN_MIMIC:
770                 {
771                         okay = (r_ptr->d_char == '$');
772                         break;
773                 }
774
775                 case SUMMON_MIMIC:
776                 {
777                         okay = ((r_ptr->d_char == '!') ||
778                                  (r_ptr->d_char == '?') ||
779                                  (r_ptr->d_char == '=') ||
780                                  (r_ptr->d_char == '$') ||
781                                  (r_ptr->d_char == '|'));
782                         break;
783                 }
784
785                 case SUMMON_GOLEM:
786                 {
787                         okay = (r_ptr->d_char == 'g');
788                         break;
789                 }
790
791                 case SUMMON_CYBER:
792                 {
793                         okay = ((r_ptr->d_char == 'U') &&
794                                 (r_ptr->flags4 & RF4_ROCKET));
795                         break;
796                 }
797
798                 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 #ifdef JP
1945                         msg_format("%s%sの顔を見てしまった!",
1946                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
1947 #else
1948                         msg_format("You behold the %s visage of %s!",
1949                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
1950 #endif
1951
1952                         if (one_in_(3))
1953                         {
1954                                 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
1955                                 p_ptr->image = p_ptr->image + randint1(r_ptr->level);
1956                         }
1957
1958                         return; /* Never mind; we can't see it clearly enough */
1959                 }
1960
1961                 /* Something frightening happens... */
1962 #ifdef JP
1963                 msg_format("%s%sの顔を見てしまった!",
1964                         horror_desc[randint0(MAX_SAN_HORROR)], m_name);
1965 #else
1966                 msg_format("You behold the %s visage of %s!",
1967                         horror_desc[randint0(MAX_SAN_HORROR)], m_name);
1968 #endif
1969
1970                 r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
1971
1972                 /* Demon characters are unaffected */
1973                 if (prace_is_(RACE_IMP) || prace_is_(RACE_DEMON) || (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) return;
1974                 if (p_ptr->wizard) return;
1975
1976                 /* Undead characters are 50% likely to be unaffected */
1977                 if (prace_is_(RACE_SKELETON) || prace_is_(RACE_ZOMBIE)
1978                         || prace_is_(RACE_VAMPIRE) || prace_is_(RACE_SPECTRE) ||
1979                     (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD))
1980                 {
1981                         if (saving_throw(25 + p_ptr->lev)) return;
1982                 }
1983         }
1984         else if(!necro)
1985         {
1986                 monster_race *r_ptr;
1987                 GAME_TEXT m_name[MAX_NLEN];
1988                 concptr desc;
1989
1990                 get_mon_num_prep(get_nightmare, NULL);
1991
1992                 r_ptr = &r_info[get_mon_num(MAX_DEPTH)];
1993                 power = r_ptr->level + 10;
1994                 desc = r_name + r_ptr->name;
1995
1996                 get_mon_num_prep(NULL, NULL);
1997
1998 #ifndef JP
1999                 if (!(r_ptr->flags1 & RF1_UNIQUE))
2000                         sprintf(m_name, "%s %s", (is_a_vowel(desc[0]) ? "an" : "a"), desc);
2001                 else
2002 #endif
2003                 sprintf(m_name, "%s", desc);
2004
2005                 if (!(r_ptr->flags1 & RF1_UNIQUE))
2006                 {
2007                         if (r_ptr->flags1 & RF1_FRIENDS) power /= 2;
2008                 }
2009                 else power *= 2;
2010
2011                 if (saving_throw(p_ptr->skill_sav * 100 / power))
2012                 {
2013                         msg_format(_("夢の中で%sに追いかけられた。", "%^s chases you through your dreams."), m_name);
2014                         /* Safe */
2015                         return;
2016                 }
2017
2018                 if (p_ptr->image)
2019                 {
2020                         /* Something silly happens... */
2021                         msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"),
2022                                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2023
2024                         if (one_in_(3))
2025                         {
2026                                 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
2027                                 p_ptr->image = p_ptr->image + randint1(r_ptr->level);
2028                         }
2029
2030                         /* Never mind; we can't see it clearly enough */
2031                         return;
2032                 }
2033
2034                 /* Something frightening happens... */
2035                 msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"),
2036                                   horror_desc[randint0(MAX_SAN_HORROR)], desc);
2037
2038                 r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
2039
2040                 if (!p_ptr->mimic_form)
2041                 {
2042                         switch (p_ptr->prace)
2043                         {
2044                         /* Demons may make a saving throw */
2045                         case RACE_IMP:
2046                         case RACE_DEMON:
2047                                 if (saving_throw(20 + p_ptr->lev)) return;
2048                                 break;
2049                         /* Undead may make a saving throw */
2050                         case RACE_SKELETON:
2051                         case RACE_ZOMBIE:
2052                         case RACE_SPECTRE:
2053                         case RACE_VAMPIRE:
2054                                 if (saving_throw(10 + p_ptr->lev)) return;
2055                                 break;
2056                         }
2057                 }
2058                 else
2059                 {
2060                         /* Demons may make a saving throw */
2061                         if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)
2062                         {
2063                                 if (saving_throw(20 + p_ptr->lev)) return;
2064                         }
2065                         /* Undead may make a saving throw */
2066                         else if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD)
2067                         {
2068                                 if (saving_throw(10 + p_ptr->lev)) return;
2069                         }
2070                 }
2071         }
2072         else
2073         {
2074                 msg_print(_("ネクロノミコンを読んで正気を失った!", "Your sanity is shaken by reading the Necronomicon!"));
2075         }
2076
2077         if (saving_throw(p_ptr->skill_sav - power))
2078         {
2079                 return;
2080         }
2081
2082         do {
2083                 (void)do_dec_stat(A_INT);
2084         } while (randint0(100) > p_ptr->skill_sav && one_in_(2));
2085
2086         do {
2087                 (void)do_dec_stat(A_WIS);
2088         } while (randint0(100) > p_ptr->skill_sav && one_in_(2));
2089
2090         switch (randint1(21))
2091         {
2092         case 1:
2093                 if (!(p_ptr->muta3 & MUT3_MORONIC) && one_in_(5))
2094                 {
2095                         if ((p_ptr->stat_use[A_INT] < 4) && (p_ptr->stat_use[A_WIS] < 4))
2096                         {
2097                                 msg_print(_("あなたは完璧な馬鹿になったような気がした。しかしそれは元々だった。", "You turn into an utter moron!"));
2098                         }
2099                         else
2100                         {
2101                                 msg_print(_("あなたは完璧な馬鹿になった!", "You turn into an utter moron!"));
2102                         }
2103
2104                         if (p_ptr->muta3 & MUT3_HYPER_INT)
2105                         {
2106                                 msg_print(_("あなたの脳は生体コンピュータではなくなった。", "Your brain is no longer a living computer."));
2107                                 p_ptr->muta3 &= ~(MUT3_HYPER_INT);
2108                         }
2109                         p_ptr->muta3 |= MUT3_MORONIC;
2110                 }
2111                 break;
2112         case 2:
2113         case 3:
2114         case 4:
2115                 if (!(p_ptr->muta2 & MUT2_COWARDICE) && !p_ptr->resist_fear)
2116                 {
2117                         msg_print(_("あなたはパラノイアになった!", "You become paranoid!"));
2118
2119                         /* Duh, the following should never happen, but anyway... */
2120                         if (p_ptr->muta3 & MUT3_FEARLESS)
2121                         {
2122                                 msg_print(_("あなたはもう恐れ知らずではなくなった。", "You are no longer fearless."));
2123                                 p_ptr->muta3 &= ~(MUT3_FEARLESS);
2124                         }
2125
2126                         p_ptr->muta2 |= MUT2_COWARDICE;
2127                 }
2128                 break;
2129         case 5:
2130         case 6:
2131         case 7:
2132                 if (!(p_ptr->muta2 & MUT2_HALLU) && !p_ptr->resist_chaos)
2133                 {
2134                         msg_print(_("幻覚をひき起こす精神錯乱に陥った!", "You are afflicted by a hallucinatory insanity!"));
2135                         p_ptr->muta2 |= MUT2_HALLU;
2136                 }
2137                 break;
2138         case 8:
2139         case 9:
2140         case 10:
2141                 if (!(p_ptr->muta2 & MUT2_BERS_RAGE))
2142                 {
2143                         msg_print(_("激烈な感情の発作におそわれるようになった!", "You become subject to fits of berserk rage!"));
2144                         p_ptr->muta2 |= MUT2_BERS_RAGE;
2145                 }
2146                 break;
2147         case 11:
2148         case 12:
2149         case 13:
2150         case 14:
2151         case 15:
2152         case 16:
2153                 /* Brain smash */
2154                 if (!p_ptr->resist_conf)
2155                 {
2156                         (void)set_confused(p_ptr->confused + randint0(4) + 4);
2157                 }
2158                 if (!p_ptr->free_act)
2159                 {
2160                         (void)set_paralyzed(p_ptr->paralyzed + randint0(4) + 4);
2161                 }
2162                 if (!p_ptr->resist_chaos)
2163                 {
2164                         (void)set_image(p_ptr->image + randint0(250) + 150);
2165                 }
2166                 break;
2167         case 17:
2168         case 18:
2169         case 19:
2170         case 20:
2171         case 21:
2172                 /* Amnesia */
2173                 if (lose_all_info())
2174                         msg_print(_("あまりの恐怖に全てのことを忘れてしまった!", "You forget everything in your utmost terror!"));
2175                 break;
2176         }
2177
2178         p_ptr->update |= PU_BONUS;
2179         handle_stuff();
2180 }
2181
2182 /*!
2183  * @brief モンスターの各情報を更新する / This function updates the monster record of the given monster
2184  * @param m_idx 更新するモンスター情報のID
2185  * @param full プレイヤーとの距離更新を行うならばtrue
2186  * @return なし
2187  * @details
2188  * This involves extracting the distance to the player (if requested),
2189  * and then checking for visibility (natural, infravision, see-invis,
2190  * telepathy), updating the monster visibility flag, redrawing (or
2191  * erasing) the monster when its visibility changes, and taking note
2192  * of any interesting monster flags (cold-blooded, invisible, etc).
2193  *
2194  * Note the new "mflag" field which encodes several monster state flags,
2195  * including "view" for when the monster is currently in line of sight,
2196  * and "mark" for when the monster is currently visible via detection.
2197  *
2198  * The only monster fields that are changed here are "cdis" (the
2199  * distance from the player), "ml" (visible to the player), and
2200  * "mflag" (to maintain the "MFLAG_VIEW" flag).
2201  *
2202  * Note the special "update_monsters()" function which can be used to
2203  * call this function once for every monster.
2204  *
2205  * Note the "full" flag which requests that the "cdis" field be updated,
2206  * this is only needed when the monster (or the player) has moved.
2207  *
2208  * Every time a monster moves, we must call this function for that
2209  * monster, and update the distance, and the visibility.  Every time
2210  * the player moves, we must call this function for every monster, and
2211  * update the distance, and the visibility.  Whenever the player "state"
2212  * changes in certain ways ("blindness", "infravision", "telepathy",
2213  * and "see invisible"), we must call this function for every monster,
2214  * and update the visibility.
2215  *
2216  * Routines that change the "illumination" of a grid must also call this
2217  * function for any monster in that grid, since the "visibility" of some
2218  * monsters may be based on the illumination of their grid.
2219  *
2220  * Note that this function is called once per monster every time the
2221  * player moves.  When the player is running, this function is one
2222  * of the primary bottlenecks, along with "update_view()" and the
2223  * "process_monsters()" code, so efficiency is important.
2224  *
2225  * Note the optimized "inline" version of the "distance()" function.
2226  *
2227  * A monster is "visible" to the player if (1) it has been detected
2228  * by the player, (2) it is close to the player and the player has
2229  * telepathy, or (3) it is close to the player, and in line of sight
2230  * of the player, and it is "illuminated" by some combination of
2231  * infravision, torch light, or permanent light (invisible monsters
2232  * are only affected by "light" if the player can see invisible).
2233  *
2234  * Monsters which are not on the current panel may be "visible" to
2235  * the player, and their descriptions will include an "offscreen"
2236  * reference.  Currently, offscreen monsters cannot be targetted
2237  * or viewed directly, but old targets will remain set.  XXX XXX
2238  *
2239  * The player can choose to be disturbed by several things, including
2240  * "disturb_move" (monster which is viewable moves in some way), and
2241  * "disturb_near" (monster which is "easily" viewable moves in some
2242  * way).  Note that "moves" includes "appears" and "disappears".
2243  */
2244 void update_monster(MONSTER_IDX m_idx, bool full)
2245 {
2246         monster_type *m_ptr = &m_list[m_idx];
2247
2248         monster_race *r_ptr = &r_info[m_ptr->r_idx];
2249
2250         bool do_disturb = disturb_move;
2251
2252         int d;
2253
2254         /* Current location */
2255         int fy = m_ptr->fy;
2256         int fx = m_ptr->fx;
2257
2258         /* Seen at all */
2259         bool flag = FALSE;
2260
2261         /* Seen by vision */
2262         bool easy = FALSE;
2263
2264         /* Non-Ninja player in the darkness */
2265         bool in_darkness = (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto;
2266
2267         /* Do disturb? */
2268         if (disturb_high)
2269         {
2270                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2271
2272                 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
2273                         do_disturb = TRUE;
2274         }
2275
2276         /* Compute distance */
2277         if (full)
2278         {
2279                 /* Distance components */
2280                 int dy = (p_ptr->y > fy) ? (p_ptr->y - fy) : (fy - p_ptr->y);
2281                 int dx = (p_ptr->x > fx) ? (p_ptr->x - fx) : (fx - p_ptr->x);
2282
2283                 /* Approximate distance */
2284                 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2285
2286                 /* Restrict distance */
2287                 if (d > 255) d = 255;
2288
2289                 if (!d) d = 1;
2290
2291                 /* Save the distance */
2292                 m_ptr->cdis = d;
2293         }
2294
2295         /* Extract distance */
2296         else
2297         {
2298                 /* Extract the distance */
2299                 d = m_ptr->cdis;
2300         }
2301
2302
2303         /* Detected */
2304         if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
2305
2306
2307         /* Nearby */
2308         if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
2309         {
2310                 if (!in_darkness || (d <= MAX_SIGHT / 4))
2311                 {
2312                         if (p_ptr->special_defense & KATA_MUSOU)
2313                         {
2314                                 /* Detectable */
2315                                 flag = TRUE;
2316
2317                                 if (is_original_ap(m_ptr) && !p_ptr->image)
2318                                 {
2319                                         /* Hack -- Memorize mental flags */
2320                                         if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2321                                         if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2322                                 }
2323                         }
2324
2325                         /* Basic telepathy */
2326                         /* Snipers get telepathy when they concentrate deeper */
2327                         else if (p_ptr->telepathy)
2328                         {
2329                                 /* Empty mind, no telepathy */
2330                                 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
2331                                 {
2332                                         /* Memorize flags */
2333                                         if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
2334                                 }
2335
2336                                 /* Weird mind, occasional telepathy */
2337                                 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
2338                                 {
2339                                         /* One in ten individuals are detectable */
2340                                         if ((m_idx % 10) == 5)
2341                                         {
2342                                                 /* Detectable */
2343                                                 flag = TRUE;
2344
2345                                                 if (is_original_ap(m_ptr) && !p_ptr->image)
2346                                                 {
2347                                                         /* Memorize flags */
2348                                                         r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
2349
2350                                                         /* Hack -- Memorize mental flags */
2351                                                         if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2352                                                         if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2353                                                 }
2354                                         }
2355                                 }
2356
2357                                 /* Normal mind, allow telepathy */
2358                                 else
2359                                 {
2360                                         /* Detectable */
2361                                         flag = TRUE;
2362
2363                                         if (is_original_ap(m_ptr) && !p_ptr->image)
2364                                         {
2365                                                 /* Hack -- Memorize mental flags */
2366                                                 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2367                                                 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2368                                         }
2369                                 }
2370                         }
2371
2372                         /* Magical sensing */
2373                         if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
2374                         {
2375                                 flag = TRUE;
2376                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ANIMAL);
2377                         }
2378
2379                         /* Magical sensing */
2380                         if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
2381                         {
2382                                 flag = TRUE;
2383                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_UNDEAD);
2384                         }
2385
2386                         /* Magical sensing */
2387                         if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
2388                         {
2389                                 flag = TRUE;
2390                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DEMON);
2391                         }
2392
2393                         /* Magical sensing */
2394                         if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
2395                         {
2396                                 flag = TRUE;
2397                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ORC);
2398                         }
2399
2400                         /* Magical sensing */
2401                         if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
2402                         {
2403                                 flag = TRUE;
2404                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_TROLL);
2405                         }
2406
2407                         /* Magical sensing */
2408                         if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
2409                         {
2410                                 flag = TRUE;
2411                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GIANT);
2412                         }
2413
2414                         /* Magical sensing */
2415                         if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
2416                         {
2417                                 flag = TRUE;
2418                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DRAGON);
2419                         }
2420
2421                         /* Magical sensing */
2422                         if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
2423                         {
2424                                 flag = TRUE;
2425                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_HUMAN);
2426                         }
2427
2428                         /* Magical sensing */
2429                         if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
2430                         {
2431                                 flag = TRUE;
2432                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_EVIL);
2433                         }
2434
2435                         /* Magical sensing */
2436                         if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
2437                         {
2438                                 flag = TRUE;
2439                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GOOD);
2440                         }
2441
2442                         /* Magical sensing */
2443                         if ((p_ptr->esp_nonliving) &&
2444                             ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
2445                         {
2446                                 flag = TRUE;
2447                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_NONLIVING);
2448                         }
2449
2450                         /* Magical sensing */
2451                         if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
2452                         {
2453                                 flag = TRUE;
2454                                 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags1 |= (RF1_UNIQUE);
2455                         }
2456                 }
2457
2458                 /* Normal line of sight, and not blind */
2459                 if (player_has_los_bold(fy, fx) && !p_ptr->blind)
2460                 {
2461                         bool do_invisible = FALSE;
2462                         bool do_cold_blood = FALSE;
2463
2464                         /* Snipers can see targets in darkness when they concentrate deeper */
2465                         if (p_ptr->concent >= CONCENT_RADAR_THRESHOLD)
2466                         {
2467                                 /* Easy to see */
2468                                 easy = flag = TRUE;
2469                         }
2470
2471                         /* Use "infravision" */
2472                         if (d <= p_ptr->see_infra)
2473                         {
2474                                 /* Handle "cold blooded" monsters */
2475                                 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
2476                                 {
2477                                         do_cold_blood = TRUE;
2478                                 }
2479
2480                                 /* Handle "warm blooded" monsters */
2481                                 else
2482                                 {
2483                                         /* Easy to see */
2484                                         easy = flag = TRUE;
2485                                 }
2486                         }
2487
2488                         /* Use "illumination" */
2489                         if (player_can_see_bold(fy, fx))
2490                         {
2491                                 /* Handle "invisible" monsters */
2492                                 if (r_ptr->flags2 & (RF2_INVISIBLE))
2493                                 {
2494                                         do_invisible = TRUE;
2495
2496                                         /* See invisible */
2497                                         if (p_ptr->see_inv)
2498                                         {
2499                                                 /* Easy to see */
2500                                                 easy = flag = TRUE;
2501                                         }
2502                                 }
2503
2504                                 /* Handle "normal" monsters */
2505                                 else
2506                                 {
2507                                         /* Easy to see */
2508                                         easy = flag = TRUE;
2509                                 }
2510                         }
2511
2512                         /* Visible */
2513                         if (flag)
2514                         {
2515                                 if (is_original_ap(m_ptr) && !p_ptr->image)
2516                                 {
2517                                         /* Memorize flags */
2518                                         if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2519                                         if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2520                                 }
2521                         }
2522                 }
2523         }
2524
2525
2526         /* The monster is now visible */
2527         if (flag)
2528         {
2529                 /* It was previously unseen */
2530                 if (!m_ptr->ml)
2531                 {
2532                         /* Mark as visible */
2533                         m_ptr->ml = TRUE;
2534
2535                         /* Draw the monster */
2536                         lite_spot(fy, fx);
2537
2538                         /* Update health bar as needed */
2539                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2540                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2541
2542                         /* Hack -- Count "fresh" sightings */
2543                         if (!p_ptr->image)
2544                         {
2545                                 if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2546                                         r_info[MON_KAGE].r_sights++;
2547                                 else if (is_original_ap(m_ptr) && (r_ptr->r_sights < MAX_SHORT))
2548                                         r_ptr->r_sights++;
2549                         }
2550
2551                         /* Eldritch Horror */
2552                         if (r_info[m_ptr->ap_r_idx].flags2 & RF2_ELDRITCH_HORROR)
2553                         {
2554                                 sanity_blast(m_ptr, FALSE);
2555                         }
2556
2557                         /* Disturb on appearance */
2558                         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)))
2559                         {
2560                                 if (disturb_pets || is_hostile(m_ptr))
2561                                         disturb(TRUE, TRUE);
2562                         }
2563                 }
2564         }
2565
2566         /* The monster is not visible */
2567         else
2568         {
2569                 /* It was previously seen */
2570                 if (m_ptr->ml)
2571                 {
2572                         /* Mark as not visible */
2573                         m_ptr->ml = FALSE;
2574
2575                         /* Erase the monster */
2576                         lite_spot(fy, fx);
2577
2578                         /* Update health bar as needed */
2579                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2580                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2581
2582                         /* Disturb on disappearance */
2583                         if (do_disturb)
2584                         {
2585                                 if (disturb_pets || is_hostile(m_ptr))
2586                                         disturb(TRUE, TRUE);
2587                         }
2588                 }
2589         }
2590
2591
2592         /* The monster is now easily visible */
2593         if (easy)
2594         {
2595                 /* Change */
2596                 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2597                 {
2598                         /* Mark as easily visible */
2599                         m_ptr->mflag |= (MFLAG_VIEW);
2600
2601                         /* Disturb on appearance */
2602                         if (do_disturb)
2603                         {
2604                                 if (disturb_pets || is_hostile(m_ptr))
2605                                         disturb(TRUE, TRUE);
2606                         }
2607                 }
2608         }
2609
2610         /* The monster is not easily visible */
2611         else
2612         {
2613                 /* Change */
2614                 if (m_ptr->mflag & (MFLAG_VIEW))
2615                 {
2616                         /* Mark as not easily visible */
2617                         m_ptr->mflag &= ~(MFLAG_VIEW);
2618
2619                         /* Disturb on disappearance */
2620                         if (do_disturb)
2621                         {
2622                                 if (disturb_pets || is_hostile(m_ptr))
2623                                         disturb(TRUE, TRUE);
2624                         }
2625                 }
2626         }
2627 }
2628
2629
2630 /*!
2631  * @brief 単純に生存している全モンスターの更新処理を行う / This function simply updates all the (non-dead) monsters (see above).
2632  * @param full 距離更新を行うならtrue
2633  * @return なし
2634  */
2635 void update_monsters(bool full)
2636 {
2637         IDX i;
2638
2639         /* Update each (live) monster */
2640         for (i = 1; i < m_max; i++)
2641         {
2642                 monster_type *m_ptr = &m_list[i];
2643
2644                 /* Skip dead monsters */
2645                 if (!m_ptr->r_idx) continue;
2646                 update_monster(i, full);
2647         }
2648 }
2649
2650
2651 /*!
2652  * @brief カメレオンの王の変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2653  * @param r_idx モンスター種族ID
2654  * @return 対象にできるならtrueを返す
2655  */
2656 static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx)
2657 {
2658         monster_race *r_ptr = &r_info[r_idx];
2659         monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2660         monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2661
2662         if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2663         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2664
2665         if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2666
2667         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))
2668                 return FALSE;
2669
2670         if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2671
2672         /* Not born */
2673         if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2674         {
2675                 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
2676         }
2677
2678         /* Born now */
2679         else if (summon_specific_who > 0)
2680         {
2681                 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2682         }
2683
2684         return TRUE;
2685 }
2686
2687 /*!
2688  * @brief カメレオンの変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2689  * @param r_idx モンスター種族ID
2690  * @return 対象にできるならtrueを返す
2691  */
2692 static bool monster_hook_chameleon(MONRACE_IDX r_idx)
2693 {
2694         monster_race *r_ptr = &r_info[r_idx];
2695         monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2696         monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2697
2698         if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2699         if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2700         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2701         
2702         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))
2703                 return FALSE;
2704
2705         if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2706
2707         /* Not born */
2708         if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2709         {
2710                 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2711                 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2712                 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2713         }
2714
2715         /* Born now */
2716         else if (summon_specific_who > 0)
2717         {
2718                 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2719         }
2720
2721         return (*(get_monster_hook()))(r_idx);
2722 }
2723
2724 /*!
2725  * @brief モンスターの変身処理
2726  * @param m_idx 変身処理を受けるモンスター情報のID
2727  * @param born 生成時の初変身先指定ならばtrue
2728  * @param r_idx 旧モンスター種族のID
2729  * @return なし
2730  */
2731 void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
2732 {
2733         int oldmaxhp;
2734         monster_type *m_ptr = &m_list[m_idx];
2735         monster_race *r_ptr;
2736         char old_m_name[MAX_NLEN];
2737         bool old_unique = FALSE;
2738         int old_r_idx = m_ptr->r_idx;
2739
2740         if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2741                 old_unique = TRUE;
2742         if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2743         r_ptr = &r_info[r_idx];
2744
2745         monster_desc(old_m_name, m_ptr, 0);
2746
2747         if (!r_idx)
2748         {
2749                 DEPTH level;
2750
2751                 chameleon_change_m_idx = m_idx;
2752                 if (old_unique)
2753                         get_mon_num_prep(monster_hook_chameleon_lord, NULL);
2754                 else
2755                         get_mon_num_prep(monster_hook_chameleon, NULL);
2756
2757                 if (old_unique)
2758                         level = r_info[MON_CHAMELEON_K].level;
2759                 else if (!dun_level)
2760                         level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
2761                 else
2762                         level = dun_level;
2763
2764                 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
2765
2766                 r_idx = get_mon_num(level);
2767                 r_ptr = &r_info[r_idx];
2768
2769                 chameleon_change_m_idx = 0;
2770
2771                 /* Paranoia */
2772                 if (!r_idx) return;
2773         }
2774
2775         if (is_pet(m_ptr)) check_pets_num_and_align(m_ptr, FALSE);
2776
2777         m_ptr->r_idx = r_idx;
2778         m_ptr->ap_r_idx = r_idx;
2779         update_monster(m_idx, FALSE);
2780         lite_spot(m_ptr->fy, m_ptr->fx);
2781
2782         if ((r_info[old_r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) ||
2783             (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)))
2784                 p_ptr->update |= (PU_MON_LITE);
2785
2786         if (is_pet(m_ptr)) check_pets_num_and_align(m_ptr, TRUE);
2787
2788         if (born)
2789         {
2790                 /* Sub-alignment of a chameleon */
2791                 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2792                 {
2793                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2794                         if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2795                         if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2796                 }
2797                 return;
2798         }
2799
2800         if (m_idx == p_ptr->riding)
2801         {
2802                 GAME_TEXT m_name[MAX_NLEN];
2803                 monster_desc(m_name, m_ptr, 0);
2804                 msg_format(_("突然%sが変身した。", "Suddenly, %s transforms!"), old_m_name);
2805                 if (!(r_ptr->flags7 & RF7_RIDING))
2806                         if (rakuba(0, TRUE)) msg_format(_("地面に落とされた。", "You have fallen from %s."), m_name);
2807         }
2808
2809         /* Extract the monster base speed */
2810         m_ptr->mspeed = get_mspeed(r_ptr);
2811
2812         oldmaxhp = m_ptr->max_maxhp;
2813         /* Assign maximal hitpoints */
2814         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2815         {
2816                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2817         }
2818         else
2819         {
2820                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2821         }
2822
2823         /* Monsters have double hitpoints in Nightmare mode */
2824         if (ironman_nightmare)
2825         {
2826                 u32b hp = m_ptr->max_maxhp * 2L;
2827                 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2828         }
2829
2830         m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2831         if (m_ptr->maxhp < 1) m_ptr->maxhp = 1;
2832         m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2833         
2834         /* reset dealt_damage */
2835         m_ptr->dealt_damage = 0;
2836 }
2837
2838
2839 /*!
2840  * @brief たぬきの変身対象となるモンスターかどうか判定する / Hook for Tanuki
2841  * @param r_idx モンスター種族ID
2842  * @return 対象にできるならtrueを返す
2843  */
2844 static bool monster_hook_tanuki(MONRACE_IDX r_idx)
2845 {
2846         monster_race *r_ptr = &r_info[r_idx];
2847
2848         if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2849         if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2850         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2851         if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2852         
2853         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))
2854                 return FALSE;
2855
2856         return (*(get_monster_hook()))(r_idx);
2857 }
2858
2859
2860 /*!
2861  * @brief モンスターの表層IDを設定する / Set initial racial appearance of a monster
2862  * @param r_idx モンスター種族ID
2863  * @return モンスター種族の表層ID
2864  */
2865 static IDX initial_r_appearance(MONRACE_IDX r_idx)
2866 {
2867         int attempts = 1000;
2868         IDX ap_r_idx;
2869         DEPTH min = MIN(base_level-5, 50);
2870
2871         if (p_ptr->pseikaku == SEIKAKU_CHARGEMAN)
2872         {
2873                 if (base_level == 0 || one_in_(5)) return MON_ALIEN_JURAL;
2874         }
2875
2876         if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2877                 return r_idx;
2878
2879         get_mon_num_prep(monster_hook_tanuki, NULL);
2880
2881         while (--attempts)
2882         {
2883                 ap_r_idx = get_mon_num(base_level + 10);
2884                 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2885         }
2886
2887         return r_idx;
2888 }
2889
2890
2891 /*!
2892  * @brief モンスターの個体加速を設定する / Get initial monster speed
2893  * @param r_ptr モンスター種族の参照ポインタ
2894  * @return 加速値
2895  */
2896 byte get_mspeed(monster_race *r_ptr)
2897 {
2898         /* Extract the monster base speed */
2899         int mspeed = r_ptr->speed;
2900
2901         /* Hack -- small racial variety */
2902         if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
2903         {
2904                 /* Allow some small variation per monster */
2905                 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2906                 if (i) mspeed += rand_spread(0, i);
2907         }
2908
2909         if (mspeed > 199) mspeed = 199;
2910
2911         return (byte)mspeed;
2912 }
2913
2914
2915 /*!
2916  * @brief モンスターを一体生成する / Attempt to place a monster of the given race at the given location.
2917  * @param who 召喚を行ったモンスターID
2918  * @param y 生成位置y座標
2919  * @param x 生成位置x座標
2920  * @param r_idx 生成モンスター種族
2921  * @param mode 生成オプション
2922  * @return 成功したらtrue
2923  * @details 
2924  * To give the player a sporting chance, any monster that appears in
2925  * line-of-sight and is extremely dangerous can be marked as
2926  * "FORCE_SLEEP", which will cause them to be placed with low energy,
2927  * which often (but not always) lets the player move before they do.
2928  *
2929  * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2930  *
2931  * Use special "here" and "dead" flags for unique monsters,
2932  * remove old "cur_num" and "max_num" fields.
2933  *
2934  * Actually, do something similar for artifacts, to simplify
2935  * the "preserve" mode, and to make the "what artifacts" flag more useful.
2936  *
2937  * This is the only function which may place a monster in the dungeon,
2938  * except for the savefile loading code.
2939  */
2940 static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2941 {
2942         /* Access the location */
2943         cave_type               *c_ptr = &cave[y][x];
2944         monster_type    *m_ptr;
2945         monster_race    *r_ptr = &r_info[r_idx];
2946         concptr         name = (r_name + r_ptr->name);
2947
2948         int cmi;
2949
2950         /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
2951         if (p_ptr->wild_mode) return FALSE;
2952
2953         /* Verify location */
2954         if (!in_bounds(y, x)) return (FALSE);
2955
2956         /* Paranoia */
2957         if (!r_idx) return (FALSE);
2958
2959         /* Paranoia */
2960         if (!r_ptr->name) return (FALSE);
2961
2962         if (!(mode & PM_IGNORE_TERRAIN))
2963         {
2964                 /* Not on the Pattern */
2965                 if (pattern_tile(y, x)) return FALSE;
2966
2967                 /* Require empty space (if not ghostly) */
2968                 if (!monster_can_enter(y, x, r_ptr, 0)) return FALSE;
2969         }
2970
2971         if (!p_ptr->inside_battle)
2972         {
2973                 /* Hack -- "unique" monsters must be "unique" */
2974                 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
2975                      (r_ptr->flags7 & (RF7_NAZGUL))) &&
2976                     (r_ptr->cur_num >= r_ptr->max_num))
2977                 {
2978                         /* Cannot create */
2979                         return (FALSE);
2980                 }
2981
2982                 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
2983                     (r_ptr->cur_num >= 1))
2984                 {
2985                         return (FALSE);
2986                 }
2987
2988                 if (r_idx == MON_BANORLUPART)
2989                 {
2990                         if (r_info[MON_BANOR].cur_num > 0) return FALSE;
2991                         if (r_info[MON_LUPART].cur_num > 0) return FALSE;
2992                 }
2993
2994                 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
2995                 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (dun_level < r_ptr->level) &&
2996                     (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
2997                 {
2998                         /* Cannot create */
2999                         return (FALSE);
3000                 }
3001         }
3002
3003         if (quest_number(dun_level))
3004         {
3005                 int hoge = quest_number(dun_level);
3006                 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
3007                 {
3008                         if(r_idx == quest[hoge].r_idx)
3009                         {
3010                                 int number_mon, i2, j2;
3011                                 number_mon = 0;
3012
3013                                 /* Count all quest monsters */
3014                                 for (i2 = 0; i2 < cur_wid; ++i2)
3015                                         for (j2 = 0; j2 < cur_hgt; j2++)
3016                                                 if (cave[j2][i2].m_idx > 0)
3017                                                         if (m_list[cave[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
3018                                                                 number_mon++;
3019                                 if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
3020                                         return FALSE;
3021                         }
3022                 }
3023         }
3024
3025         if (is_glyph_grid(c_ptr))
3026         {
3027                 if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
3028                 {
3029                         /* Describe observable breakage */
3030                         if (c_ptr->info & CAVE_MARK)
3031                         {
3032                                 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
3033                         }
3034
3035                         /* Forget the rune */
3036                         c_ptr->info &= ~(CAVE_MARK);
3037
3038                         /* Break the rune */
3039                         c_ptr->info &= ~(CAVE_OBJECT);
3040                         c_ptr->mimic = 0;
3041
3042                         note_spot(y, x);
3043                 }
3044                 else return FALSE;
3045         }
3046
3047         msg_format_wizard(CHEAT_MONSTER, _("%s(Lv%d)を生成しました。", "%s(Lv%d) was generated."), name, r_ptr->level);
3048
3049         if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL) || (r_ptr->level < 10)) mode &= ~PM_KAGE;
3050
3051         /* Make a new monster */
3052         c_ptr->m_idx = m_pop();
3053         hack_m_idx_ii = c_ptr->m_idx;
3054
3055         /* Mega-Hack -- catch "failure" */
3056         if (!c_ptr->m_idx) return (FALSE);
3057
3058
3059         /* Get a new monster record */
3060         m_ptr = &m_list[c_ptr->m_idx];
3061
3062         /* Save the race */
3063         m_ptr->r_idx = r_idx;
3064         m_ptr->ap_r_idx = initial_r_appearance(r_idx);
3065
3066         /* No flags */
3067         m_ptr->mflag = 0;
3068         m_ptr->mflag2 = 0;
3069
3070         /* Hack -- Appearance transfer */
3071         if ((mode & PM_MULTIPLY) && (who > 0) && !is_original_ap(&m_list[who]))
3072         {
3073                 m_ptr->ap_r_idx = m_list[who].ap_r_idx;
3074
3075                 /* Hack -- Shadower spawns Shadower */
3076                 if (m_list[who].mflag2 & MFLAG2_KAGE) m_ptr->mflag2 |= MFLAG2_KAGE;
3077         }
3078
3079         /* Sub-alignment of a monster */
3080         if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
3081                 m_ptr->sub_align = m_list[who].sub_align;
3082         else
3083         {
3084                 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3085                 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
3086                 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
3087         }
3088
3089         /* Place the monster at the location */
3090         m_ptr->fy = y;
3091         m_ptr->fx = x;
3092
3093
3094         /* No "timed status" yet */
3095         for (cmi = 0; cmi < MAX_MTIMED; cmi++) m_ptr->mtimed[cmi] = 0;
3096
3097         /* Unknown distance */
3098         m_ptr->cdis = 0;
3099
3100         reset_target(m_ptr);
3101
3102         m_ptr->nickname = 0;
3103
3104         m_ptr->exp = 0;
3105
3106
3107         /* Your pet summons its pet. */
3108         if (who > 0 && is_pet(&m_list[who]))
3109         {
3110                 mode |= PM_FORCE_PET;
3111                 m_ptr->parent_m_idx = who;
3112         }
3113         else
3114         {
3115                 m_ptr->parent_m_idx = 0;
3116         }
3117
3118         if (r_ptr->flags7 & RF7_CHAMELEON)
3119         {
3120                 choose_new_monster(c_ptr->m_idx, TRUE, 0);
3121                 r_ptr = &r_info[m_ptr->r_idx];
3122                 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
3123
3124                 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
3125                 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
3126                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3127         }
3128         else if ((mode & PM_KAGE) && !(mode & PM_FORCE_PET))
3129         {
3130                 m_ptr->ap_r_idx = MON_KAGE;
3131                 m_ptr->mflag2 |= MFLAG2_KAGE;
3132         }
3133
3134         if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
3135
3136         /* Not visible */
3137         m_ptr->ml = FALSE;
3138
3139         /* Pet? */
3140         if (mode & PM_FORCE_PET)
3141         {
3142                 set_pet(m_ptr);
3143         }
3144         /* Friendly? */
3145         else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
3146                  (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
3147         {
3148                 if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
3149         }
3150
3151         /* Assume no sleeping */
3152         m_ptr->mtimed[MTIMED_CSLEEP] = 0;
3153
3154         /* Enforce sleeping if needed */
3155         if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
3156         {
3157                 int val = r_ptr->sleep;
3158                 (void)set_monster_csleep(c_ptr->m_idx, (val * 2) + randint1(val * 10));
3159         }
3160
3161         /* Assign maximal hitpoints */
3162         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
3163         {
3164                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
3165         }
3166         else
3167         {
3168                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
3169         }
3170
3171         /* Monsters have double hitpoints in Nightmare mode */
3172         if (ironman_nightmare)
3173         {
3174                 u32b hp = m_ptr->max_maxhp * 2L;
3175
3176                 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
3177         }
3178
3179         m_ptr->maxhp = m_ptr->max_maxhp;
3180
3181         /* And start out fully healthy */
3182         if (m_ptr->r_idx == MON_WOUNDED_BEAR)
3183                 m_ptr->hp = m_ptr->maxhp / 2;
3184         else m_ptr->hp = m_ptr->maxhp;
3185         
3186         
3187         /* dealt damage is 0 at initial*/
3188         m_ptr->dealt_damage = 0;
3189
3190
3191         /* Extract the monster base speed */
3192         m_ptr->mspeed = get_mspeed(r_ptr);
3193
3194         if (mode & PM_HASTE) (void)set_monster_fast(c_ptr->m_idx, 100);
3195
3196         /* Give a random starting energy */
3197         if (!ironman_nightmare)
3198         {
3199                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
3200         }
3201         else
3202         {
3203                 /* Nightmare monsters are more prepared */
3204                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
3205         }
3206
3207         /* Force monster to wait for player, unless in Nightmare mode */
3208         if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
3209         {
3210                 /* Monster is still being nice */
3211                 m_ptr->mflag |= (MFLAG_NICE);
3212
3213                 /* Must repair monsters */
3214                 repair_monsters = TRUE;
3215         }
3216
3217         /* Hack -- see "process_monsters()" */
3218         if (c_ptr->m_idx < hack_m_idx)
3219         {
3220                 /* Monster is still being born */
3221                 m_ptr->mflag |= (MFLAG_BORN);
3222         }
3223
3224
3225         if (r_ptr->flags7 & RF7_SELF_LD_MASK)
3226                 p_ptr->update |= (PU_MON_LITE);
3227         else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !MON_CSLEEP(m_ptr))
3228                 p_ptr->update |= (PU_MON_LITE);
3229         update_monster(c_ptr->m_idx, TRUE);
3230
3231
3232         /* Count the monsters on the level */
3233         real_r_ptr(m_ptr)->cur_num++;
3234
3235         /*
3236          * Memorize location of the unique monster in saved floors.
3237          * A unique monster move from old saved floor.
3238          */
3239         if (character_dungeon &&
3240             ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)))
3241                 real_r_ptr(m_ptr)->floor_id = p_ptr->floor_id;
3242
3243         /* Hack -- Count the number of "reproducers" */
3244         if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
3245
3246         /* Hack -- Notice new multi-hued monsters */
3247         {
3248                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3249                 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
3250                         shimmer_monsters = TRUE;
3251         }
3252
3253         if (p_ptr->warning && character_dungeon)
3254         {
3255                 if (r_ptr->flags1 & RF1_UNIQUE)
3256                 {
3257                         concptr color;
3258                         object_type *o_ptr;
3259                         GAME_TEXT o_name[MAX_NLEN];
3260
3261                         if (r_ptr->level > p_ptr->lev + 30)
3262                                 color = _("黒く", "black");
3263                         else if (r_ptr->level > p_ptr->lev + 15)
3264                                 color = _("紫色に", "purple");
3265                         else if (r_ptr->level > p_ptr->lev + 5)
3266                                 color = _("ルビー色に", "deep red");
3267                         else if (r_ptr->level > p_ptr->lev - 5)
3268                                 color = _("赤く", "red");
3269                         else if (r_ptr->level > p_ptr->lev - 15)
3270                                 color = _("ピンク色に", "pink");
3271                         else
3272                                 color = _("白く", "white");
3273
3274                         o_ptr = choose_warning_item();
3275                         if (o_ptr)
3276                         {
3277                                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3278                                 msg_format(_("%sは%s光った。", "%s glows %s."), o_name, color);
3279                         }
3280                         else
3281                         {
3282                                 msg_format(_("%s光る物が頭に浮かんだ。", "An %s image forms in your mind."), color);
3283                         }
3284                 }
3285         }
3286
3287         if (is_explosive_rune_grid(c_ptr))
3288         {
3289                 /* Break the ward */
3290                 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3291                 {
3292                         /* Describe observable breakage */
3293                         if (c_ptr->info & CAVE_MARK)
3294                         {
3295                                 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
3296                                 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);
3297                         }
3298                 }
3299                 else
3300                 {
3301                         msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
3302                 }
3303
3304                 /* Forget the rune */
3305                 c_ptr->info &= ~(CAVE_MARK);
3306
3307                 /* Break the rune */
3308                 c_ptr->info &= ~(CAVE_OBJECT);
3309                 c_ptr->mimic = 0;
3310
3311                 note_spot(y, x);
3312                 lite_spot(y, x);
3313         }
3314
3315         /* Success */
3316         return (TRUE);
3317 }
3318
3319
3320
3321 #define MON_SCAT_MAXD 10 /*!< mon_scatter()関数によるモンスター配置で許される中心からの最大距離 */
3322
3323 /*!
3324  * @brief モンスター1体を目標地点に可能な限り近い位置に生成する / improved version of scatter() for place monster
3325  * @param r_idx 生成モンスター種族
3326  * @param yp 結果生成位置y座標
3327  * @param xp 結果生成位置x座標
3328  * @param y 中心生成位置y座標
3329  * @param x 中心生成位置x座標
3330  * @param max_dist 生成位置の最大半径
3331  * @return 成功したらtrue
3332  *  
3333  */
3334 static bool mon_scatter(MONRACE_IDX r_idx, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION max_dist)
3335 {
3336         POSITION place_x[MON_SCAT_MAXD];
3337         POSITION place_y[MON_SCAT_MAXD];
3338         int num[MON_SCAT_MAXD];
3339         int i;
3340         POSITION nx, ny;
3341
3342         if (max_dist >= MON_SCAT_MAXD)
3343                 return FALSE;
3344
3345         for (i = 0; i < MON_SCAT_MAXD; i++)
3346                 num[i] = 0;
3347
3348         for (nx = x - max_dist; nx <= x + max_dist; nx++)
3349         {
3350                 for (ny = y - max_dist; ny <= y + max_dist; ny++)
3351                 {
3352                         /* Ignore annoying locations */
3353                         if (!in_bounds(ny, nx)) continue;
3354
3355                         /* Require "line of projection" */
3356                         if (!projectable(y, x, ny, nx)) continue;
3357
3358                         if (r_idx > 0)
3359                         {
3360                                 monster_race *r_ptr = &r_info[r_idx];
3361
3362                                 /* Require empty space (if not ghostly) */
3363                                 if (!monster_can_enter(ny, nx, r_ptr, 0))
3364                                         continue;
3365                         }
3366                         else
3367                         {
3368                                 /* Walls and Monsters block flow */
3369                                 if (!cave_empty_bold2(ny, nx)) continue;
3370
3371                                 /* ... nor on the Pattern */
3372                                 if (pattern_tile(ny, nx)) continue;
3373                         }
3374
3375                         i = distance(y, x, ny, nx);
3376
3377                         if (i > max_dist)
3378                                 continue;
3379
3380                         num[i]++;
3381
3382                         /* random swap */
3383                         if (one_in_(num[i]))
3384                         {
3385                                 place_x[i] = nx;
3386                                 place_y[i] = ny;
3387                         }
3388                 }
3389         }
3390
3391         i = 0;
3392         while (i < MON_SCAT_MAXD && 0 == num[i])
3393                 i++;
3394         if (i >= MON_SCAT_MAXD)
3395                 return FALSE;
3396
3397         *xp = place_x[i];
3398         *yp = place_y[i];
3399
3400         return TRUE;
3401 }
3402
3403 /*!
3404  * @brief モンスターを目標地点に集団生成する / Attempt to place a "group" of monsters around the given location
3405  * @param who 召喚主のモンスター情報ID
3406  * @param y 中心生成位置y座標
3407  * @param x 中心生成位置x座標
3408  * @param r_idx 生成モンスター種族
3409  * @param mode 生成オプション
3410  * @return 成功したらtrue
3411  */
3412 static bool place_monster_group(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
3413 {
3414         monster_race *r_ptr = &r_info[r_idx];
3415
3416         int n, i;
3417         int total = 0, extra = 0;
3418
3419         int hack_n = 0;
3420
3421         POSITION hack_y[GROUP_MAX];
3422         POSITION hack_x[GROUP_MAX];
3423
3424
3425         /* Pick a group size */
3426         total = randint1(10);
3427
3428         /* Hard monsters, small groups */
3429         if (r_ptr->level > dun_level)
3430         {
3431                 extra = r_ptr->level - dun_level;
3432                 extra = 0 - randint1(extra);
3433         }
3434
3435         /* Easy monsters, large groups */
3436         else if (r_ptr->level < dun_level)
3437         {
3438                 extra = dun_level - r_ptr->level;
3439                 extra = randint1(extra);
3440         }
3441
3442         /* Hack -- limit group reduction */
3443         if (extra > 9) extra = 9;
3444
3445         /* Modify the group size */
3446         total += extra;
3447
3448         /* Minimum size */
3449         if (total < 1) total = 1;
3450
3451         /* Maximum size */
3452         if (total > GROUP_MAX) total = GROUP_MAX;
3453
3454
3455         /* Start on the monster */
3456         hack_n = 1;
3457         hack_x[0] = x;
3458         hack_y[0] = y;
3459
3460         /* Puddle monsters, breadth first, up to total */
3461         for (n = 0; (n < hack_n) && (hack_n < total); n++)
3462         {
3463                 /* Grab the location */
3464                 POSITION hx = hack_x[n];
3465                 POSITION hy = hack_y[n];
3466
3467                 /* Check each direction, up to total */
3468                 for (i = 0; (i < 8) && (hack_n < total); i++)
3469                 {
3470                         POSITION mx, my;
3471
3472                         scatter(&my, &mx, hy, hx, 4, 0);
3473
3474                         /* Walls and Monsters block flow */
3475                         if (!cave_empty_bold2(my, mx)) continue;
3476
3477                         /* Attempt to place another monster */
3478                         if (place_monster_one(who, my, mx, r_idx, mode))
3479                         {
3480                                 /* Add it to the "hack" set */
3481                                 hack_y[hack_n] = my;
3482                                 hack_x[hack_n] = mx;
3483                                 hack_n++;
3484                         }
3485                 }
3486         }
3487
3488
3489         /* Success */
3490         return (TRUE);
3491 }
3492
3493 /*!
3494  * @var place_monster_idx
3495  * @brief 護衛対象となるモンスター種族IDを渡すグローバル変数 / Hack -- help pick an escort type
3496  * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_idxを除去し、関数引数化する
3497  */
3498 static MONSTER_IDX place_monster_idx = 0;
3499
3500 /*!
3501  * @var place_monster_m_idx
3502  * @brief 護衛対象となるモンスターIDを渡すグローバル変数 / Hack -- help pick an escort type
3503  * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_m_idxを除去し、関数引数化する
3504  */
3505 static MONSTER_IDX place_monster_m_idx = 0;
3506
3507 /*!
3508  * @brief モンスター種族が召喚主の護衛となれるかどうかをチェックする / Hack -- help pick an escort type
3509  * @param r_idx チェックするモンスター種族のID
3510  * @return 護衛にできるならばtrue
3511  */
3512 static bool place_monster_can_escort(MONRACE_IDX r_idx)
3513 {
3514         monster_race *r_ptr = &r_info[place_monster_idx];
3515         monster_type *m_ptr = &m_list[place_monster_m_idx];
3516
3517         monster_race *z_ptr = &r_info[r_idx];
3518
3519         /* Hack - Escorts have to have the same dungeon flag */
3520         if (mon_hook_dungeon(place_monster_idx) != mon_hook_dungeon(r_idx)) return (FALSE);
3521
3522         /* Require similar "race" */
3523         if (z_ptr->d_char != r_ptr->d_char) return (FALSE);
3524
3525         /* Skip more advanced monsters */
3526         if (z_ptr->level > r_ptr->level) return (FALSE);
3527
3528         /* Skip unique monsters */
3529         if (z_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3530
3531         /* Paranoia -- Skip identical monsters */
3532         if (place_monster_idx == r_idx) return (FALSE);
3533
3534         /* Skip different alignment */
3535         if (monster_has_hostile_align(m_ptr, 0, 0, z_ptr)) return FALSE;
3536
3537         if (r_ptr->flags7 & RF7_FRIENDLY)
3538         {
3539                 if (monster_has_hostile_align(NULL, 1, -1, z_ptr)) return FALSE;
3540         }
3541
3542         if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3543                 return FALSE;
3544
3545         return (TRUE);
3546 }
3547
3548
3549 /*!
3550  * @brief 一般的なモンスター生成処理のサブルーチン / Attempt to place a monster of the given race at the given location
3551  * @param who 召喚主のモンスター情報ID
3552  * @param y 生成地点y座標
3553  * @param x 生成地点x座標
3554  * @param r_idx 生成するモンスターの種族ID
3555  * @param mode 生成オプション
3556  * @return 生成に成功したらtrue
3557  * @details
3558  * Note that certain monsters are now marked as requiring "friends".
3559  * These monsters, if successfully placed, and if the "grp" parameter
3560  * is TRUE, will be surrounded by a "group" of identical monsters.
3561  *
3562  * Note that certain monsters are now marked as requiring an "escort",
3563  * which is a collection of monsters with similar "race" but lower level.
3564  *
3565  * Some monsters induce a fake "group" flag on their escorts.
3566  *
3567  * Note the "bizarre" use of non-recursion to prevent annoying output
3568  * when running a code profiler.
3569  *
3570  * Note the use of the new "monster allocation table" code to restrict
3571  * the "get_mon_num()" function to "legal" escort types.
3572  */
3573 bool place_monster_aux(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
3574 {
3575         int             i, j, n;
3576         monster_race    *r_ptr = &r_info[r_idx];
3577
3578         if (!(mode & PM_NO_KAGE) && one_in_(333))
3579                 mode |= PM_KAGE;
3580
3581         /* Place one monster, or fail */
3582         if (!place_monster_one(who, y, x, r_idx, mode)) return (FALSE);
3583
3584         /* Require the "group" flag */
3585         if (!(mode & PM_ALLOW_GROUP)) return (TRUE);
3586
3587         place_monster_m_idx = hack_m_idx_ii;
3588
3589         /* Reinforcement */
3590         for(i = 0; i < A_MAX; i++)
3591         {
3592                 if(!r_ptr->reinforce_id[i]) break;
3593                 n = damroll(r_ptr->reinforce_dd[i], r_ptr->reinforce_ds[i]);
3594                 for(j = 0; j < n; j++)
3595                 {
3596                         POSITION nx, ny, d = 7;
3597                         scatter(&ny, &nx, y, x, d, 0);
3598                         (void)place_monster_one(place_monster_m_idx, ny, nx, r_ptr->reinforce_id[i], mode);
3599                 }
3600         }
3601
3602         /* Friends for certain monsters */
3603         if (r_ptr->flags1 & (RF1_FRIENDS))
3604         {
3605                 /* Attempt to place a group */
3606                 (void)place_monster_group(who, y, x, r_idx, mode);
3607         }
3608
3609         /* Escorts for certain monsters */
3610         if (r_ptr->flags1 & (RF1_ESCORT))
3611         {
3612                 /* Set the escort index */
3613                 place_monster_idx = r_idx;
3614
3615                 /* Try to place several "escorts" */
3616                 for (i = 0; i < 32; i++)
3617                 {
3618                         POSITION nx, ny, d = 3;
3619                         MONRACE_IDX z; 
3620
3621                         /* Pick a location */
3622                         scatter(&ny, &nx, y, x, d, 0);
3623
3624                         /* Require empty grids */
3625                         if (!cave_empty_bold2(ny, nx)) continue;
3626                         get_mon_num_prep(place_monster_can_escort, get_monster_hook2(ny, nx));
3627
3628                         /* Pick a random race */
3629                         z = get_mon_num(r_ptr->level);
3630
3631                         /* Handle failure */
3632                         if (!z) break;
3633
3634                         /* Place a single escort */
3635                         (void)place_monster_one(place_monster_m_idx, ny, nx, z, mode);
3636
3637                         /* Place a "group" of escorts if needed */
3638                         if ((r_info[z].flags1 & RF1_FRIENDS) ||
3639                             (r_ptr->flags1 & RF1_ESCORTS))
3640                         {
3641                                 /* Place a group of monsters */
3642                                 (void)place_monster_group(place_monster_m_idx, ny, nx, z, mode);
3643                         }
3644                 }
3645         }
3646
3647         /* Success */
3648         return (TRUE);
3649 }
3650
3651 /*!
3652  * @brief 一般的なモンスター生成処理のメインルーチン / Attempt to place a monster of the given race at the given location
3653  * @param y 生成地点y座標
3654  * @param x 生成地点x座標
3655  * @param mode 生成オプション
3656  * @return 生成に成功したらtrue
3657  */
3658 bool place_monster(POSITION y, POSITION x, BIT_FLAGS mode)
3659 {
3660         MONRACE_IDX r_idx;
3661         get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3662
3663         /* Pick a monster */
3664         r_idx = get_mon_num(monster_level);
3665
3666         /* Handle failure */
3667         if (!r_idx) return (FALSE);
3668
3669         /* Attempt to place the monster */
3670         if (place_monster_aux(0, y, x, r_idx, mode)) return (TRUE);
3671
3672         return (FALSE);
3673 }
3674
3675 /*!
3676  * @brief 指定地点に1種類のモンスター種族による群れを生成する
3677  * @param y 生成地点y座標
3678  * @param x 生成地点x座標
3679  * @return 生成に成功したらtrue
3680  */
3681 bool alloc_horde(POSITION y, POSITION x)
3682 {
3683         monster_race *r_ptr = NULL;
3684         MONRACE_IDX r_idx = 0;
3685         MONSTER_IDX m_idx;
3686         int attempts = 1000;
3687         POSITION cy = y;
3688         POSITION cx = x;
3689         get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3690
3691         while (--attempts)
3692         {
3693                 /* Pick a monster */
3694                 r_idx = get_mon_num(monster_level);
3695
3696                 /* Handle failure */
3697                 if (!r_idx) return (FALSE);
3698
3699                 r_ptr = &r_info[r_idx];
3700
3701                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3702
3703                 if (r_idx == MON_HAGURE) continue;
3704                 break;
3705         }
3706         if (attempts < 1) return FALSE;
3707
3708         attempts = 1000;
3709
3710         while (--attempts)
3711         {
3712                 /* Attempt to place the monster */
3713                 if (place_monster_aux(0, y, x, r_idx, 0L)) break;
3714         }
3715
3716         if (attempts < 1) return FALSE;
3717
3718         m_idx = cave[y][x].m_idx;
3719
3720         if (m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[m_list[m_idx].r_idx];
3721
3722         for (attempts = randint1(10) + 5; attempts; attempts--)
3723         {
3724                 scatter(&cy, &cx, y, x, 5, 0);
3725
3726                 (void)summon_specific(m_idx, cy, cx, dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP, r_ptr->d_char);
3727
3728                 y = cy;
3729                 x = cx;
3730         }
3731
3732         if (cheat_hear) msg_format(_("モンスターの大群(%c)", "Monster horde (%c)."), r_ptr->d_char);
3733         return TRUE;
3734 }
3735
3736 /*!
3737  * @brief ダンジョンの主生成を試みる / Put the Guardian
3738  * @param def_val 現在の主の生成状態
3739  * @return 生成に成功したらtrue
3740  */
3741 bool alloc_guardian(bool def_val)
3742 {
3743         MONRACE_IDX guardian = d_info[p_ptr->dungeon_idx].final_guardian;
3744
3745         if (guardian && (d_info[p_ptr->dungeon_idx].maxdepth == dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
3746         {
3747                 int oy;
3748                 int ox;
3749                 int try_count = 4000;
3750
3751                 /* Find a good position */
3752                 while (try_count)
3753                 {
3754                         /* Get a random spot */
3755                         oy = randint1(cur_hgt - 4) + 2;
3756                         ox = randint1(cur_wid - 4) + 2;
3757
3758                         /* Is it a good spot ? */
3759                         if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(cave[oy][ox].feat, &r_info[guardian], 0))
3760                         {
3761                                 /* Place the guardian */
3762                                 if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE;
3763                         }
3764
3765                         /* One less try count */
3766                         try_count--;
3767                 }
3768
3769                 return FALSE;
3770         }
3771
3772         return def_val;
3773 }
3774
3775
3776 /*!
3777  * @brief ダンジョンの初期配置モンスターを生成1回生成する / Attempt to allocate a random monster in the dungeon.
3778  * @param dis プレイヤーから離れるべき最低距離
3779  * @param mode 生成オプション
3780  * @return 生成に成功したらtrue
3781  * @details
3782  * Place the monster at least "dis" distance from the player.
3783  * Use "slp" to choose the initial "sleep" status
3784  * Use "monster_level" for the monster level
3785  */
3786 bool alloc_monster(POSITION dis, BIT_FLAGS mode)
3787 {
3788         int y = 0, x = 0;
3789         int attempts_left = 10000;
3790
3791         /* Put the Guardian */
3792         if (alloc_guardian(FALSE)) return TRUE;
3793
3794         /* Find a legal, distant, unoccupied, space */
3795         while (attempts_left--)
3796         {
3797                 /* Pick a location */
3798                 y = randint0(cur_hgt);
3799                 x = randint0(cur_wid);
3800
3801                 /* Require empty floor grid (was "naked") */
3802                 if (dun_level)
3803                 {
3804                         if (!cave_empty_bold2(y, x)) continue;
3805                 }
3806                 else
3807                 {
3808                         if (!cave_empty_bold(y, x)) continue;
3809                 }
3810
3811                 /* Accept far away grids */
3812                 if (distance(y, x, p_ptr->y, p_ptr->x) > dis) break;
3813         }
3814
3815         if (!attempts_left)
3816         {
3817                 if (cheat_xtra || cheat_hear)
3818                 {
3819                         msg_print(_("警告!新たなモンスターを配置できません。小さい階ですか?", "Warning! Could not allocate a new monster. Small level?"));
3820                 }
3821
3822                 return (FALSE);
3823         }
3824
3825
3826         if (randint1(5000) <= dun_level)
3827         {
3828                 if (alloc_horde(y, x))
3829                 {
3830                         return (TRUE);
3831                 }
3832         }
3833         else
3834         {
3835                 /* Attempt to place the monster, allow groups */
3836                 if (place_monster(y, x, (mode | PM_ALLOW_GROUP))) return (TRUE);
3837         }
3838
3839         return (FALSE);
3840 }
3841
3842
3843 /*!
3844  * @brief モンスターが召喚の基本条件に合っているかをチェックする / Hack -- help decide if a monster race is "okay" to summon
3845  * @param r_idx チェックするモンスター種族ID
3846  * @return 召喚対象にできるならばTRUE
3847  */
3848 static bool summon_specific_okay(MONRACE_IDX r_idx)
3849 {
3850         monster_race *r_ptr = &r_info[r_idx];
3851
3852         /* Hack - Only summon dungeon monsters */
3853         if (!mon_hook_dungeon(r_idx)) return (FALSE);
3854
3855         /* Hack -- identify the summoning monster */
3856         if (summon_specific_who > 0)
3857         {
3858                 monster_type *m_ptr = &m_list[summon_specific_who];
3859
3860                 /* Do not summon enemies */
3861
3862                 /* Friendly vs. opposite aligned normal or pet */
3863                 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
3864         }
3865         /* Use the player's alignment */
3866         else if (summon_specific_who < 0)
3867         {
3868                 /* Do not summon enemies of the pets */
3869                 if (monster_has_hostile_align(NULL, 10, -10, r_ptr))
3870                 {
3871                         if (!one_in_(ABS(p_ptr->align) / 2 + 1)) return FALSE;
3872                 }
3873         }
3874
3875         if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL))) return FALSE;
3876
3877         /* Hack -- no specific type specified */
3878         if (!summon_specific_type) return (TRUE);
3879
3880         if ((summon_specific_who < 0) &&
3881             ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
3882             monster_has_hostile_align(NULL, 10, -10, r_ptr))
3883                 return FALSE;
3884
3885         if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON)) return TRUE;
3886
3887         return (summon_specific_aux(r_idx));
3888 }
3889
3890
3891 /*!
3892  * @brief モンスターを召喚により配置する / Place a monster (of the specified "type") near the given location. Return TRUE if a monster was actually summoned.
3893  * @param who 召喚主のモンスター情報ID
3894  * @param y1 目標地点y座標
3895  * @param x1 目標地点x座標
3896  * @param lev 相当生成階
3897  * @param type 召喚種別
3898  * @param mode 生成オプション 
3899  * @return 召喚できたらtrueを返す
3900  * @details
3901  *
3902  * We will attempt to place the monster up to 10 times before giving up.
3903  *
3904  * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
3905  * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
3906  * Note: None of the other summon codes will ever summon Unique's.
3907  *
3908  * This function has been changed.  We now take the "monster level"
3909  * of the summoning monster as a parameter, and use that, along with
3910  * the current dungeon level, to help determine the level of the
3911  * desired monster.  Note that this is an upper bound, and also
3912  * tends to "prefer" monsters of that level.  Currently, we use
3913  * the average of the dungeon and monster levels, and then add
3914  * five to allow slight increases in monster power.
3915  *
3916  * Note that we use the new "monster allocation table" creation code
3917  * to restrict the "get_mon_num()" function to the set of "legal"
3918  * monsters, making this function much faster and more reliable.
3919  *
3920  * Note that this function may not succeed, though this is very rare.
3921  */
3922 bool summon_specific(MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int type, BIT_FLAGS mode, SYMBOL_CODE symbol)
3923 {
3924         POSITION x, y;
3925         MONRACE_IDX r_idx;
3926
3927         if (p_ptr->inside_arena) return (FALSE);
3928
3929         if (!mon_scatter(0, &y, &x, y1, x1, 2)) return FALSE;
3930
3931         /* Save the summoner */
3932         summon_specific_who = who;
3933
3934         /* Save the "summon" type */
3935         summon_specific_type = type;
3936
3937         summon_kin_type = symbol;
3938
3939         summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
3940         get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
3941
3942         /* Pick a monster, using the level calculation */
3943         r_idx = get_mon_num((dun_level + lev) / 2 + 5);
3944
3945         /* Handle failure */
3946         if (!r_idx)
3947         {
3948                 summon_specific_type = 0;
3949                 return (FALSE);
3950         }
3951
3952         if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
3953
3954         /* Attempt to place the monster (awake, allow groups) */
3955         if (!place_monster_aux(who, y, x, r_idx, mode))
3956         {
3957                 summon_specific_type = 0;
3958                 return (FALSE);
3959         }
3960
3961         summon_specific_type = 0;
3962         /* Success */
3963         sound(SOUND_SUMMON);
3964         return (TRUE);
3965 }
3966
3967
3968 /*!
3969  * @brief 特定モンスター種族を召喚により生成する / A "dangerous" function, creates a pet of the specified type
3970  * @param who 召喚主のモンスター情報ID
3971  * @param oy 目標地点y座標
3972  * @param ox 目標地点x座標
3973  * @param r_idx 生成するモンスター種族ID
3974  * @param mode 生成オプション 
3975  * @return 召喚できたらtrueを返す
3976  */
3977 bool summon_named_creature(MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_IDX r_idx, BIT_FLAGS mode)
3978 {
3979         POSITION x, y;
3980
3981         /* Paranoia */
3982         /* if (!r_idx) return; */
3983
3984         /* Prevent illegal monsters */
3985         if (r_idx >= max_r_idx) return FALSE;
3986
3987         if (p_ptr->inside_arena) return FALSE;
3988
3989         if (!mon_scatter(r_idx, &y, &x, oy, ox, 2)) return FALSE;
3990
3991         /* Place it (allow groups) */
3992         return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
3993 }
3994
3995
3996 /*!
3997  * @brief モンスターを増殖生成する / Let the given monster attempt to reproduce.
3998  * @param m_idx 増殖するモンスター情報ID
3999  * @param clone クローン・モンスター処理ならばtrue
4000  * @param mode 生成オプション 
4001  * @return 生成できたらtrueを返す
4002  * @details
4003  * Note that "reproduction" REQUIRES empty space.
4004  */
4005 bool multiply_monster(MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
4006 {
4007         monster_type    *m_ptr = &m_list[m_idx];
4008
4009         POSITION y, x;
4010
4011         if (!mon_scatter(m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
4012                 return FALSE;
4013
4014         if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
4015
4016         /* Create a new monster (awake, no groups) */
4017         if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
4018                 return FALSE;
4019
4020         /* Hack -- Transfer "clone" flag */
4021         if (clone || (m_ptr->smart & SM_CLONED))
4022         {
4023                 m_list[hack_m_idx_ii].smart |= SM_CLONED;
4024                 m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
4025         }
4026
4027         return TRUE;
4028 }
4029
4030
4031
4032 /*!
4033  * @brief ダメージを受けたモンスターの様子を記述する / Dump a message describing a monster's reaction to damage
4034  * @param m_idx モンスター情報ID
4035  * @param dam 与えたダメージ
4036  * @return なし
4037  * @details
4038  * Technically should attempt to treat "Beholder"'s as jelly's
4039  */
4040 void message_pain(MONSTER_IDX m_idx, HIT_POINT dam)
4041 {
4042         HIT_POINT oldhp, newhp;
4043         HIT_POINT tmp;
4044         PERCENTAGE percentage;
4045
4046         monster_type *m_ptr = &m_list[m_idx];
4047         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4048
4049         GAME_TEXT m_name[MAX_NLEN];
4050
4051         monster_desc(m_name, m_ptr, 0);
4052
4053         if(dam == 0) // Notice non-damage
4054         {
4055                 msg_format(_("%^sはダメージを受けていない。", "%^s is unharmed."), m_name);
4056                 return;
4057         }
4058
4059         /* Note -- subtle fix -CFT */
4060         newhp = m_ptr->hp;
4061         oldhp = newhp + dam;
4062         tmp = (newhp * 100L) / oldhp;
4063         percentage = tmp;
4064
4065         if(my_strchr(",ejmvwQ", r_ptr->d_char)) // Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs
4066         {
4067 #ifdef JP
4068                 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
4069                 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
4070                 else if(percentage > 50) msg_format("%^sは縮こまった。", m_name);
4071                 else if(percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
4072                 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
4073                 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
4074                 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
4075 #else
4076                 if(percentage > 95) msg_format("%^s barely notices.", m_name);
4077                 else if(percentage > 75) msg_format("%^s flinches.", m_name);
4078                 else if(percentage > 50) msg_format("%^s squelches.", m_name);
4079                 else if(percentage > 35) msg_format("%^s quivers in pain.", m_name);
4080                 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
4081                 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
4082                 else msg_format("%^s jerks limply.", m_name);
4083 #endif
4084         }
4085
4086         else if(my_strchr("l", r_ptr->d_char)) // Fish
4087         {
4088 #ifdef JP
4089                 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
4090                 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
4091                 else if(percentage > 50) msg_format("%^sは躊躇した。", m_name);
4092                 else if(percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
4093                 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
4094                 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
4095                 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
4096 #else
4097                 if(percentage > 95) msg_format("%^s barely notices.", m_name);
4098                 else if(percentage > 75) msg_format("%^s flinches.", m_name);
4099                 else if(percentage > 50) msg_format("%^s hesitates.", m_name);
4100                 else if(percentage > 35) msg_format("%^s quivers in pain.", m_name);
4101                 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
4102                 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
4103                 else msg_format("%^s jerks limply.", m_name);
4104 #endif          
4105         }
4106
4107         else if(my_strchr("g#+<>", r_ptr->d_char)) // Golems, Walls, Doors, Stairs
4108         {       
4109 #ifdef JP
4110                 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
4111                 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
4112                 else if(percentage > 50) msg_format("%^sは雷鳴のように吠えた。", m_name);
4113                 else if(percentage > 35) msg_format("%^sは苦しげに吠えた。", m_name);
4114                 else if(percentage > 20) msg_format("%^sはうめいた。", m_name);
4115                 else if(percentage > 10) msg_format("%^sは躊躇した。", m_name);
4116                 else msg_format("%^sはくしゃくしゃになった。", m_name);
4117 #else
4118                 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
4119                 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
4120                 else if(percentage > 50) msg_format("%^s roars thunderously.", m_name);
4121                 else if(percentage > 35) msg_format("%^s rumbles.", m_name);
4122                 else if(percentage > 20) msg_format("%^s grunts.", m_name);
4123                 else if(percentage > 10) msg_format("%^s hesitates.", m_name);
4124                 else msg_format("%^s crumples.", m_name);
4125 #endif
4126         }
4127
4128         else if(my_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char)) // Snakes, Hydrae, Reptiles, Mimics
4129         {
4130 #ifdef JP
4131                 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
4132                 else if(percentage > 75) msg_format("%^sはシーッと鳴いた。", m_name);
4133                 else if(percentage > 50) msg_format("%^sは怒って頭を上げた。", m_name);
4134                 else if(percentage > 35) msg_format("%^sは猛然と威嚇した。", m_name);
4135                 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
4136                 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
4137                 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
4138 #else
4139                 if(percentage > 95) msg_format("%^s barely notices.", m_name);
4140                 else if(percentage > 75) msg_format("%^s hisses.", m_name);
4141                 else if(percentage > 50) msg_format("%^s rears up in anger.", m_name);
4142                 else if(percentage > 35) msg_format("%^s hisses furiously.", m_name);
4143                 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
4144                 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
4145                 else msg_format("%^s jerks limply.", m_name);
4146 #endif
4147         }
4148
4149         else if(my_strchr("f", r_ptr->d_char))
4150         {
4151 #ifdef JP
4152                 if(percentage > 95) msg_format("%sは攻撃に肩をすくめた。", m_name);
4153                 else if(percentage > 75) msg_format("%^sは吠えた。", m_name);
4154                 else if(percentage > 50) msg_format("%^sは怒って吠えた。", m_name);
4155                 else if(percentage > 35) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
4156                 else if(percentage > 20) msg_format("%^sは痛みで弱々しく鳴いた。", m_name);
4157                 else if(percentage > 10) msg_format("%^sは苦痛にうめいた。", m_name);
4158                 else msg_format("%sは哀れな鳴き声を出した。", m_name);
4159 #else
4160                 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
4161                 else if(percentage > 75) msg_format("%^s roars.", m_name);
4162                 else if(percentage > 50) msg_format("%^s growls angrily.", m_name);
4163                 else if(percentage > 35) msg_format("%^s hisses with pain.", m_name);
4164                 else if(percentage > 20) msg_format("%^s mewls in pain.", m_name);
4165                 else if(percentage > 10) msg_format("%^s hisses in agony.", m_name);
4166                 else msg_format("%^s mewls pitifully.", m_name);
4167 #endif
4168         }
4169
4170         else if(my_strchr("acFIKS", r_ptr->d_char)) // Ants, Centipedes, Flies, Insects, Beetles, Spiders
4171         {
4172 #ifdef JP
4173                 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
4174                 else if(percentage > 75) msg_format("%^sはキーキー鳴いた。", m_name);
4175                 else if(percentage > 50) msg_format("%^sはヨロヨロ逃げ回った。", m_name);
4176                 else if(percentage > 35) msg_format("%^sはうるさく鳴いた。", m_name);
4177                 else if(percentage > 20) msg_format("%^sは痛みに痙攣した。", m_name);
4178                 else if(percentage > 10) msg_format("%^sは苦痛で痙攣した。", m_name);
4179                 else msg_format("%^sはピクピクひきつった。", m_name);
4180 #else
4181                 if(percentage > 95)     msg_format("%^s ignores the attack.", m_name);
4182                 else if(percentage > 75) msg_format("%^s chitters.", m_name);
4183                 else if(percentage > 50) msg_format("%^s scuttles about.", m_name);
4184                 else if(percentage > 35) msg_format("%^s twitters.", m_name);
4185                 else if(percentage > 20) msg_format("%^s jerks in pain.", m_name);
4186                 else if(percentage > 10) msg_format("%^s jerks in agony.", m_name);
4187                 else msg_format("%^s twitches.", m_name);
4188 #endif
4189         }
4190
4191         else if(my_strchr("B", r_ptr->d_char)) // Birds
4192         {               
4193 #ifdef JP
4194                 if(percentage > 95) msg_format("%^sはさえずった。", m_name);
4195                 else if(percentage > 75) msg_format("%^sはピーピー鳴いた。", m_name);
4196                 else if(percentage > 50) msg_format("%^sはギャーギャー鳴いた。", m_name);
4197                 else if(percentage > 35) msg_format("%^sはギャーギャー鳴きわめいた。", m_name);
4198                 else if(percentage > 20) msg_format("%^sは苦しんだ。", m_name);
4199                 else if(percentage > 10) msg_format("%^sはのたうち回った。", m_name);
4200                 else msg_format("%^sはキーキーと鳴き叫んだ。", m_name);
4201 #else
4202                 if(percentage > 95)     msg_format("%^s chirps.", m_name);
4203                 else if(percentage > 75) msg_format("%^s twitters.", m_name);
4204                 else if(percentage > 50) msg_format("%^s squawks.", m_name);
4205                 else if(percentage > 35) msg_format("%^s chatters.", m_name);
4206                 else if(percentage > 20) msg_format("%^s jeers.", m_name);
4207                 else if(percentage > 10) msg_format("%^s flutters about.", m_name);
4208                 else msg_format("%^s squeaks.", m_name);
4209 #endif
4210         }
4211
4212         else if(my_strchr("duDLUW", r_ptr->d_char)) // Dragons, Demons, High Undead
4213         {       
4214 #ifdef JP
4215                 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
4216                 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
4217                 else if(percentage > 50) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
4218                 else if(percentage > 35) msg_format("%^sは痛みでうなった。", m_name);
4219                 else if(percentage > 20) msg_format("%^sは痛みに吠えた。", m_name);
4220                 else if(percentage > 10) msg_format("%^sは苦しげに叫んだ。", m_name);
4221                 else msg_format("%^sは弱々しくうなった。", m_name);
4222 #else
4223                 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
4224                 else if(percentage > 75) msg_format("%^s flinches.", m_name);
4225                 else if(percentage > 50) msg_format("%^s hisses in pain.", m_name);
4226                 else if(percentage > 35) msg_format("%^s snarls with pain.", m_name);
4227                 else if(percentage > 20) msg_format("%^s roars with pain.", m_name);
4228                 else if(percentage > 10) msg_format("%^s gasps.", m_name);
4229                 else msg_format("%^s snarls feebly.", m_name);
4230 #endif
4231         }
4232
4233         else if(my_strchr("s", r_ptr->d_char)) // Skeletons
4234         {
4235 #ifdef JP
4236                 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
4237                 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
4238                 else if(percentage > 50) msg_format("%^sはカタカタと笑った。", m_name);
4239                 else if(percentage > 35) msg_format("%^sはよろめいた。", m_name);
4240                 else if(percentage > 20) msg_format("%^sはカタカタ言った。", m_name);
4241                 else if(percentage > 10) msg_format("%^sはよろめいた。", m_name);
4242                 else msg_format("%^sはガタガタ言った。", m_name);
4243 #else
4244                 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
4245                 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
4246                 else if(percentage > 50) msg_format("%^s rattles.", m_name);
4247                 else if(percentage > 35) msg_format("%^s stumbles.", m_name);
4248                 else if(percentage > 20) msg_format("%^s rattles.", m_name);
4249                 else if(percentage > 10) msg_format("%^s staggers.", m_name);
4250                 else msg_format("%^s clatters.", m_name);
4251 #endif
4252         }
4253
4254         else if(my_strchr("z", r_ptr->d_char)) // Zombies
4255         {               
4256 #ifdef JP
4257                 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
4258                 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
4259                 else if(percentage > 50) msg_format("%^sはうめいた。", m_name);
4260                 else if(percentage > 35) msg_format("%sは苦しげにうめいた。", m_name);
4261                 else if(percentage > 20) msg_format("%^sは躊躇した。", m_name);
4262                 else if(percentage > 10) msg_format("%^sはうなった。", m_name);
4263                 else msg_format("%^sはよろめいた。", m_name);
4264 #else
4265                 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
4266                 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
4267                 else if(percentage > 50) msg_format("%^s groans.", m_name);
4268                 else if(percentage > 35) msg_format("%^s moans.", m_name);
4269                 else if(percentage > 20) msg_format("%^s hesitates.", m_name);
4270                 else if(percentage > 10) msg_format("%^s grunts.", m_name);
4271                 else msg_format("%^s staggers.", m_name);
4272 #endif
4273         }
4274
4275         else if(my_strchr("G", r_ptr->d_char)) // Ghosts
4276         {
4277 #ifdef JP
4278                 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
4279                 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
4280                 else if(percentage > 50) msg_format("%sはうめいた。", m_name);
4281                 else if(percentage > 35) msg_format("%^sは泣きわめいた。", m_name);
4282                 else if(percentage > 20) msg_format("%^sは吠えた。", m_name);
4283                 else if(percentage > 10) msg_format("%sは弱々しくうめいた。", m_name);
4284                 else msg_format("%^sはかすかにうめいた。", m_name);
4285 #else
4286                 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
4287                 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
4288                 else if(percentage > 50)  msg_format("%^s moans.", m_name);
4289                 else if(percentage > 35) msg_format("%^s wails.", m_name);
4290                 else if(percentage > 20) msg_format("%^s howls.", m_name);
4291                 else if(percentage > 10) msg_format("%^s moans softly.", m_name);
4292                 else msg_format("%^s sighs.", m_name);
4293 #endif
4294         }
4295
4296         else if(my_strchr("CZ", r_ptr->d_char)) // Dogs and Hounds
4297         {
4298 #ifdef JP
4299                 if(percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
4300                 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
4301                 else if(percentage > 50) msg_format("%^sは痛みでキャンキャン吠えた。", m_name);
4302                 else if(percentage > 35) msg_format("%^sは痛みで鳴きわめいた。", m_name);
4303                 else if(percentage > 20) msg_format("%^sは苦痛のあまり鳴きわめいた。", m_name);
4304                 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
4305                 else msg_format("%^sは弱々しく吠えた。", m_name);
4306 #else
4307                 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
4308                 else if(percentage > 75) msg_format("%^s snarls with pain.", m_name);
4309                 else if(percentage > 50) msg_format("%^s yelps in pain.", m_name);
4310                 else if(percentage > 35) msg_format("%^s howls in pain.", m_name);
4311                 else if(percentage > 20) msg_format("%^s howls in agony.", m_name);
4312                 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
4313                 else msg_format("%^s yelps feebly.", m_name);
4314 #endif
4315         }
4316
4317         else if(my_strchr("Xbilqrt", r_ptr->d_char)) // One type of creatures (ignore,squeal,shriek)
4318         {
4319 #ifdef JP
4320                 if(percentage > 95) msg_format("%^sは攻撃を気にとめていない。", m_name);
4321                 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
4322                 else if(percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
4323                 else if(percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
4324                 else if(percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
4325                 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
4326                 else msg_format("%^sは弱々しく叫んだ。", m_name);
4327 #else
4328                 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
4329                 else if(percentage > 75) msg_format("%^s grunts with pain.", m_name);
4330                 else if(percentage > 50) msg_format("%^s squeals in pain.", m_name);
4331                 else if(percentage > 35) msg_format("%^s shrieks in pain.", m_name);
4332                 else if(percentage > 20) msg_format("%^s shrieks in agony.", m_name);
4333                 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
4334                 else msg_format("%^s cries out feebly.", m_name);
4335 #endif
4336         }
4337
4338         else // Another type of creatures (shrug,cry,scream)
4339         {
4340 #ifdef JP
4341                 if(percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
4342                 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
4343                 else if(percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
4344                 else if(percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
4345                 else if(percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
4346                 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
4347                 else msg_format("%^sは弱々しく叫んだ。", m_name);
4348 #else
4349                 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
4350                 else if(percentage > 75) msg_format("%^s grunts with pain.", m_name);
4351                 else if(percentage > 50) msg_format("%^s cries out in pain.", m_name);
4352                 else if(percentage > 35) msg_format("%^s screams in pain.", m_name);
4353                 else if(percentage > 20) msg_format("%^s screams in agony.", m_name);
4354                 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
4355                 else msg_format("%^s cries out feebly.", m_name);
4356 #endif
4357         }
4358 }
4359
4360
4361
4362 /*!
4363  * @brief SMART(適格に攻撃を行う)モンスターの学習状況を更新する / Learn about an "observed" resistance.
4364  * @param m_idx 更新を行う「モンスター情報ID
4365  * @param what 学習対象ID
4366  * @return なし
4367  */
4368 void update_smart_learn(MONSTER_IDX m_idx, int what)
4369 {
4370         monster_type *m_ptr = &m_list[m_idx];
4371         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4372
4373         /* Not allowed to learn */
4374         if (!smart_learn) return;
4375
4376         /* Too stupid to learn anything */
4377         if (r_ptr->flags2 & (RF2_STUPID)) return;
4378
4379         /* Not intelligent, only learn sometimes */
4380         if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
4381
4382         /* Analyze the knowledge */
4383         switch (what)
4384         {
4385         case DRS_ACID:
4386                 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
4387                 if (IS_OPPOSE_ACID()) m_ptr->smart |= (SM_OPP_ACID);
4388                 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
4389                 break;
4390
4391         case DRS_ELEC:
4392                 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
4393                 if (IS_OPPOSE_ELEC()) m_ptr->smart |= (SM_OPP_ELEC);
4394                 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
4395                 break;
4396
4397         case DRS_FIRE:
4398                 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
4399                 if (IS_OPPOSE_FIRE()) m_ptr->smart |= (SM_OPP_FIRE);
4400                 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
4401                 break;
4402
4403         case DRS_COLD:
4404                 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
4405                 if (IS_OPPOSE_COLD()) m_ptr->smart |= (SM_OPP_COLD);
4406                 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
4407                 break;
4408
4409         case DRS_POIS:
4410                 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
4411                 if (IS_OPPOSE_POIS()) m_ptr->smart |= (SM_OPP_POIS);
4412                 break;
4413
4414
4415         case DRS_NETH:
4416                 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
4417                 break;
4418
4419         case DRS_LITE:
4420                 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
4421                 break;
4422
4423         case DRS_DARK:
4424                 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
4425                 break;
4426
4427         case DRS_FEAR:
4428                 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
4429                 break;
4430
4431         case DRS_CONF:
4432                 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
4433                 break;
4434
4435         case DRS_CHAOS:
4436                 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
4437                 break;
4438
4439         case DRS_DISEN:
4440                 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
4441                 break;
4442
4443         case DRS_BLIND:
4444                 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
4445                 break;
4446
4447         case DRS_NEXUS:
4448                 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
4449                 break;
4450
4451         case DRS_SOUND:
4452                 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
4453                 break;
4454
4455         case DRS_SHARD:
4456                 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
4457                 break;
4458
4459         case DRS_FREE:
4460                 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
4461                 break;
4462
4463         case DRS_MANA:
4464                 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
4465                 break;
4466
4467         case DRS_REFLECT:
4468                 if (p_ptr->reflect) m_ptr-> smart |= (SM_IMM_REFLECT);
4469                 break;
4470         }
4471 }
4472
4473
4474 /*!
4475  * @brief プレイヤーを指定座標に配置する / Place the player in the dungeon XXX XXX
4476  * @param x 配置先X座標
4477  * @param y 配置先Y座標
4478  * @return 配置に成功したらTRUE
4479  */
4480 bool player_place(POSITION y, POSITION x)
4481 {
4482         /* Paranoia XXX XXX */
4483         if (cave[y][x].m_idx != 0) return FALSE;
4484
4485         /* Save player location */
4486         p_ptr->y = y;
4487         p_ptr->x = x;
4488
4489         /* Success */
4490         return TRUE;
4491 }
4492
4493
4494 /*!
4495  * @brief モンスターが盗みや拾いで確保していたアイテムを全てドロップさせる / Drop all items carried by a monster
4496  * @param m_ptr モンスター参照ポインタ
4497  * @return なし
4498  */
4499 void monster_drop_carried_objects(monster_type *m_ptr)
4500 {
4501         OBJECT_IDX this_o_idx, next_o_idx = 0;
4502         object_type forge;
4503         object_type *o_ptr;
4504         object_type *q_ptr;
4505
4506
4507         /* Drop objects being carried */
4508         for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4509         {
4510                 o_ptr = &o_list[this_o_idx];
4511
4512                 /* Acquire next object */
4513                 next_o_idx = o_ptr->next_o_idx;
4514                 q_ptr = &forge;
4515
4516                 /* Copy the object */
4517                 object_copy(q_ptr, o_ptr);
4518
4519                 /* Forget monster */
4520                 q_ptr->held_m_idx = 0;
4521
4522                 delete_object_idx(this_o_idx);
4523
4524                 /* Drop it */
4525                 (void)drop_near(q_ptr, -1, m_ptr->fy, m_ptr->fx);
4526         }
4527
4528         /* Forget objects */
4529         m_ptr->hold_o_idx = 0;
4530 }