OSDN Git Service

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