OSDN Git Service

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