OSDN Git Service

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