OSDN Git Service

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