OSDN Git Service

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