OSDN Git Service

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