OSDN Git Service

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