OSDN Git Service

保存階にいるアイテムを拾ったユニークモンスターが別の階に現れてから保
[hengbandforosx/hengbandosx.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 bool is_kage = FALSE;
19
20 cptr horror_desc[MAX_SAN_HORROR] =
21 {
22 #ifdef JP
23         "´÷¤Þ¤ï¤·¤¤",
24         "ÄìÃΤì¤Ì",
25         "¤¾¤Ã¤È¤¹¤ë",
26         "ÇËÌÇŪ¤Ê",
27         "ËÁÆÂŪ¤Ê",
28
29         "¤¤¤ä¤Ê",
30         "¶²¤í¤·¤¤",
31         "ÉÔ·é¤Ê",
32         "ÍƼϤΤʤ¤",
33         "¤ª¤¾¤Þ¤·¤¤",
34
35         "ÃϹö¤Î",
36         "¿È¤ÎÌÓ¤â¤è¤À¤Ä",
37         "ÃϹö¤Î",
38         "´÷¤Þ¤ï¤·¤¤",
39         "°­Ì´¤Î¤è¤¦¤Ê",
40
41         "·ù°­¤ò´¶¤¸¤ë",
42         "ȳÅö¤¿¤ê¤Ê",
43         "¶²¤¤",
44         "ÉÔ¾ô¤Ê",
45         "¸À¤¦¤â¤ª¤¾¤Þ¤·¤¤",
46 #else
47         "abominable",
48         "abysmal",
49         "appalling",
50         "baleful",
51         "blasphemous",
52
53         "disgusting",
54         "dreadful",
55         "filthy",
56         "grisly",
57         "hideous",
58
59         "hellish",
60         "horrible",
61         "infernal",
62         "loathsome",
63         "nightmarish",
64
65         "repulsive",
66         "sacrilegious",
67         "terrible",
68         "unclean",
69         "unspeakable",
70 #endif
71
72 };
73
74 cptr funny_desc[MAX_SAN_FUNNY] =
75 {
76 #ifdef JP
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         "ÌîÀ­Åª¤Ê",
102         "Èó¾ï¼±¤Ê",
103 #else
104         "silly",
105         "hilarious",
106         "absurd",
107         "insipid",
108         "ridiculous",
109
110         "laughable",
111         "ludicrous",
112         "far-out",
113         "groovy",
114         "postmodern",
115
116         "fantastic",
117         "dadaistic",
118         "cubistic",
119         "cosmic",
120         "awesome",
121
122         "incomprehensible",
123         "fabulous",
124         "amazing",
125         "incredible",
126         "chaotic",
127
128         "wild",
129         "preposterous",
130 #endif
131
132 };
133
134 cptr funny_comments[MAX_SAN_COMMENT] =
135 {
136 #ifdef JP
137   /* nuke me */
138         "ºÇ¹â¤À¤¼¡ª",
139         "¤¦¤Ò¤ç¡¼¡ª",
140         "¤¤¤«¤¹¤¼¡ª",
141         "¤¹¤ó¤Ð¤é¤·¤¤¡ª",
142         "¤Ö¤Ã¤È¤Ó¡¼¡ª"
143 #else
144         "Wow, cosmic, man!",
145         "Rad!",
146         "Groovy!",
147         "Cool!",
148         "Far out!"
149 #endif
150
151 };
152
153
154 /*
155  * Set the target of counter attack
156  */
157 void set_target(monster_type *m_ptr, int y, int x)
158 {
159         m_ptr->target_y = y;
160         m_ptr->target_x = x;
161 }
162
163
164 /*
165  * Reset the target of counter attack
166  */
167 void reset_target(monster_type *m_ptr)
168 {
169         set_target(m_ptr, 0, 0);
170 }
171
172
173 /*
174  *  Extract monster race pointer of a monster's true form
175  */
176 monster_race *real_r_ptr(monster_type *m_ptr)
177 {
178         monster_race *r_ptr = &r_info[m_ptr->r_idx];
179
180         /* Extract real race */
181         if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
182         {
183                 if (r_ptr->flags1 & RF1_UNIQUE)
184                         return &r_info[MON_CHAMELEON_K];
185                 else
186                         return &r_info[MON_CHAMELEON];
187         }
188         else
189         {
190                 return r_ptr;
191         }
192 }
193
194
195 /*
196  * Delete a monster by index.
197  *
198  * When a monster is deleted, all of its objects are deleted.
199  */
200 void delete_monster_idx(int i)
201 {
202         int x, y;
203
204         monster_type *m_ptr = &m_list[i];
205
206         monster_race *r_ptr = &r_info[m_ptr->r_idx];
207
208         s16b this_o_idx, next_o_idx = 0;
209
210
211         /* Get location */
212         y = m_ptr->fy;
213         x = m_ptr->fx;
214
215
216         /* Hack -- Reduce the racial counter */
217         real_r_ptr(m_ptr)->cur_num--;
218
219         /* Hack -- count the number of "reproducers" */
220         if (r_ptr->flags2 & (RF2_MULTIPLY)) num_repro--;
221
222
223         /* Hack -- remove target monster */
224         if (i == target_who) target_who = 0;
225
226         /* Hack -- remove tracked monster */
227         if (i == p_ptr->health_who) health_track(0);
228
229         if (pet_t_m_idx == i ) pet_t_m_idx = 0;
230         if (riding_t_m_idx == i) riding_t_m_idx = 0;
231         if (p_ptr->riding == i) p_ptr->riding = 0;
232
233         /* Monster is gone */
234         cave[y][x].m_idx = 0;
235
236
237         /* Delete objects */
238         for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
239         {
240                 object_type *o_ptr;
241
242                 /* Acquire object */
243                 o_ptr = &o_list[this_o_idx];
244
245                 /* Acquire next object */
246                 next_o_idx = o_ptr->next_o_idx;
247
248                 /*
249                  * o_ptr->held_m_idx is needed in delete_object_idx()
250                  * to prevent calling lite_spot()
251                  */
252
253                 /* Delete the object */
254                 delete_object_idx(this_o_idx);
255         }
256
257
258         /* Wipe the Monster */
259         (void)WIPE(m_ptr, monster_type);
260
261         /* Count monsters */
262         m_cnt--;
263
264         /* Visual update */
265         lite_spot(y, x);
266
267         /* Update some things */
268         p_ptr->update |= (PU_MON_LITE);
269 }
270
271
272 /*
273  * Delete the monster, if any, at a given location
274  */
275 void delete_monster(int y, int x)
276 {
277         cave_type *c_ptr;
278
279         /* Paranoia */
280         if (!in_bounds(y, x)) return;
281
282         /* Check the grid */
283         c_ptr = &cave[y][x];
284
285         /* Delete the monster (if any) */
286         if (c_ptr->m_idx) delete_monster_idx(c_ptr->m_idx);
287 }
288
289
290 /*
291  * Move an object from index i1 to index i2 in the object list
292  */
293 static void compact_monsters_aux(int i1, int i2)
294 {
295         int y, x;
296
297         cave_type *c_ptr;
298
299         monster_type *m_ptr;
300
301         s16b this_o_idx, next_o_idx = 0;
302
303
304         /* Do nothing */
305         if (i1 == i2) return;
306
307
308         /* Old monster */
309         m_ptr = &m_list[i1];
310
311         /* Location */
312         y = m_ptr->fy;
313         x = m_ptr->fx;
314
315         /* Cave grid */
316         c_ptr = &cave[y][x];
317
318         /* Update the cave */
319         c_ptr->m_idx = i2;
320
321         /* Repair objects being carried by monster */
322         for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
323         {
324                 object_type *o_ptr;
325
326                 /* Acquire object */
327                 o_ptr = &o_list[this_o_idx];
328
329                 /* Acquire next object */
330                 next_o_idx = o_ptr->next_o_idx;
331
332                 /* Reset monster pointer */
333                 o_ptr->held_m_idx = i2;
334         }
335
336         /* Hack -- Update the target */
337         if (target_who == i1) target_who = i2;
338
339         /* Hack -- Update the target */
340         if (pet_t_m_idx == i1) pet_t_m_idx = i2;
341         if (riding_t_m_idx == i1) riding_t_m_idx = i2;
342
343         /* Hack -- Update the riding */
344         if (p_ptr->riding == i1) p_ptr->riding = i2;
345
346         /* Hack -- Update the health bar */
347         if (p_ptr->health_who == i1) health_track(i2);
348
349         /* Structure copy */
350         COPY(&m_list[i2], &m_list[i1], monster_type);
351
352         /* Wipe the hole */
353         (void)WIPE(&m_list[i1], monster_type);
354
355 }
356
357
358 /*
359  * Compact and Reorder the monster list
360  *
361  * This function can be very dangerous, use with caution!
362  *
363  * When actually "compacting" monsters, we base the saving throw
364  * on a combination of monster level, distance from player, and
365  * current "desperation".
366  *
367  * After "compacting" (if needed), we "reorder" the monsters into a more
368  * compact order, and we reset the allocation info, and the "live" array.
369  */
370 void compact_monsters(int size)
371 {
372         int             i, num, cnt;
373         int             cur_lev, cur_dis, chance;
374
375         /* Message (only if compacting) */
376 #ifdef JP
377         if (size) msg_print("¥â¥ó¥¹¥¿¡¼¾ðÊó¤ò°µ½Ì¤·¤Æ¤¤¤Þ¤¹...");
378 #else
379         if (size) msg_print("Compacting monsters...");
380 #endif
381
382
383         /* Compact at least 'size' objects */
384         for (num = 0, cnt = 1; num < size; cnt++)
385         {
386                 /* Get more vicious each iteration */
387                 cur_lev = 5 * cnt;
388
389                 /* Get closer each iteration */
390                 cur_dis = 5 * (20 - cnt);
391
392                 /* Check all the monsters */
393                 for (i = 1; i < m_max; i++)
394                 {
395                         monster_type *m_ptr = &m_list[i];
396
397                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
398
399                         /* Paranoia -- skip "dead" monsters */
400                         if (!m_ptr->r_idx) continue;
401
402                         /* Hack -- High level monsters start out "immune" */
403                         if (r_ptr->level > cur_lev) continue;
404
405                         if (i == p_ptr->riding) continue;
406
407                         /* Ignore nearby monsters */
408                         if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
409
410                         /* Saving throw chance */
411                         chance = 90;
412
413                         /* Only compact "Quest" Monsters in emergencies */
414                         if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
415
416                         /* Try not to compact Unique Monsters */
417                         if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
418
419                         /* All monsters get a saving throw */
420                         if (randint0(100) < chance) continue;
421
422                         /* Delete the monster */
423                         delete_monster_idx(i);
424
425                         /* Count the monster */
426                         num++;
427                 }
428         }
429
430
431         /* Excise dead monsters (backwards!) */
432         for (i = m_max - 1; i >= 1; i--)
433         {
434                 /* Get the i'th monster */
435                 monster_type *m_ptr = &m_list[i];
436
437                 /* Skip real monsters */
438                 if (m_ptr->r_idx) continue;
439
440                 /* Move last monster into open hole */
441                 compact_monsters_aux(m_max - 1, i);
442
443                 /* Compress "m_max" */
444                 m_max--;
445         }
446 }
447
448
449 /*
450  * Pre-calculate the racial counters of preserved pets
451  * To prevent multiple generation of unique monster who is the minion of player
452  */
453 void precalc_cur_num_of_pet(void)
454 {
455         monster_type *m_ptr;
456         int i;
457         int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
458
459         for (i = 0; i < max_num; i++)
460         {
461                 m_ptr = &party_mon[i];
462
463                 /* Skip empty monsters */
464                 if (!m_ptr->r_idx) continue;
465
466                 /* Hack -- Increase the racial counter */
467                 real_r_ptr(m_ptr)->cur_num++;
468         }
469 }
470
471
472 /*
473  * Delete/Remove all the monsters when the player leaves the level
474  *
475  * This is an efficient method of simulating multiple calls to the
476  * "delete_monster()" function, with no visual effects.
477  */
478 void wipe_m_list(void)
479 {
480         int i;
481
482         /* Hack -- if Banor or Lupart dies, stay another dead */
483         if (!r_info[MON_BANORLUPART].max_num)
484         {
485                 if (r_info[MON_BANOR].max_num)
486                 {
487                         r_info[MON_BANOR].max_num = 0;
488                         r_info[MON_BANOR].r_pkills++;
489                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
490                 }
491                 if (r_info[MON_LUPART].max_num)
492                 {
493                         r_info[MON_LUPART].max_num = 0;
494                         r_info[MON_LUPART].r_pkills++;
495                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
496                 }
497         }
498
499         /* Delete all the monsters */
500         for (i = m_max - 1; i >= 1; i--)
501         {
502                 monster_type *m_ptr = &m_list[i];
503
504                 /* Skip dead monsters */
505                 if (!m_ptr->r_idx) continue;
506
507                 /* Monster is gone */
508                 cave[m_ptr->fy][m_ptr->fx].m_idx = 0;
509
510                 /* Wipe the Monster */
511                 (void)WIPE(m_ptr, monster_type);
512
513         }
514
515         /*
516          * Wiping racial counters of all monsters and incrementing of racial
517          * counters of monsters in party_mon[] is required to prevent multiple
518          * generation of unique monster who is the minion of player.
519          */
520
521         /* Hack -- Wipe the racial counter of all monster races */
522         for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
523
524         /* Hack -- Increase the racial counters of pets */
525         precalc_cur_num_of_pet();
526
527         /* Reset "m_max" */
528         m_max = 1;
529
530         /* Reset "m_cnt" */
531         m_cnt = 0;
532
533         /* Hack -- reset "reproducer" count */
534         num_repro = 0;
535
536         /* Hack -- no more target */
537         target_who = 0;
538         pet_t_m_idx = 0;
539         riding_t_m_idx = 0;
540
541         /* Hack -- no more tracking */
542         health_track(0);
543 }
544
545
546 /*
547  * Acquires and returns the index of a "free" monster.
548  *
549  * This routine should almost never fail, but it *can* happen.
550  */
551 s16b m_pop(void)
552 {
553         int i;
554
555
556         /* Normal allocation */
557         if (m_max < max_m_idx)
558         {
559                 /* Access the next hole */
560                 i = m_max;
561
562                 /* Expand the array */
563                 m_max++;
564
565                 /* Count monsters */
566                 m_cnt++;
567
568                 /* Return the index */
569                 return (i);
570         }
571
572
573         /* Recycle dead monsters */
574         for (i = 1; i < m_max; i++)
575         {
576                 monster_type *m_ptr;
577
578                 /* Acquire monster */
579                 m_ptr = &m_list[i];
580
581                 /* Skip live monsters */
582                 if (m_ptr->r_idx) continue;
583
584                 /* Count monsters */
585                 m_cnt++;
586
587                 /* Use this monster */
588                 return (i);
589         }
590
591
592         /* Warn the player (except during dungeon creation) */
593 #ifdef JP
594         if (character_dungeon) msg_print("¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë¡ª");
595 #else
596         if (character_dungeon) msg_print("Too many monsters!");
597 #endif
598
599
600         /* Try not to crash */
601         return (0);
602 }
603
604
605
606
607 /*
608  * Hack -- the "type" of the current "summon specific"
609  */
610 static int summon_specific_type = 0;
611
612
613 /*
614  * Hack -- the index of the summoning monster
615  */
616 static int summon_specific_who = -1;
617
618
619 /*
620  * Hack -- the hostility of the summoned monster
621  */
622 static bool summon_specific_hostile = TRUE;
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                                (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
1248         int                     r_idx;
1249
1250         long            value, total;
1251
1252         monster_race    *r_ptr;
1253
1254         alloc_entry             *table = alloc_race_table;
1255
1256         int pls_kakuritu, pls_level;
1257         int hoge=mysqrt(level*10000L);
1258
1259         if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
1260
1261         if ((dungeon_turn > hoge*(TURNS_PER_TICK*500L)) && !level)
1262         {
1263                 pls_kakuritu = MAX(2, NASTY_MON-((dungeon_turn/(TURNS_PER_TICK*2500L)-hoge/10)));
1264                 pls_level = MIN(8,3 + dungeon_turn/(TURNS_PER_TICK*20000L)-hoge/40);
1265         }
1266         else
1267         {
1268                 pls_kakuritu = NASTY_MON;
1269                 pls_level = 2;
1270         }
1271
1272         if (d_info[dungeon_type].flags1 & DF1_MAZE)
1273         {
1274                 pls_kakuritu = MIN(pls_kakuritu/2, pls_kakuritu-10);
1275                 if (pls_kakuritu < 2) pls_kakuritu = 2;
1276                 pls_level += 2;
1277                 level += 3;
1278         }
1279
1280         /* Boost the level */
1281         if ((level > 0) && !p_ptr->inside_battle && !(d_info[dungeon_type].flags1 & DF1_BEGINNER))
1282         {
1283                 /* Nightmare mode allows more out-of depth monsters */
1284                 if (ironman_nightmare && !randint0(pls_kakuritu))
1285                 {
1286                         /* What a bizarre calculation */
1287                         level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
1288                 }
1289                 else
1290                 {
1291                         /* Occasional "nasty" monster */
1292                         if (!randint0(pls_kakuritu))
1293                         {
1294                                 /* Pick a level bonus */
1295                                 int d = MIN(5, level/10) + pls_level;
1296
1297                                 /* Boost the level */
1298                                 level += d;
1299                         }
1300
1301                         /* Occasional "nasty" monster */
1302                         if (!randint0(pls_kakuritu))
1303                         {
1304                                 /* Pick a level bonus */
1305                                 int d = MIN(5, level/10) + pls_level;
1306
1307                                 /* Boost the level */
1308                                 level += d;
1309                         }
1310                 }
1311         }
1312
1313
1314         /* Reset total */
1315         total = 0L;
1316
1317         /* Process probabilities */
1318         for (i = 0; i < alloc_race_size; i++)
1319         {
1320                 /* Monsters are sorted by depth */
1321                 if (table[i].level > level) break;
1322
1323                 /* Default */
1324                 table[i].prob3 = 0;
1325
1326                 /* Access the "r_idx" of the chosen monster */
1327                 r_idx = table[i].index;
1328
1329                 /* Access the actual race */
1330                 r_ptr = &r_info[r_idx];
1331
1332                 if (!p_ptr->inside_battle && !chameleon_change_m_idx)
1333                 {
1334                         /* Hack -- "unique" monsters must be "unique" */
1335                         if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
1336                              (r_ptr->flags7 & (RF7_UNIQUE_7))) &&
1337                             (r_ptr->cur_num >= r_ptr->max_num))
1338                         {
1339                                 continue;
1340                         }
1341
1342                         if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
1343                             (r_ptr->cur_num >= 1))
1344                         {
1345                                 continue;
1346                         }
1347
1348                         if (r_idx == MON_BANORLUPART)
1349                         {
1350                                 if (r_info[MON_BANOR].cur_num > 0) continue;
1351                                 if (r_info[MON_LUPART].cur_num > 0) continue;
1352                         }
1353                 }
1354
1355                 /* Accept */
1356                 table[i].prob3 = table[i].prob2;
1357
1358                 /* Total */
1359                 total += table[i].prob3;
1360         }
1361
1362         /* No legal monsters */
1363         if (total <= 0) return (0);
1364
1365
1366         /* Pick a monster */
1367         value = randint0(total);
1368
1369         /* Find the monster */
1370         for (i = 0; i < alloc_race_size; i++)
1371         {
1372                 /* Found the entry */
1373                 if (value < table[i].prob3) break;
1374
1375                 /* Decrement */
1376                 value = value - table[i].prob3;
1377         }
1378
1379
1380         /* Power boost */
1381         p = randint0(100);
1382
1383         /* Try for a "harder" monster once (50%) or twice (10%) */
1384         if (p < 60)
1385         {
1386                 /* Save old */
1387                 j = i;
1388
1389                 /* Pick a monster */
1390                 value = randint0(total);
1391
1392                 /* Find the monster */
1393                 for (i = 0; i < alloc_race_size; i++)
1394                 {
1395                         /* Found the entry */
1396                         if (value < table[i].prob3) break;
1397
1398                         /* Decrement */
1399                         value = value - table[i].prob3;
1400                 }
1401
1402                 /* Keep the "best" one */
1403                 if (table[i].level < table[j].level) i = j;
1404         }
1405
1406         /* Try for a "harder" monster twice (10%) */
1407         if (p < 10)
1408         {
1409                 /* Save old */
1410                 j = i;
1411
1412                 /* Pick a monster */
1413                 value = randint0(total);
1414
1415                 /* Find the monster */
1416                 for (i = 0; i < alloc_race_size; i++)
1417                 {
1418                         /* Found the entry */
1419                         if (value < table[i].prob3) break;
1420
1421                         /* Decrement */
1422                         value = value - table[i].prob3;
1423                 }
1424
1425                 /* Keep the "best" one */
1426                 if (table[i].level < table[j].level) i = j;
1427         }
1428
1429         /* Result */
1430         return (table[i].index);
1431 }
1432
1433
1434
1435
1436
1437 /*
1438  * Build a string describing a monster in some way.
1439  *
1440  * We can correctly describe monsters based on their visibility.
1441  * We can force all monsters to be treated as visible or invisible.
1442  * We can build nominatives, objectives, possessives, or reflexives.
1443  * We can selectively pronominalize hidden, visible, or all monsters.
1444  * We can use definite or indefinite descriptions for hidden monsters.
1445  * We can use definite or indefinite descriptions for visible monsters.
1446  *
1447  * Pronominalization involves the gender whenever possible and allowed,
1448  * so that by cleverly requesting pronominalization / visibility, you
1449  * can get messages like "You hit someone.  She screams in agony!".
1450  *
1451  * Reflexives are acquired by requesting Objective plus Possessive.
1452  *
1453  * If no m_ptr arg is given (?), the monster is assumed to be hidden,
1454  * unless the "Assume Visible" mode is requested.
1455  *
1456  * If no r_ptr arg is given, it is extracted from m_ptr and r_info
1457  * If neither m_ptr nor r_ptr is given, the monster is assumed to
1458  * be neuter, singular, and hidden (unless "Assume Visible" is set),
1459  * in which case you may be in trouble... :-)
1460  *
1461  * I am assuming that no monster name is more than 70 characters long,
1462  * so that "char desc[80];" is sufficiently large for any result.
1463  *
1464  * Mode Flags:
1465  *  MD_OBJECTIVE      --> Objective (or Reflexive)
1466  *  MD_POSSESSIVE     --> Possessive (or Reflexive)
1467  *  MD_INDEF_HIDDEN   --> Use indefinites for hidden monsters ("something")
1468  *  MD_INDEF_VISIBLE  --> Use indefinites for visible monsters ("a kobold")
1469  *  MD_PRON_HIDDEN    --> Pronominalize hidden monsters
1470  *  MD_PRON_VISIBLE   --> Pronominalize visible monsters
1471  *  MD_ASSUME_HIDDEN  --> Assume the monster is hidden
1472  *  MD_ASSUME_VISIBLE --> Assume the monster is visible
1473  *  MD_TRUE_NAME      --> Chameleon's true name
1474  *  MD_IGNORE_HALLU   --> Ignore hallucination, and penetrate shape change
1475  *  MD_ASSUME_OUTSIDE --> Assume this monster pet waiting outside the floor
1476  *
1477  * Useful Modes:
1478  *  0x00 --> Full nominative name ("the kobold") or "it"
1479  *  MD_INDEF_HIDDEN --> Full nominative name ("the kobold") or "something"
1480  *  MD_ASSUME_VISIBLE --> Genocide resistance name ("the kobold")
1481  *  MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE --> Killing name ("a kobold")
1482  *  MD_PRON_VISIBLE | MD_POSSESSIVE
1483  *    --> Possessive, genderized if visable ("his") or "its"
1484  *  MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE
1485  *    --> Reflexive, genderized if visable ("himself") or "itself"
1486  */
1487 void monster_desc(char *desc, monster_type *m_ptr, int mode)
1488 {
1489         cptr            res;
1490         monster_race    *r_ptr;
1491
1492         cptr            name;
1493         char            buf[128];
1494         char            silly_name[1024];
1495         bool            seen, pron;
1496         bool            named = FALSE;
1497
1498         r_ptr = &r_info[m_ptr->ap_r_idx];
1499
1500         /* Mode of MD_TRUE_NAME will reveal Chameleon's true name */
1501         if (mode & MD_TRUE_NAME) name = (r_name + real_r_ptr(m_ptr)->name);
1502         else name = (r_name + r_ptr->name);
1503
1504         /* Are we hallucinating? (Idea from Nethack...) */
1505         if (p_ptr->image && !(mode & MD_IGNORE_HALLU))
1506         {
1507                 if (one_in_(2))
1508                 {
1509 #ifdef JP
1510                         if (!get_rnd_line("silly_j.txt", m_ptr->r_idx, silly_name))
1511 #else
1512                         if (!get_rnd_line("silly.txt", m_ptr->r_idx, silly_name))
1513 #endif
1514
1515                                 named = TRUE;
1516                 }
1517
1518                 if (!named)
1519                 {
1520                         monster_race *hallu_race;
1521
1522                         do
1523                         {
1524                                 hallu_race = &r_info[randint1(max_r_idx - 1)];
1525                         }
1526                         while (hallu_race->flags1 & RF1_UNIQUE);
1527
1528                         strcpy(silly_name, (r_name + hallu_race->name));
1529                 }
1530
1531                 /* Better not strcpy it, or we could corrupt r_info... */
1532                 name = silly_name;
1533         }
1534
1535         /* Can we "see" it (exists + forced, or visible + not unforced) */
1536         seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml)));
1537
1538         /* Sexed Pronouns (seen and allowed, or unseen and allowed) */
1539         pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN))));
1540
1541
1542         /* First, try using pronouns, or describing hidden monsters */
1543         if (!seen || pron)
1544         {
1545                 /* an encoding of the monster "sex" */
1546                 int kind = 0x00;
1547
1548                 /* Extract the gender (if applicable) */
1549                 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1550                 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1551
1552                 /* Ignore the gender (if desired) */
1553                 if (!m_ptr || !pron) kind = 0x00;
1554
1555
1556                 /* Assume simple result */
1557 #ifdef JP
1558                 res = "²¿¤«";
1559 #else
1560                 res = "it";
1561 #endif
1562
1563
1564                 /* Brute force: split on the possibilities */
1565                 switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE)))
1566                 {
1567                         /* Neuter, or unknown */
1568 #ifdef JP
1569                         case 0x00:                                                    res = "²¿¤«"; break;
1570                         case 0x00 + (MD_OBJECTIVE):                                   res = "²¿¤«"; break;
1571                         case 0x00 + (MD_POSSESSIVE):                                  res = "²¿¤«¤Î"; break;
1572                         case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "²¿¤«¼«¿È"; break;
1573                         case 0x00 + (MD_INDEF_HIDDEN):                                res = "²¿¤«"; break;
1574                         case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "²¿¤«"; break;
1575                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "²¿¤«"; break;
1576                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "¤½¤ì¼«¿È"; break;
1577 #else
1578                         case 0x00:                                                    res = "it"; break;
1579                         case 0x00 + (MD_OBJECTIVE):                                   res = "it"; break;
1580                         case 0x00 + (MD_POSSESSIVE):                                  res = "its"; break;
1581                         case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "itself"; break;
1582                         case 0x00 + (MD_INDEF_HIDDEN):                                res = "something"; break;
1583                         case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "something"; break;
1584                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "something's"; break;
1585                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1586 #endif
1587
1588
1589                         /* Male (assume human if vague) */
1590 #ifdef JP
1591                         case 0x10:                                                    res = "Èà"; break;
1592                         case 0x10 + (MD_OBJECTIVE):                                   res = "Èà"; break;
1593                         case 0x10 + (MD_POSSESSIVE):                                  res = "Èà¤Î"; break;
1594                         case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "È༫¿È"; break;
1595                         case 0x10 + (MD_INDEF_HIDDEN):                                res = "狼"; break;
1596                         case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "狼"; break;
1597                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "狼¤Î"; break;
1598                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "È༫¿È"; break;
1599 #else
1600                         case 0x10:                                                    res = "he"; break;
1601                         case 0x10 + (MD_OBJECTIVE):                                   res = "him"; break;
1602                         case 0x10 + (MD_POSSESSIVE):                                  res = "his"; break;
1603                         case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "himself"; break;
1604                         case 0x10 + (MD_INDEF_HIDDEN):                                res = "someone"; break;
1605                         case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "someone"; break;
1606                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "someone's"; break;
1607                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1608 #endif
1609
1610
1611                         /* Female (assume human if vague) */
1612 #ifdef JP
1613                         case 0x20:                                                    res = "Èà½÷"; break;
1614                         case 0x20 + (MD_OBJECTIVE):                                   res = "Èà½÷"; break;
1615                         case 0x20 + (MD_POSSESSIVE):                                  res = "Èà½÷¤Î"; break;
1616                         case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "Èà½÷¼«¿È"; break;
1617                         case 0x20 + (MD_INDEF_HIDDEN):                                res = "狼"; break;
1618                         case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "狼"; break;
1619                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "狼¤Î"; break;
1620                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "Èà½÷¼«¿È"; break;
1621 #else
1622                         case 0x20:                                                    res = "she"; break;
1623                         case 0x20 + (MD_OBJECTIVE):                                   res = "her"; break;
1624                         case 0x20 + (MD_POSSESSIVE):                                  res = "her"; break;
1625                         case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "herself"; break;
1626                         case 0x20 + (MD_INDEF_HIDDEN):                                res = "someone"; break;
1627                         case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "someone"; break;
1628                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "someone's"; break;
1629                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1630 #endif
1631                 }
1632
1633                 /* Copy the result */
1634                 (void)strcpy(desc, res);
1635         }
1636
1637
1638         /* Handle visible monsters, "reflexive" request */
1639         else if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE))
1640         {
1641                 /* The monster is visible, so use its gender */
1642 #ifdef JP
1643                 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, "Èà½÷¼«¿È");
1644                 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, "È༫¿È");
1645                 else strcpy(desc, "¤½¤ì¼«¿È");
1646 #else
1647                 if (r_ptr->flags1 & RF1_FEMALE) strcpy(desc, "herself");
1648                 else if (r_ptr->flags1 & RF1_MALE) strcpy(desc, "himself");
1649                 else strcpy(desc, "itself");
1650 #endif
1651         }
1652
1653
1654         /* Handle all other visible monster requests */
1655         else
1656         {
1657                 /* Tanuki? */
1658                 if (is_pet(m_ptr) && m_ptr->ap_r_idx != m_ptr->r_idx)
1659                 {
1660 #ifdef JP
1661                         char *t;
1662                         strcpy(buf, name);
1663                         t = buf;
1664                         while(strncmp(t, "¡Ù", 2) && *t) t++;
1665                         if (*t)
1666                         {
1667                                 *t = '\0';
1668                                 (void)sprintf(desc, "%s¡©¡Ù", buf);
1669                         }
1670                         else
1671                                 (void)sprintf(desc, "%s¡©", name);
1672 #else
1673                         (void)sprintf(desc, "%s?", name);
1674 #endif
1675                 }
1676                 else
1677
1678                 /* It could be a Unique */
1679                 if ((r_ptr->flags1 & RF1_UNIQUE) && !(p_ptr->image && !(mode & MD_IGNORE_HALLU)))
1680                 {
1681                         /* Start with the name (thus nominative and objective) */
1682                         if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME))
1683                         {
1684 #ifdef JP
1685                                 char *t;
1686                                 strcpy(buf, name);
1687                                 t = buf;
1688                                 while (strncmp(t, "¡Ù", 2) && *t) t++;
1689                                 if (*t)
1690                                 {
1691                                         *t = '\0';
1692                                         (void)sprintf(desc, "%s¡©¡Ù", buf);
1693                                 }
1694                                 else
1695                                         (void)sprintf(desc, "%s¡©", name);
1696 #else
1697                                 (void)sprintf(desc, "%s?", name);
1698 #endif
1699                         }
1700                         else if ((cave[m_ptr->fy][m_ptr->fx].m_idx == p_ptr->riding) || !p_ptr->inside_battle)
1701                                 (void)strcpy(desc, name);
1702                         else
1703 #ifdef JP
1704                                 (void)sprintf(desc, "%s¤â¤É¤­", name);
1705 #else
1706                                 (void)sprintf(desc, "fake %s", name);
1707 #endif
1708                 }
1709
1710                 /* It could be an indefinite monster */
1711                 else if (mode & MD_INDEF_VISIBLE)
1712                 {
1713                         /* XXX Check plurality for "some" */
1714
1715                         /* Indefinite monsters need an indefinite article */
1716 #ifdef JP
1717                         (void)strcpy(desc, "");
1718 #else
1719                         (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1720 #endif
1721
1722                         (void)strcat(desc, name);
1723                 }
1724
1725                 /* It could be a normal, definite, monster */
1726                 else
1727                 {
1728                         /* Definite monsters need a definite article */
1729                         if (is_pet(m_ptr))
1730 #ifdef JP
1731                                 (void)strcpy(desc, "¤¢¤Ê¤¿¤Î");
1732 #else
1733                                 (void)strcpy(desc, "your ");
1734 #endif
1735
1736                         else
1737 #ifdef JP
1738                                 (void)strcpy(desc, "");
1739 #else
1740                                 (void)strcpy(desc, "the ");
1741 #endif
1742
1743                         (void)strcat(desc, name);
1744                 }
1745
1746                 if (m_ptr->nickname)
1747                 {
1748 #ifdef JP
1749                         sprintf(buf,"¡Ö%s¡×",quark_str(m_ptr->nickname));
1750 #else
1751                         sprintf(buf," called %s",quark_str(m_ptr->nickname));
1752 #endif
1753                         strcat(desc,buf);
1754                 }
1755
1756                 if (player_bold(m_ptr->fy, m_ptr->fx))
1757                 {
1758 #ifdef JP
1759                         strcat(desc,"(¾èÇÏÃæ)");
1760 #else
1761                         strcat(desc,"(riding)");
1762 #endif
1763                 }
1764
1765                 if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1766                 {
1767                         if (r_ptr->flags1 & RF1_UNIQUE)
1768                         {
1769 #ifdef JP
1770                                 strcat(desc,"(¥«¥á¥ì¥ª¥ó¤Î²¦)");
1771 #else
1772                                 strcat(desc,"(Chameleon Lord)");
1773 #endif
1774                         }
1775                         else
1776                         {
1777 #ifdef JP
1778                                 strcat(desc,"(¥«¥á¥ì¥ª¥ó)");
1779 #else
1780                                 strcat(desc,"(Chameleon)");
1781 #endif
1782                         }
1783                 }
1784
1785                 if ((mode & MD_IGNORE_HALLU) && m_ptr->ap_r_idx != m_ptr->r_idx)
1786                 {
1787                         strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1788                 }
1789
1790                 if (mode & MD_ASSUME_OUTSIDE)
1791                 {
1792 #ifdef JP
1793                         strcat(desc,"(ÂÔµ¡Ãæ)");
1794 #else
1795                         strcat(desc,"(waiting)");
1796 #endif
1797                 }
1798
1799                 /* Handle the Possessive as a special afterthought */
1800                 if (mode & MD_POSSESSIVE)
1801                 {
1802                         /* XXX Check for trailing "s" */
1803                         
1804                         /* Simply append "apostrophe" and "s" */
1805 #ifdef JP
1806                         (void)strcat(desc, "¤Î");
1807 #else
1808                         (void)strcat(desc, "'s");
1809 #endif
1810                 }
1811         }
1812 }
1813
1814
1815
1816
1817 /*
1818  * Learn about a monster (by "probing" it)
1819  *
1820  * Return the number of new flags learnt.  -Mogami-
1821  */
1822 int lore_do_probe(int r_idx)
1823 {
1824         monster_race *r_ptr = &r_info[r_idx];
1825         int i, n = 0;
1826         byte tmp_byte;
1827
1828         /* Maximal info about awareness */
1829         if (r_ptr->r_wake != MAX_UCHAR) n++;
1830         if (r_ptr->r_ignore != MAX_UCHAR) n++;
1831         r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1832
1833         /* Observe "maximal" attacks */
1834         for (i = 0; i < 4; i++)
1835         {
1836                 /* Examine "actual" blows */
1837                 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1838                 {
1839                         /* Maximal observations */
1840                         if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1841                         r_ptr->r_blows[i] = MAX_UCHAR;
1842                 }
1843         }
1844
1845         /* Maximal drops */
1846         tmp_byte =
1847                 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1848                  ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1849                  ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1850                  ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1851                  ((r_ptr->flags1 & RF1_DROP_90)  ? 1 : 0) +
1852                  ((r_ptr->flags1 & RF1_DROP_60)  ? 1 : 0));
1853
1854         /* Only "valid" drops */
1855         if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1856         {
1857                 if (r_ptr->r_drop_item != tmp_byte) n++;
1858                 r_ptr->r_drop_item = tmp_byte;
1859         }
1860         if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1861         {
1862                 if (r_ptr->r_drop_gold != tmp_byte) n++;
1863                 r_ptr->r_drop_gold = tmp_byte;
1864         }
1865
1866         /* Observe many spells */
1867         if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1868         r_ptr->r_cast_spell = MAX_UCHAR;
1869
1870         /* Count unknown flags */
1871         for (i = 0; i < 32; i++)
1872         {
1873                 if (!(r_ptr->r_flags1 & (1L << i)) &&
1874                     (r_ptr->flags1 & (1L << i))) n++;
1875                 if (!(r_ptr->r_flags2 & (1L << i)) &&
1876                     (r_ptr->flags2 & (1L << i))) n++;
1877                 if (!(r_ptr->r_flags3 & (1L << i)) &&
1878                     (r_ptr->flags3 & (1L << i))) n++;
1879                 if (!(r_ptr->r_flags4 & (1L << i)) &&
1880                     (r_ptr->flags4 & (1L << i))) n++;
1881                 if (!(r_ptr->r_flags5 & (1L << i)) &&
1882                     (r_ptr->flags5 & (1L << i))) n++;
1883                 if (!(r_ptr->r_flags6 & (1L << i)) &&
1884                     (r_ptr->flags6 & (1L << i))) n++;
1885                 if (!(r_ptr->r_flagsr & (1L << i)) &&
1886                     (r_ptr->flagsr & (1L << i))) n++;
1887
1888                 /* r_flags7 is actually unused */
1889 #if 0
1890                 if (!(r_ptr->r_flags7 & (1L << i)) &&
1891                     (r_ptr->flags7 & (1L << i))) n++;
1892 #endif
1893         }
1894
1895         /* Know all the flags */
1896         r_ptr->r_flags1 = r_ptr->flags1;
1897         r_ptr->r_flags2 = r_ptr->flags2;
1898         r_ptr->r_flags3 = r_ptr->flags3;
1899         r_ptr->r_flags4 = r_ptr->flags4;
1900         r_ptr->r_flags5 = r_ptr->flags5;
1901         r_ptr->r_flags6 = r_ptr->flags6;
1902         r_ptr->r_flagsr = r_ptr->flagsr;
1903
1904         /* r_flags7 is actually unused */
1905         /* r_ptr->r_flags7 = r_ptr->flags7; */
1906
1907         /* Know about evolution */
1908         if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1909         r_ptr->r_xtra1 |= MR1_SINKA;
1910
1911         /* Update monster recall window */
1912         if (p_ptr->monster_race_idx == r_idx)
1913         {
1914                 /* Window stuff */
1915                 p_ptr->window |= (PW_MONSTER);
1916         }
1917
1918         /* Return the number of new flags learnt */
1919         return n;
1920 }
1921
1922
1923 /*
1924  * Take note that the given monster just dropped some treasure
1925  *
1926  * Note that learning the "GOOD"/"GREAT" flags gives information
1927  * about the treasure (even when the monster is killed for the first
1928  * time, such as uniques, and the treasure has not been examined yet).
1929  *
1930  * This "indirect" method is used to prevent the player from learning
1931  * exactly how much treasure a monster can drop from observing only
1932  * a single example of a drop.  This method actually observes how much
1933  * gold and items are dropped, and remembers that information to be
1934  * described later by the monster recall code.
1935  */
1936 void lore_treasure(int m_idx, int num_item, int num_gold)
1937 {
1938         monster_type *m_ptr = &m_list[m_idx];
1939
1940         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1941
1942         /* If the monster doesn't have original appearance, don't note */
1943         if (!is_original_ap(m_ptr)) return;
1944
1945         /* Note the number of things dropped */
1946         if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1947         if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1948
1949         /* Hack -- memorize the good/great flags */
1950         if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1951         if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1952
1953         /* Update monster recall window */
1954         if (p_ptr->monster_race_idx == m_ptr->r_idx)
1955         {
1956                 /* Window stuff */
1957                 p_ptr->window |= (PW_MONSTER);
1958         }
1959 }
1960
1961
1962
1963 void sanity_blast(monster_type *m_ptr, bool necro)
1964 {
1965         bool happened = FALSE;
1966         int power = 100;
1967
1968         if (p_ptr->inside_battle || !character_dungeon) return;
1969
1970         if (!necro)
1971         {
1972                 char            m_name[80];
1973                 monster_race    *r_ptr = &r_info[m_ptr->ap_r_idx];
1974
1975                 power = r_ptr->level / 2;
1976
1977                 monster_desc(m_name, m_ptr, 0);
1978
1979                 if (!(r_ptr->flags1 & RF1_UNIQUE))
1980                 {
1981                         if (r_ptr->flags1 & RF1_FRIENDS)
1982                         power /= 2;
1983                 }
1984                 else power *= 2;
1985
1986                 if (!hack_mind)
1987                         return; /* No effect yet, just loaded... */
1988
1989                 if (!m_ptr->ml)
1990                         return; /* Cannot see it for some reason */
1991
1992                 if (!(r_ptr->flags2 & RF2_ELDRITCH_HORROR))
1993                         return; /* oops */
1994
1995
1996
1997                 if (is_pet(m_ptr))
1998                         return; /* Pet eldritch horrors are safe most of the time */
1999
2000                 if (randint1(100) > power) return;
2001
2002                 if (saving_throw(p_ptr->skill_sav - power))
2003                 {
2004                         return; /* Save, no adverse effects */
2005                 }
2006
2007                 if (p_ptr->image)
2008                 {
2009                         /* Something silly happens... */
2010 #ifdef JP
2011                         msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2012                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2013 #else
2014                         msg_format("You behold the %s visage of %s!",
2015                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2016 #endif
2017
2018
2019                         if (one_in_(3))
2020                         {
2021                                 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
2022                                 p_ptr->image = p_ptr->image + randint1(r_ptr->level);
2023                         }
2024
2025                         return; /* Never mind; we can't see it clearly enough */
2026                 }
2027
2028                 /* Something frightening happens... */
2029 #ifdef JP
2030                 msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2031                         horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2032 #else
2033                 msg_format("You behold the %s visage of %s!",
2034                         horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2035 #endif
2036
2037                 r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
2038
2039                 /* Demon characters are unaffected */
2040                 if (prace_is_(RACE_IMP) || prace_is_(RACE_DEMON) || (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) return;
2041                 if (p_ptr->wizard) return;
2042
2043                 /* Undead characters are 50% likely to be unaffected */
2044                 if (prace_is_(RACE_SKELETON) || prace_is_(RACE_ZOMBIE)
2045                         || prace_is_(RACE_VAMPIRE) || prace_is_(RACE_SPECTRE) ||
2046                     (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD))
2047                 {
2048                         if (saving_throw(25 + p_ptr->lev)) return;
2049                 }
2050         }
2051         else
2052         {
2053 #ifdef JP
2054 msg_print("¥Í¥¯¥í¥Î¥ß¥³¥ó¤òÆɤó¤ÇÀµµ¤¤ò¼º¤Ã¤¿¡ª");
2055 #else
2056                 msg_print("Your sanity is shaken by reading the Necronomicon!");
2057 #endif
2058
2059         }
2060
2061         if (!saving_throw(p_ptr->skill_sav - power)) /* Mind blast */
2062         {
2063                 if (!p_ptr->resist_conf)
2064                 {
2065                         (void)set_confused(p_ptr->confused + randint0(4) + 4);
2066                 }
2067                 if (!p_ptr->resist_chaos && one_in_(3))
2068                 {
2069                         (void)set_image(p_ptr->image + randint0(250) + 150);
2070                 }
2071                 return;
2072         }
2073
2074         if (!saving_throw(p_ptr->skill_sav - power)) /* Lose int & wis */
2075         {
2076                 do_dec_stat(A_INT);
2077                 do_dec_stat(A_WIS);
2078                 return;
2079         }
2080
2081         if (!saving_throw(p_ptr->skill_sav - power)) /* Brain smash */
2082         {
2083                 if (!p_ptr->resist_conf)
2084                 {
2085                         (void)set_confused(p_ptr->confused + randint0(4) + 4);
2086                 }
2087                 if (!p_ptr->free_act)
2088                 {
2089                         (void)set_paralyzed(p_ptr->paralyzed + randint0(4) + 4);
2090                 }
2091                 while (randint0(100) > p_ptr->skill_sav)
2092                         (void)do_dec_stat(A_INT);
2093                 while (randint0(100) > p_ptr->skill_sav)
2094                         (void)do_dec_stat(A_WIS);
2095                 if (!p_ptr->resist_chaos)
2096                 {
2097                         (void)set_image(p_ptr->image + randint0(250) + 150);
2098                 }
2099                 return;
2100         }
2101
2102         if (!saving_throw(p_ptr->skill_sav - power)) /* Amnesia */
2103         {
2104
2105                 if (lose_all_info())
2106 #ifdef JP
2107 msg_print("¤¢¤Þ¤ê¤Î¶²ÉݤËÁ´¤Æ¤Î¤³¤È¤ò˺¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª");
2108 #else
2109                         msg_print("You forget everything in your utmost terror!");
2110 #endif
2111
2112                 return;
2113         }
2114
2115         if (saving_throw(p_ptr->skill_sav - power))
2116         {
2117                 return;
2118         }
2119
2120         /* Else gain permanent insanity */
2121         if ((p_ptr->muta3 & MUT3_MORONIC) && /*(p_ptr->muta2 & MUT2_BERS_RAGE) &&*/
2122                 ((p_ptr->muta2 & MUT2_COWARDICE) || (p_ptr->resist_fear)) &&
2123                 ((p_ptr->muta2 & MUT2_HALLU) || (p_ptr->resist_chaos)))
2124         {
2125                 /* The poor bastard already has all possible insanities! */
2126                 return;
2127         }
2128
2129         while (!happened)
2130         {
2131                 switch (randint1(21))
2132                 {
2133                         case 1:
2134                                 if (!(p_ptr->muta3 & MUT3_MORONIC) && one_in_(5))
2135                                 {
2136                                         if ((p_ptr->stat_use[A_INT] < 4) && (p_ptr->stat_use[A_WIS] < 4))
2137                                         {
2138 #ifdef JP
2139 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¤è¤¦¤Êµ¤¤¬¤·¤¿¡£¤·¤«¤·¤½¤ì¤Ï¸µ¡¹¤À¤Ã¤¿¡£");
2140 #else
2141                                                 msg_print("You turn into an utter moron!");
2142 #endif
2143                                         }
2144                                         else
2145                                         {
2146 #ifdef JP
2147 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¡ª");
2148 #else
2149                                                 msg_print("You turn into an utter moron!");
2150 #endif
2151                                         }
2152
2153                                         if (p_ptr->muta3 & MUT3_HYPER_INT)
2154                                         {
2155 #ifdef JP
2156 msg_print("¤¢¤Ê¤¿¤ÎǾ¤ÏÀ¸ÂÎ¥³¥ó¥Ô¥å¡¼¥¿¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2157 #else
2158                                                 msg_print("Your brain is no longer a living computer.");
2159 #endif
2160
2161                                                 p_ptr->muta3 &= ~(MUT3_HYPER_INT);
2162                                         }
2163                                         p_ptr->muta3 |= MUT3_MORONIC;
2164                                         happened = TRUE;
2165                                 }
2166                                 break;
2167                         case 2:
2168                         case 3:
2169                         case 4:
2170                         case 5:
2171                         case 6:
2172                         case 7:
2173                         case 8:
2174                         case 9:
2175                         case 10:
2176                         case 11:
2177                                 if (!(p_ptr->muta2 & MUT2_COWARDICE) && !p_ptr->resist_fear)
2178                                 {
2179 #ifdef JP
2180 msg_print("¤¢¤Ê¤¿¤Ï¥Ñ¥é¥Î¥¤¥¢¤Ë¤Ê¤Ã¤¿¡ª");
2181 #else
2182                                         msg_print("You become paranoid!");
2183 #endif
2184
2185
2186                                         /* Duh, the following should never happen, but anyway... */
2187                                         if (p_ptr->muta3 & MUT3_FEARLESS)
2188                                         {
2189 #ifdef JP
2190 msg_print("¤¢¤Ê¤¿¤Ï¤â¤¦¶²¤ìÃΤ餺¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2191 #else
2192                                                 msg_print("You are no longer fearless.");
2193 #endif
2194
2195                                                 p_ptr->muta3 &= ~(MUT3_FEARLESS);
2196                                         }
2197
2198                                         p_ptr->muta2 |= MUT2_COWARDICE;
2199                                         happened = TRUE;
2200                                 }
2201                                 break;
2202                         case 12:
2203                         case 13:
2204                         case 14:
2205                         case 15:
2206                         case 16:
2207                         case 17:
2208                         case 18:
2209                         case 19:
2210                         case 20:
2211                         case 21:
2212                                 if (!(p_ptr->muta2 & MUT2_HALLU) && !p_ptr->resist_chaos)
2213                                 {
2214 #ifdef JP
2215 msg_print("¸¸³Ð¤ò¤Ò¤­µ¯¤³¤¹Àº¿ÀºøÍð¤Ë´Ù¤Ã¤¿¡ª");
2216 #else
2217                                         msg_print("You are afflicted by a hallucinatory insanity!");
2218 #endif
2219
2220                                         p_ptr->muta2 |= MUT2_HALLU;
2221                                         happened = TRUE;
2222                                 }
2223                                 break;
2224                         default:
2225                                 if (!(p_ptr->muta2 & MUT2_BERS_RAGE))
2226                                 {
2227 #ifdef JP
2228 msg_print("·ãÎõ¤Ê´¶¾ð¤Îȯºî¤Ë¤ª¤½¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡ª");
2229 #else
2230                                         msg_print("You become subject to fits of berserk rage!");
2231 #endif
2232
2233                                         p_ptr->muta2 |= MUT2_BERS_RAGE;
2234                                         happened = TRUE;
2235                                 }
2236                                 break;
2237                 }
2238         }
2239
2240         p_ptr->update |= PU_BONUS;
2241         handle_stuff();
2242 }
2243
2244
2245 /*
2246  * This function updates the monster record of the given monster
2247  *
2248  * This involves extracting the distance to the player (if requested),
2249  * and then checking for visibility (natural, infravision, see-invis,
2250  * telepathy), updating the monster visibility flag, redrawing (or
2251  * erasing) the monster when its visibility changes, and taking note
2252  * of any interesting monster flags (cold-blooded, invisible, etc).
2253  *
2254  * Note the new "mflag" field which encodes several monster state flags,
2255  * including "view" for when the monster is currently in line of sight,
2256  * and "mark" for when the monster is currently visible via detection.
2257  *
2258  * The only monster fields that are changed here are "cdis" (the
2259  * distance from the player), "ml" (visible to the player), and
2260  * "mflag" (to maintain the "MFLAG_VIEW" flag).
2261  *
2262  * Note the special "update_monsters()" function which can be used to
2263  * call this function once for every monster.
2264  *
2265  * Note the "full" flag which requests that the "cdis" field be updated,
2266  * this is only needed when the monster (or the player) has moved.
2267  *
2268  * Every time a monster moves, we must call this function for that
2269  * monster, and update the distance, and the visibility.  Every time
2270  * the player moves, we must call this function for every monster, and
2271  * update the distance, and the visibility.  Whenever the player "state"
2272  * changes in certain ways ("blindness", "infravision", "telepathy",
2273  * and "see invisible"), we must call this function for every monster,
2274  * and update the visibility.
2275  *
2276  * Routines that change the "illumination" of a grid must also call this
2277  * function for any monster in that grid, since the "visibility" of some
2278  * monsters may be based on the illumination of their grid.
2279  *
2280  * Note that this function is called once per monster every time the
2281  * player moves.  When the player is running, this function is one
2282  * of the primary bottlenecks, along with "update_view()" and the
2283  * "process_monsters()" code, so efficiency is important.
2284  *
2285  * Note the optimized "inline" version of the "distance()" function.
2286  *
2287  * A monster is "visible" to the player if (1) it has been detected
2288  * by the player, (2) it is close to the player and the player has
2289  * telepathy, or (3) it is close to the player, and in line of sight
2290  * of the player, and it is "illuminated" by some combination of
2291  * infravision, torch light, or permanent light (invisible monsters
2292  * are only affected by "light" if the player can see invisible).
2293  *
2294  * Monsters which are not on the current panel may be "visible" to
2295  * the player, and their descriptions will include an "offscreen"
2296  * reference.  Currently, offscreen monsters cannot be targetted
2297  * or viewed directly, but old targets will remain set.  XXX XXX
2298  *
2299  * The player can choose to be disturbed by several things, including
2300  * "disturb_move" (monster which is viewable moves in some way), and
2301  * "disturb_near" (monster which is "easily" viewable moves in some
2302  * way).  Note that "moves" includes "appears" and "disappears".
2303  */
2304 void update_mon(int m_idx, bool full)
2305 {
2306         monster_type *m_ptr = &m_list[m_idx];
2307
2308         monster_race *r_ptr = &r_info[m_ptr->r_idx];
2309
2310         bool do_disturb = disturb_move;
2311
2312         int d;
2313
2314         /* Current location */
2315         int fy = m_ptr->fy;
2316         int fx = m_ptr->fx;
2317
2318         /* Seen at all */
2319         bool flag = FALSE;
2320
2321         /* Seen by vision */
2322         bool easy = FALSE;
2323
2324         /* Non-Ninja player in the darkness */
2325         bool in_darkness = (d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto;
2326
2327         /* Do disturb? */
2328         if (disturb_high)
2329         {
2330                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2331
2332                 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
2333                         do_disturb = TRUE;
2334         }
2335
2336         /* Compute distance */
2337         if (full)
2338         {
2339                 /* Distance components */
2340                 int dy = (py > fy) ? (py - fy) : (fy - py);
2341                 int dx = (px > fx) ? (px - fx) : (fx - px);
2342
2343                 /* Approximate distance */
2344                 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2345
2346                 /* Restrict distance */
2347                 if (d > 255) d = 255;
2348
2349                 if (!d) d = 1;
2350
2351                 /* Save the distance */
2352                 m_ptr->cdis = d;
2353         }
2354
2355         /* Extract distance */
2356         else
2357         {
2358                 /* Extract the distance */
2359                 d = m_ptr->cdis;
2360         }
2361
2362
2363         /* Detected */
2364         if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
2365
2366
2367         /* Nearby */
2368         if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
2369         {
2370                 if (!in_darkness || (d <= MAX_SIGHT / 4))
2371                 {
2372                         if (p_ptr->special_defense & KATA_MUSOU)
2373                         {
2374                                 /* Detectable */
2375                                 flag = TRUE;
2376
2377                                 if (is_original_ap(m_ptr))
2378                                 {
2379                                         /* Hack -- Memorize mental flags */
2380                                         if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2381                                         if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2382                                 }
2383                         }
2384
2385                         /* Basic telepathy */
2386                         else if (p_ptr->telepathy)
2387                         {
2388                                 /* Empty mind, no telepathy */
2389                                 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
2390                                 {
2391                                         /* Memorize flags */
2392                                         if (is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
2393                                 }
2394
2395                                 /* Weird mind, occasional telepathy */
2396                                 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
2397                                 {
2398                                         /* One in ten individuals are detectable */
2399                                         if ((m_idx % 10) == 5)
2400                                         {
2401                                                 /* Detectable */
2402                                                 flag = TRUE;
2403
2404                                                 if (is_original_ap(m_ptr))
2405                                                 {
2406                                                         /* Memorize flags */
2407                                                         r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
2408
2409                                                         /* Hack -- Memorize mental flags */
2410                                                         if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2411                                                         if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2412                                                 }
2413                                         }
2414                                 }
2415
2416                                 /* Normal mind, allow telepathy */
2417                                 else
2418                                 {
2419                                         /* Detectable */
2420                                         flag = TRUE;
2421
2422                                         if (is_original_ap(m_ptr))
2423                                         {
2424                                                 /* Hack -- Memorize mental flags */
2425                                                 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2426                                                 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2427                                         }
2428                                 }
2429                         }
2430
2431                         /* Magical sensing */
2432                         if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
2433                         {
2434                                 flag = TRUE;
2435                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_ANIMAL);
2436                         }
2437
2438                         /* Magical sensing */
2439                         if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
2440                         {
2441                                 flag = TRUE;
2442                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_UNDEAD);
2443                         }
2444
2445                         /* Magical sensing */
2446                         if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
2447                         {
2448                                 flag = TRUE;
2449                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_DEMON);
2450                         }
2451
2452                         /* Magical sensing */
2453                         if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
2454                         {
2455                                 flag = TRUE;
2456                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_ORC);
2457                         }
2458
2459                         /* Magical sensing */
2460                         if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
2461                         {
2462                                 flag = TRUE;
2463                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_TROLL);
2464                         }
2465
2466                         /* Magical sensing */
2467                         if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
2468                         {
2469                                 flag = TRUE;
2470                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_GIANT);
2471                         }
2472
2473                         /* Magical sensing */
2474                         if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
2475                         {
2476                                 flag = TRUE;
2477                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_DRAGON);
2478                         }
2479
2480                         /* Magical sensing */
2481                         if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
2482                         {
2483                                 flag = TRUE;
2484                                 if (is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_HUMAN);
2485                         }
2486
2487                         /* Magical sensing */
2488                         if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
2489                         {
2490                                 flag = TRUE;
2491                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_EVIL);
2492                         }
2493
2494                         /* Magical sensing */
2495                         if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
2496                         {
2497                                 flag = TRUE;
2498                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_GOOD);
2499                         }
2500
2501                         /* Magical sensing */
2502                         if ((p_ptr->esp_nonliving) &&
2503                             ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
2504                         {
2505                                 flag = TRUE;
2506                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_NONLIVING);
2507                         }
2508
2509                         /* Magical sensing */
2510                         if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
2511                         {
2512                                 flag = TRUE;
2513                                 if (is_original_ap(m_ptr)) r_ptr->r_flags1 |= (RF1_UNIQUE);
2514                         }
2515                 }
2516
2517                 /* Normal line of sight, and not blind */
2518                 if (player_has_los_bold(fy, fx) && !p_ptr->blind)
2519                 {
2520                         bool do_invisible = FALSE;
2521                         bool do_cold_blood = FALSE;
2522
2523                         /* Use "infravision" */
2524                         if (d <= p_ptr->see_infra)
2525                         {
2526                                 /* Handle "cold blooded" monsters */
2527                                 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
2528                                 {
2529                                         /* Take note */
2530                                         do_cold_blood = TRUE;
2531                                 }
2532
2533                                 /* Handle "warm blooded" monsters */
2534                                 else
2535                                 {
2536                                         /* Easy to see */
2537                                         easy = flag = TRUE;
2538                                 }
2539                         }
2540
2541                         /* Use "illumination" */
2542                         if (player_can_see_bold(fy, fx))
2543                         {
2544                                 /* Handle "invisible" monsters */
2545                                 if (r_ptr->flags2 & (RF2_INVISIBLE))
2546                                 {
2547                                         /* Take note */
2548                                         do_invisible = TRUE;
2549
2550                                         /* See invisible */
2551                                         if (p_ptr->see_inv)
2552                                         {
2553                                                 /* Easy to see */
2554                                                 easy = flag = TRUE;
2555                                         }
2556                                 }
2557
2558                                 /* Handle "normal" monsters */
2559                                 else
2560                                 {
2561                                         /* Easy to see */
2562                                         easy = flag = TRUE;
2563                                 }
2564                         }
2565
2566                         /* Visible */
2567                         if (flag)
2568                         {
2569                                 if (is_original_ap(m_ptr))
2570                                 {
2571                                         /* Memorize flags */
2572                                         if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2573                                         if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2574                                 }
2575                         }
2576                 }
2577         }
2578
2579
2580         /* The monster is now visible */
2581         if (flag)
2582         {
2583                 /* It was previously unseen */
2584                 if (!m_ptr->ml)
2585                 {
2586                         /* Mark as visible */
2587                         m_ptr->ml = TRUE;
2588
2589                         /* Draw the monster */
2590                         lite_spot(fy, fx);
2591
2592                         /* Update health bar as needed */
2593                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2594                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2595
2596                         /* Hack -- Count "fresh" sightings */
2597                         if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2598                                 r_info[MON_KAGE].r_sights++;
2599                         else if (m_ptr->ap_r_idx == m_ptr->r_idx && 
2600                                  r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
2601
2602                         /* Eldritch Horror */
2603                         if (r_ptr->flags2 & RF2_ELDRITCH_HORROR)
2604                         {
2605                                 sanity_blast(m_ptr, FALSE);
2606                         }
2607
2608                         /* Disturb on appearance */
2609                         if (disturb_near && (projectable(m_ptr->fy, m_ptr->fx, py, px) && projectable(py, px, m_ptr->fy, m_ptr->fx)))
2610                         {
2611                                 if (disturb_pets || is_hostile(m_ptr))
2612                                         disturb(1, 0);
2613                         }
2614                 }
2615         }
2616
2617         /* The monster is not visible */
2618         else
2619         {
2620                 /* It was previously seen */
2621                 if (m_ptr->ml)
2622                 {
2623                         /* Mark as not visible */
2624                         m_ptr->ml = FALSE;
2625
2626                         /* Erase the monster */
2627                         lite_spot(fy, fx);
2628
2629                         /* Update health bar as needed */
2630                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2631                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2632
2633                         /* Disturb on disappearance */
2634                         if (do_disturb)
2635                         {
2636                                 if (disturb_pets || is_hostile(m_ptr))
2637                                         disturb(1, 0);
2638                         }
2639                 }
2640         }
2641
2642
2643         /* The monster is now easily visible */
2644         if (easy)
2645         {
2646                 /* Change */
2647                 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2648                 {
2649                         /* Mark as easily visible */
2650                         m_ptr->mflag |= (MFLAG_VIEW);
2651
2652                         /* Disturb on appearance */
2653                         if (do_disturb)
2654                         {
2655                                 if (disturb_pets || is_hostile(m_ptr))
2656                                         disturb(1, 0);
2657                         }
2658                 }
2659         }
2660
2661         /* The monster is not easily visible */
2662         else
2663         {
2664                 /* Change */
2665                 if (m_ptr->mflag & (MFLAG_VIEW))
2666                 {
2667                         /* Mark as not easily visible */
2668                         m_ptr->mflag &= ~(MFLAG_VIEW);
2669
2670                         /* Disturb on disappearance */
2671                         if (do_disturb)
2672                         {
2673                                 if (disturb_pets || is_hostile(m_ptr))
2674                                         disturb(1, 0);
2675                         }
2676                 }
2677         }
2678 }
2679
2680
2681 /*
2682  * This function simply updates all the (non-dead) monsters (see above).
2683  */
2684 void update_monsters(bool full)
2685 {
2686         int i;
2687
2688         /* Update each (live) monster */
2689         for (i = 1; i < m_max; i++)
2690         {
2691                 monster_type *m_ptr = &m_list[i];
2692
2693                 /* Skip dead monsters */
2694                 if (!m_ptr->r_idx) continue;
2695
2696                 /* Update the monster */
2697                 update_mon(i, full);
2698         }
2699 }
2700
2701
2702 /*
2703  * Hack -- the index of the summoning monster
2704  */
2705 static bool monster_hook_chameleon_lord(int r_idx)
2706 {
2707         monster_race *r_ptr = &r_info[r_idx];
2708         monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2709         monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2710
2711         if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2712         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2713
2714         if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2715
2716         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))
2717                 return FALSE;
2718
2719         if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr)) return FALSE;
2720
2721         /* Not born */
2722         if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2723         {
2724                 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
2725         }
2726
2727         /* Born now */
2728         else if (summon_specific_who > 0)
2729         {
2730                 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2731         }
2732
2733         return TRUE;
2734 }
2735
2736 static bool monster_hook_chameleon(int r_idx)
2737 {
2738         monster_race *r_ptr = &r_info[r_idx];
2739         monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2740         monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2741
2742         if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2743         if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2744         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2745         
2746         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))
2747                 return FALSE;
2748
2749         if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr)) return FALSE;
2750
2751         /* Not born */
2752         if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2753         {
2754                 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2755                 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2756                 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2757         }
2758
2759         /* Born now */
2760         else if (summon_specific_who > 0)
2761         {
2762                 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2763         }
2764
2765         return (*(get_monster_hook()))(r_idx);
2766 }
2767
2768
2769 void choose_new_monster(int m_idx, bool born, int r_idx)
2770 {
2771         int oldmaxhp;
2772         monster_type *m_ptr = &m_list[m_idx];
2773         monster_race *r_ptr;
2774         char old_m_name[80];
2775         bool old_unique = FALSE;
2776
2777         if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2778                 old_unique = TRUE;
2779         if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2780         r_ptr = &r_info[r_idx];
2781
2782         monster_desc(old_m_name, m_ptr, 0);
2783
2784         if (!r_idx)
2785         {
2786                 int level;
2787
2788                 chameleon_change_m_idx = m_idx;
2789                 if (old_unique)
2790                         get_mon_num_prep(monster_hook_chameleon_lord, NULL);
2791                 else
2792                         get_mon_num_prep(monster_hook_chameleon, NULL);
2793
2794                 if (old_unique)
2795                         level = r_info[MON_CHAMELEON_K].level;
2796                 else if (!dun_level)
2797                         level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
2798                 else
2799                         level = dun_level;
2800
2801                 if (d_info[dungeon_type].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
2802
2803                 r_idx = get_mon_num(level);
2804                 r_ptr = &r_info[r_idx];
2805
2806                 chameleon_change_m_idx = 0;
2807
2808                 /* Paranoia */
2809                 if (!r_idx) return;
2810         }
2811
2812         m_ptr->r_idx = r_idx;
2813         m_ptr->ap_r_idx = r_idx;
2814         update_mon(m_idx, FALSE);
2815         lite_spot(m_ptr->fy, m_ptr->fx);
2816         if (born)
2817         {
2818                 /* Sub-alignment of a chameleon */
2819                 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2820                 {
2821                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2822                         if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2823                         if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2824                 }
2825                 return;
2826         }
2827
2828         if (m_idx == p_ptr->riding)
2829         {
2830                 char m_name[80];
2831                 monster_desc(m_name, m_ptr, 0);
2832 #ifdef JP
2833                 msg_format("ÆÍÁ³%s¤¬ÊѿȤ·¤¿¡£", old_m_name);
2834 #else
2835                 msg_format("Suddenly, %s transforms!", old_m_name);
2836 #endif
2837                 if (!(r_ptr->flags7 & RF7_RIDING))
2838 #ifdef JP
2839                         if (rakuba(0, TRUE)) msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2840 #else
2841                         if (rakuba(0, TRUE)) msg_format("You have fallen from %s.", m_name);
2842 #endif
2843         }
2844
2845         /* Extract the monster base speed */
2846         m_ptr->mspeed = get_mspeed(r_ptr);
2847
2848         oldmaxhp = m_ptr->max_maxhp;
2849         /* Assign maximal hitpoints */
2850         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2851         {
2852                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2853         }
2854         else
2855         {
2856                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2857         }
2858         m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2859         m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2860 }
2861
2862
2863 /*
2864  *  Hook for Tanuki
2865  */
2866 static bool monster_hook_tanuki(int r_idx)
2867 {
2868         monster_race *r_ptr = &r_info[r_idx];
2869
2870         if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2871         if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2872         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2873         if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2874         
2875         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))
2876                 return FALSE;
2877
2878         return (*(get_monster_hook()))(r_idx);
2879 }
2880
2881
2882 /*
2883  *  Set initial racial appearance of a monster
2884  */
2885 static int initial_r_appearance(int r_idx)
2886 {
2887         int attempts = 1000;
2888
2889         int ap_r_idx;
2890         int min = MIN(base_level-5, 50);
2891
2892         if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2893                 return r_idx;
2894
2895         get_mon_num_prep(monster_hook_tanuki, NULL);
2896
2897         while (--attempts)
2898         {
2899                 ap_r_idx = get_mon_num(base_level + 10);
2900                 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2901         }
2902
2903         return r_idx;
2904 }
2905
2906
2907 /*
2908  * Get initial monster speed
2909  */
2910 byte get_mspeed(monster_race *r_ptr)
2911 {
2912         /* Extract the monster base speed */
2913         int mspeed = r_ptr->speed;
2914
2915         /* Hack -- small racial variety */
2916         if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
2917         {
2918                 /* Allow some small variation per monster */
2919                 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2920                 if (i) mspeed += rand_spread(0, i);
2921         }
2922
2923         if (mspeed > 199) mspeed = 199;
2924
2925         return (byte)mspeed;
2926 }
2927
2928
2929 /*
2930  * Attempt to place a monster of the given race at the given location.
2931  *
2932  * To give the player a sporting chance, any monster that appears in
2933  * line-of-sight and is extremely dangerous can be marked as
2934  * "FORCE_SLEEP", which will cause them to be placed with low energy,
2935  * which often (but not always) lets the player move before they do.
2936  *
2937  * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2938  *
2939  * XXX XXX XXX Use special "here" and "dead" flags for unique monsters,
2940  * remove old "cur_num" and "max_num" fields.
2941  *
2942  * XXX XXX XXX Actually, do something similar for artifacts, to simplify
2943  * the "preserve" mode, and to make the "what artifacts" flag more useful.
2944  *
2945  * This is the only function which may place a monster in the dungeon,
2946  * except for the savefile loading code.
2947  */
2948 bool place_monster_one(int who, int y, int x, int r_idx, u32b mode)
2949 {
2950         cave_type               *c_ptr;
2951
2952         monster_type    *m_ptr;
2953
2954         monster_race    *r_ptr = &r_info[r_idx];
2955
2956         cptr            name = (r_name + r_ptr->name);
2957
2958         /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
2959         if(p_ptr->wild_mode) return FALSE;
2960
2961         /* Verify location */
2962         if (!in_bounds(y, x)) return (FALSE);
2963
2964         /* Require empty space (if not ghostly) */
2965         if (!(!dun_level && (cave[y][x].feat == FEAT_MOUNTAIN) && ((r_ptr->flags8 & RF8_WILD_MOUNTAIN) || (r_ptr->flags7 & RF7_CAN_FLY))) &&
2966             !(cave_empty_bold2(y, x) || (mode & PM_IGNORE_TERRAIN)) &&
2967             !((r_ptr->flags2 & RF2_PASS_WALL) &&
2968               !(cave_perma_bold(y, x) || cave[y][x].m_idx ||
2969             player_bold(y, x)))) return (FALSE);
2970
2971         /* Paranoia */
2972         if (!r_idx) return (FALSE);
2973
2974         /* Paranoia */
2975         if (!r_ptr->name) return (FALSE);
2976
2977         /* Nor on the Pattern */
2978         if ((cave[y][x].feat >= FEAT_PATTERN_START)
2979          && (cave[y][x].feat <= FEAT_PATTERN_XTRA2))
2980                 return (FALSE);
2981
2982         if (!(mode & PM_IGNORE_TERRAIN) &&
2983             !monster_can_cross_terrain(cave[y][x].feat, r_ptr))
2984         {
2985                 return FALSE;
2986         }
2987
2988         if (!p_ptr->inside_battle)
2989         {
2990                 /* Hack -- "unique" monsters must be "unique" */
2991                 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
2992                      (r_ptr->flags7 & (RF7_UNIQUE_7))) &&
2993                     (r_ptr->cur_num >= r_ptr->max_num))
2994                 {
2995                         /* Cannot create */
2996                         return (FALSE);
2997                 }
2998
2999                 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
3000                     (r_ptr->cur_num >= 1))
3001                 {
3002                         return (FALSE);
3003                 }
3004
3005                 if (r_idx == MON_BANORLUPART)
3006                 {
3007                         if (r_info[MON_BANOR].cur_num > 0) return FALSE;
3008                         if (r_info[MON_LUPART].cur_num > 0) return FALSE;
3009                 }
3010
3011                 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
3012                 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (dun_level < r_ptr->level) &&
3013                     (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
3014                 {
3015                         /* Cannot create */
3016                         return (FALSE);
3017                 }
3018         }
3019
3020         if (quest_number(dun_level))
3021         {
3022                 int hoge = quest_number(dun_level);
3023                 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
3024                 {
3025                         if(r_idx == quest[hoge].r_idx)
3026                         {
3027                                 int number_mon, i2, j2;
3028                                 number_mon = 0;
3029
3030                                 /* Count all quest monsters */
3031                                 for (i2 = 0; i2 < cur_wid; ++i2)
3032                                         for (j2 = 0; j2 < cur_hgt; j2++)
3033                                                 if (cave[j2][i2].m_idx > 0)
3034                                                         if (m_list[cave[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
3035                                                                 number_mon++;
3036                                 if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
3037                                         return FALSE;
3038                         }
3039                 }
3040         }
3041
3042         /* Access the location */
3043         c_ptr = &cave[y][x];
3044
3045         if (is_glyph_grid(c_ptr))
3046         {
3047                 if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
3048                 {
3049                         /* Describe observable breakage */
3050                         if (c_ptr->info & CAVE_MARK)
3051                         {
3052 #ifdef JP
3053 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3054 #else
3055                                 msg_print("The rune of protection is broken!");
3056 #endif
3057
3058                         }
3059
3060                         /* Forget the rune */
3061                         c_ptr->info &= ~(CAVE_MARK);
3062
3063                         /* Break the rune */
3064                         c_ptr->info &= ~(CAVE_OBJECT);
3065                         c_ptr->mimic = 0;
3066
3067                         /* Notice */
3068                         note_spot(y, x);
3069                 }
3070                 else return FALSE;
3071         }
3072
3073         /* Powerful monster */
3074         if (r_ptr->level > dun_level)
3075         {
3076                 /* Unique monsters */
3077                 if (r_ptr->flags1 & (RF1_UNIQUE))
3078                 {
3079                         /* Message for cheaters */
3080 #ifdef JP
3081                         if (cheat_hear) msg_format("¿¼ÁؤΥæ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3082 #else
3083                         if (cheat_hear) msg_format("Deep Unique (%s).", name);
3084 #endif
3085
3086
3087                         /* Boost rating by twice delta-depth */
3088                         rating += (r_ptr->level - dun_level) * 2;
3089                 }
3090
3091                 /* Normal monsters */
3092                 else
3093                 {
3094                         /* Message for cheaters */
3095 #ifdef JP
3096                         if (cheat_hear) msg_format("¿¼ÁؤΥâ¥ó¥¹¥¿¡¼ (%s)¡£", name);
3097 #else
3098                         if (cheat_hear) msg_format("Deep Monster (%s).", name);
3099 #endif
3100
3101
3102                         /* Boost rating by delta-depth */
3103                         rating += (r_ptr->level - dun_level);
3104                 }
3105         }
3106
3107         /* Note the monster */
3108         else if (r_ptr->flags1 & (RF1_UNIQUE))
3109         {
3110                 /* Unique monsters induce message */
3111 #ifdef JP
3112                 if (cheat_hear) msg_format("¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3113 #else
3114                 if (cheat_hear) msg_format("Unique (%s).", name);
3115 #endif
3116
3117         }
3118
3119         if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7) || (r_ptr->level < 10)) is_kage = FALSE;
3120
3121         /* Make a new monster */
3122         c_ptr->m_idx = m_pop();
3123         hack_m_idx_ii = c_ptr->m_idx;
3124
3125         /* Mega-Hack -- catch "failure" */
3126         if (!c_ptr->m_idx) return (FALSE);
3127
3128
3129         /* Get a new monster record */
3130         m_ptr = &m_list[c_ptr->m_idx];
3131
3132         /* Save the race */
3133         m_ptr->r_idx = r_idx;
3134         m_ptr->ap_r_idx = initial_r_appearance(r_idx);
3135
3136         /* Sub-alignment of a monster */
3137         if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
3138                 m_ptr->sub_align = m_list[who].sub_align;
3139         else
3140         {
3141                 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3142                 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
3143                 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
3144         }
3145
3146         /* Place the monster at the location */
3147         m_ptr->fy = y;
3148         m_ptr->fx = x;
3149
3150
3151         /* No "damage" yet */
3152         m_ptr->stunned = 0;
3153         m_ptr->confused = 0;
3154         m_ptr->monfear = 0;
3155
3156         /* Unknown distance */
3157         m_ptr->cdis = 0;
3158
3159         reset_target(m_ptr);
3160
3161         m_ptr->nickname = 0;
3162
3163         m_ptr->exp = 0;
3164
3165         /* No flags */
3166         m_ptr->mflag = 0;
3167         m_ptr->mflag2 = 0;
3168
3169         if (r_ptr->flags7 & RF7_CHAMELEON)
3170         {
3171                 choose_new_monster(c_ptr->m_idx, TRUE, 0);
3172                 r_ptr = &r_info[m_ptr->r_idx];
3173                 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
3174                 rating++;
3175
3176                 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
3177                 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
3178                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3179         }
3180         else if (is_kage)
3181         {
3182                 m_ptr->ap_r_idx = MON_KAGE;
3183                 m_ptr->mflag2 |= MFLAG2_KAGE;
3184         }
3185
3186         if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
3187
3188         /* Not visible */
3189         m_ptr->ml = FALSE;
3190
3191         /* Pet? */
3192         if (mode & PM_FORCE_PET)
3193         {
3194                 set_pet(m_ptr);
3195         }
3196         /* Friendly? */
3197         else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
3198                  (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
3199         {
3200                 if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
3201         }
3202
3203         /* Assume no sleeping */
3204         m_ptr->csleep = 0;
3205
3206         /* Enforce sleeping if needed */
3207         if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
3208         {
3209                 int val = r_ptr->sleep;
3210                 m_ptr->csleep = ((val * 2) + randint1(val * 10));
3211         }
3212
3213         /* Assign maximal hitpoints */
3214         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
3215         {
3216                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
3217         }
3218         else
3219         {
3220                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
3221         }
3222
3223         /* Monsters have double hitpoints in Nightmare mode */
3224         if (ironman_nightmare)
3225         {
3226                 u32b hp = m_ptr->max_maxhp * 2L;
3227
3228                 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
3229         }
3230
3231         m_ptr->maxhp = m_ptr->max_maxhp;
3232
3233         /* And start out fully healthy */
3234         if (m_ptr->r_idx == MON_WOUNDED_BEAR)
3235                 m_ptr->hp = m_ptr->maxhp / 2;
3236         else m_ptr->hp = m_ptr->maxhp;
3237
3238
3239         /* Extract the monster base speed */
3240         m_ptr->mspeed = get_mspeed(r_ptr);
3241
3242         if (mode & PM_HASTE) m_ptr->fast = 100;
3243
3244         /* Give a random starting energy */
3245         if (!ironman_nightmare)
3246         {
3247                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
3248         }
3249         else
3250         {
3251                 /* Nightmare monsters are more prepared */
3252                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
3253         }
3254
3255         /* Force monster to wait for player, unless in Nightmare mode */
3256         if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
3257         {
3258                 /* Monster is still being nice */
3259                 m_ptr->mflag |= (MFLAG_NICE);
3260
3261                 /* Must repair monsters */
3262                 repair_monsters = TRUE;
3263         }
3264
3265         /* Hack -- see "process_monsters()" */
3266         if (c_ptr->m_idx < hack_m_idx)
3267         {
3268                 /* Monster is still being born */
3269                 m_ptr->mflag |= (MFLAG_BORN);
3270         }
3271
3272
3273         if (r_ptr->flags7 & RF7_SELF_LD_MASK)
3274                 p_ptr->update |= (PU_MON_LITE);
3275         else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !m_ptr->csleep)
3276                 p_ptr->update |= (PU_MON_LITE);
3277
3278         /* Update the monster */
3279         update_mon(c_ptr->m_idx, TRUE);
3280
3281
3282         /* Count the monsters on the level */
3283         real_r_ptr(m_ptr)->cur_num++;
3284
3285         /*
3286          * Memorize location of the unique monster in saved floors.
3287          * A unique monster move from old saved floor.
3288          */
3289         if (character_dungeon &&
3290             ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)))
3291                 real_r_ptr(m_ptr)->floor_id = p_ptr->floor_id;
3292
3293         /* Hack -- Count the number of "reproducers" */
3294         if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
3295
3296
3297         /* Hack -- Notice new multi-hued monsters */
3298         {
3299                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3300                 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
3301                         shimmer_monsters = TRUE;
3302         }
3303
3304         if (p_ptr->warning && character_dungeon)
3305         {
3306                 if (r_ptr->flags1 & RF1_UNIQUE)
3307                 {
3308                         cptr color;
3309                         object_type *o_ptr;
3310                         char o_name[MAX_NLEN];
3311
3312                         if (r_ptr->level > p_ptr->lev + 30)
3313 #ifdef JP
3314                                 color = "¹õ¤¯";
3315 #else
3316                                 color = "black";
3317 #endif
3318                         else if (r_ptr->level > p_ptr->lev + 15)
3319 #ifdef JP
3320                                 color = "»ç¿§¤Ë";
3321 #else
3322                                 color = "purple";
3323 #endif
3324                         else if (r_ptr->level > p_ptr->lev + 5)
3325 #ifdef JP
3326                                 color = "¥ë¥Ó¡¼¿§¤Ë";
3327 #else
3328                                 color = "deep red";
3329 #endif
3330                         else if (r_ptr->level > p_ptr->lev - 5)
3331 #ifdef JP
3332                                 color = "ÀÖ¤¯";
3333 #else
3334                                 color = "red";
3335 #endif
3336                         else if (r_ptr->level > p_ptr->lev - 15)
3337 #ifdef JP
3338                                 color = "¥Ô¥ó¥¯¿§¤Ë";
3339 #else
3340                                 color = "pink";
3341 #endif
3342                         else
3343 #ifdef JP
3344                                 color = "Çò¤¯";
3345 #else
3346                                 color = "white";
3347 #endif
3348
3349                         o_ptr = choose_warning_item();
3350                         if (o_ptr)
3351                         {
3352                                 object_desc(o_name, o_ptr, FALSE, 0);
3353 #ifdef JP
3354                                 msg_format("%s¤Ï%s¸÷¤Ã¤¿¡£", o_name, color);
3355 #else
3356                                 msg_format("%s glows %s.", o_name, color);
3357 #endif
3358                         }
3359                         else
3360                         {
3361 #ifdef JP
3362                                 msg_format("s%¸÷¤ëʪ¤¬Æ¬¤ËÉ⤫¤ó¤À¡£", color);
3363 #else
3364                                 msg_format("An %s image forms in your mind.");
3365 #endif
3366                         }
3367                 }
3368         }
3369
3370         if (is_explosive_rune_grid(c_ptr))
3371         {
3372                 /* Break the ward */
3373                 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3374                 {
3375                         /* Describe observable breakage */
3376                         if (c_ptr->info & CAVE_MARK)
3377                         {
3378 #ifdef JP
3379 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3380 #else
3381                                 msg_print("The rune explodes!");
3382 #endif
3383
3384                                 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);
3385                         }
3386                 }
3387                 else
3388                 {
3389 #ifdef JP
3390 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3391 #else
3392                         msg_print("An explosive rune was disarmed.");
3393 #endif
3394                 }
3395
3396                 /* Forget the rune */
3397                 c_ptr->info &= ~(CAVE_MARK);
3398
3399                 /* Break the rune */
3400                 c_ptr->info &= ~(CAVE_OBJECT);
3401                 c_ptr->mimic = 0;
3402
3403                 note_spot(y, x);
3404                 lite_spot(y, x);
3405         }
3406
3407         /* Success */
3408         return (TRUE);
3409 }
3410
3411
3412 /*
3413  *  improved version of scatter() for place monster
3414  */
3415
3416 #define MON_SCAT_MAXD 10
3417
3418 static bool mon_scatter(int *yp, int *xp, int y, int x, int max_dist)
3419 {
3420         int place_x[MON_SCAT_MAXD];
3421         int place_y[MON_SCAT_MAXD];
3422         int num[MON_SCAT_MAXD];
3423         int i;
3424         int nx, ny;
3425
3426         if (max_dist >= MON_SCAT_MAXD)
3427                 return FALSE;
3428
3429         for (i = 0; i < MON_SCAT_MAXD; i++)
3430                 num[i] = 0;
3431
3432         for (nx = x - max_dist; nx <= x + max_dist; nx++)
3433                 for (ny = y - max_dist; ny <= y + max_dist; ny++)
3434                 {
3435                         /* Ignore annoying locations */
3436                         if (!in_bounds(ny, nx)) continue;
3437
3438                         /* Require "line of sight" */
3439                         if (!los(y, x, ny, nx)) continue;
3440
3441                         /* Walls and Monsters block flow */
3442                         if (!cave_empty_bold2(ny, nx)) continue;
3443                         if (cave[ny][nx].m_idx) continue;
3444                         if (player_bold(ny, nx)) continue;
3445
3446                         /* ... nor on the Pattern */
3447                         if ((cave[ny][nx].feat >= FEAT_PATTERN_START) &&
3448                             (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2))
3449                                 continue;
3450
3451                         i = distance(y, x, ny, nx);
3452
3453                         if (i > max_dist)
3454                                 continue;
3455
3456                         num[i]++;
3457
3458                         /* random swap */
3459                         if(one_in_(num[i]))
3460                         {
3461                                 place_x[i] = nx;
3462                                 place_y[i] = ny;
3463                         }
3464                 }
3465
3466         i = 0;
3467         while (i < MON_SCAT_MAXD && 0 == num[i])
3468                 i++;
3469         if (i >= MON_SCAT_MAXD)
3470                 return FALSE;
3471
3472         *xp = place_x[i];
3473         *yp = place_y[i];
3474
3475         return TRUE;
3476 }
3477
3478
3479 /*
3480  * Maximum size of a group of monsters
3481  */
3482 #define GROUP_MAX       32
3483
3484
3485 /*
3486  * Attempt to place a "group" of monsters around the given location
3487  */
3488 static bool place_monster_group(int who, int y, int x, int r_idx, u32b mode)
3489 {
3490         monster_race *r_ptr = &r_info[r_idx];
3491
3492         int old, n, i;
3493         int total = 0, extra = 0;
3494
3495         int hack_n = 0;
3496
3497         byte hack_y[GROUP_MAX];
3498         byte hack_x[GROUP_MAX];
3499
3500
3501         /* Pick a group size */
3502         total = randint1(10);
3503
3504         /* Hard monsters, small groups */
3505         if (r_ptr->level > dun_level)
3506         {
3507                 extra = r_ptr->level - dun_level;
3508                 extra = 0 - randint1(extra);
3509         }
3510
3511         /* Easy monsters, large groups */
3512         else if (r_ptr->level < dun_level)
3513         {
3514                 extra = dun_level - r_ptr->level;
3515                 extra = randint1(extra);
3516         }
3517
3518         /* Hack -- limit group reduction */
3519         if (extra > 9) extra = 9;
3520
3521         /* Modify the group size */
3522         total += extra;
3523
3524         /* Minimum size */
3525         if (total < 1) total = 1;
3526
3527         /* Maximum size */
3528         if (total > GROUP_MAX) total = GROUP_MAX;
3529
3530
3531         /* Save the rating */
3532         old = rating;
3533
3534         /* Start on the monster */
3535         hack_n = 1;
3536         hack_x[0] = x;
3537         hack_y[0] = y;
3538
3539         /* Puddle monsters, breadth first, up to total */
3540         for (n = 0; (n < hack_n) && (hack_n < total); n++)
3541         {
3542                 /* Grab the location */
3543                 int hx = hack_x[n];
3544                 int hy = hack_y[n];
3545
3546                 /* Check each direction, up to total */
3547                 for (i = 0; (i < 8) && (hack_n < total); i++)
3548                 {
3549                         int mx, my;
3550
3551                         scatter(&my, &mx, hy, hx, 4, 0);
3552
3553                         /* Walls and Monsters block flow */
3554                         if (!cave_empty_bold2(my, mx)) continue;
3555
3556                         /* Attempt to place another monster */
3557                         if (place_monster_one(who, my, mx, r_idx, mode))
3558                         {
3559                                 /* Add it to the "hack" set */
3560                                 hack_y[hack_n] = my;
3561                                 hack_x[hack_n] = mx;
3562                                 hack_n++;
3563                         }
3564                 }
3565         }
3566
3567         /* Hack -- restore the rating */
3568         rating = old;
3569
3570
3571         /* Success */
3572         return (TRUE);
3573 }
3574
3575
3576 /*
3577  * Hack -- help pick an escort type
3578  */
3579 static int place_monster_idx = 0;
3580 static int place_monster_m_idx = 0;
3581
3582 /*
3583  * Hack -- help pick an escort type
3584  */
3585 static bool place_monster_okay(int r_idx)
3586 {
3587         monster_race *r_ptr = &r_info[place_monster_idx];
3588         monster_type *m_ptr = &m_list[place_monster_m_idx];
3589
3590         monster_race *z_ptr = &r_info[r_idx];
3591
3592         /* Hack - Escorts have to have the same dungeon flag */
3593         if (monster_dungeon(place_monster_idx) != monster_dungeon(r_idx)) return (FALSE);
3594
3595         /* Require similar "race" */
3596         if (z_ptr->d_char != r_ptr->d_char) return (FALSE);
3597
3598         /* Skip more advanced monsters */
3599         if (z_ptr->level > r_ptr->level) return (FALSE);
3600
3601         /* Skip unique monsters */
3602         if (z_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3603
3604         /* Paranoia -- Skip identical monsters */
3605         if (place_monster_idx == r_idx) return (FALSE);
3606
3607         /* Skip different alignment */
3608         if (monster_has_hostile_align(m_ptr, 0, 0, z_ptr)) return FALSE;
3609
3610         if (r_ptr->flags7 & RF7_FRIENDLY)
3611         {
3612                 if (monster_has_hostile_align(NULL, 1, -1, z_ptr)) return FALSE;
3613         }
3614
3615         if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3616                 return FALSE;
3617
3618         /* Okay */
3619         return (TRUE);
3620 }
3621
3622
3623 /*
3624  * Attempt to place a monster of the given race at the given location
3625  *
3626  * Note that certain monsters are now marked as requiring "friends".
3627  * These monsters, if successfully placed, and if the "grp" parameter
3628  * is TRUE, will be surrounded by a "group" of identical monsters.
3629  *
3630  * Note that certain monsters are now marked as requiring an "escort",
3631  * which is a collection of monsters with similar "race" but lower level.
3632  *
3633  * Some monsters induce a fake "group" flag on their escorts.
3634  *
3635  * Note the "bizarre" use of non-recursion to prevent annoying output
3636  * when running a code profiler.
3637  *
3638  * Note the use of the new "monster allocation table" code to restrict
3639  * the "get_mon_num()" function to "legal" escort types.
3640  */
3641 bool place_monster_aux(int who, int y, int x, int r_idx, u32b mode)
3642 {
3643         int             i;
3644         monster_race    *r_ptr = &r_info[r_idx];
3645
3646         if (one_in_(333) && !(mode & PM_NO_KAGE) && !(mode & PM_FORCE_PET))
3647                 is_kage = TRUE;
3648         else
3649                 is_kage = FALSE;
3650
3651         /* Place one monster, or fail */
3652         if (!place_monster_one(who, y, x, r_idx, mode)) return (FALSE);
3653
3654
3655         /* Require the "group" flag */
3656         if (!(mode & PM_ALLOW_GROUP)) return (TRUE);
3657
3658         place_monster_m_idx = hack_m_idx_ii;
3659
3660         /* Friends for certain monsters */
3661         if (r_ptr->flags1 & (RF1_FRIENDS))
3662         {
3663                 /* Attempt to place a group */
3664                 (void)place_monster_group(who, y, x, r_idx, mode);
3665         }
3666
3667
3668         /* Escorts for certain monsters */
3669         if (r_ptr->flags1 & (RF1_ESCORT))
3670         {
3671                 /* Set the escort index */
3672                 place_monster_idx = r_idx;
3673
3674                 /* Try to place several "escorts" */
3675                 for (i = 0; i < 32; i++)
3676                 {
3677                         int nx, ny, z, d = 3;
3678
3679                         /* Pick a location */
3680                         scatter(&ny, &nx, y, x, d, 0);
3681
3682                         /* Require empty grids */
3683                         if (!cave_empty_bold2(ny, nx)) continue;
3684
3685                         /* Prepare allocation table */
3686                         get_mon_num_prep(place_monster_okay, get_monster_hook2(ny, nx));
3687
3688                         /* Pick a random race */
3689                         z = get_mon_num(r_ptr->level);
3690
3691                         /* Handle failure */
3692                         if (!z) break;
3693
3694                         /* Place a single escort */
3695                         (void)place_monster_one(place_monster_m_idx, ny, nx, z, mode);
3696
3697                         /* Place a "group" of escorts if needed */
3698                         if ((r_info[z].flags1 & RF1_FRIENDS) ||
3699                             (r_ptr->flags1 & RF1_ESCORTS))
3700                         {
3701                                 /* Place a group of monsters */
3702                                 (void)place_monster_group(place_monster_m_idx, ny, nx, z, mode);
3703                         }
3704                 }
3705         }
3706
3707         /* Success */
3708         return (TRUE);
3709 }
3710
3711
3712 /*
3713  * Hack -- attempt to place a monster at the given location
3714  *
3715  * Attempt to find a monster appropriate to the "monster_level"
3716  */
3717 bool place_monster(int y, int x, u32b mode)
3718 {
3719         int r_idx;
3720
3721         /* Prepare allocation table */
3722         get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3723
3724         /* Pick a monster */
3725         r_idx = get_mon_num(monster_level);
3726
3727         /* Handle failure */
3728         if (!r_idx) return (FALSE);
3729
3730         /* Attempt to place the monster */
3731         if (place_monster_aux(0, y, x, r_idx, mode)) return (TRUE);
3732
3733         /* Oops */
3734         return (FALSE);
3735 }
3736
3737
3738 #ifdef MONSTER_HORDES
3739
3740 bool alloc_horde(int y, int x)
3741 {
3742         monster_race *r_ptr = NULL;
3743         int r_idx = 0;
3744         int m_idx;
3745         int attempts = 1000;
3746         int cy = y;
3747         int cx = x;
3748
3749         /* Prepare allocation table */
3750         get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3751
3752         while (--attempts)
3753         {
3754                 /* Pick a monster */
3755                 r_idx = get_mon_num(monster_level);
3756
3757                 /* Handle failure */
3758                 if (!r_idx) return (FALSE);
3759
3760                 r_ptr = &r_info[r_idx];
3761
3762                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3763
3764                 if (r_idx == MON_HAGURE) continue;
3765                 break;
3766         }
3767         if (attempts < 1) return FALSE;
3768
3769         attempts = 1000;
3770
3771         while (--attempts)
3772         {
3773                 /* Attempt to place the monster */
3774                 if (place_monster_aux(0, y, x, r_idx, 0L)) break;
3775         }
3776
3777         if (attempts < 1) return FALSE;
3778
3779         m_idx = cave[y][x].m_idx;
3780
3781         if (m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[m_list[m_idx].r_idx];
3782         summon_kin_type = r_ptr->d_char;
3783
3784         for (attempts = randint1(10) + 5; attempts; attempts--)
3785         {
3786                 scatter(&cy, &cx, y, x, 5, 0);
3787
3788                 (void)summon_specific(m_idx, cy, cx, dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
3789
3790                 y = cy;
3791                 x = cx;
3792         }
3793
3794         return TRUE;
3795 }
3796
3797 #endif /* MONSTER_HORDES */
3798
3799
3800 /*
3801  * Put the Guardian
3802  */
3803 bool alloc_guardian(void)
3804 {
3805         int guardian = d_info[dungeon_type].final_guardian;
3806
3807         if (guardian && (d_info[dungeon_type].maxdepth == dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
3808         {
3809                 int oy;
3810                 int ox;
3811                 int try = 4000;
3812
3813                 /* Find a good position */
3814                 while (try)
3815                 {
3816                         /* Get a random spot */
3817                         oy = randint1(cur_hgt - 4) + 2;
3818                         ox = randint1(cur_wid - 4) + 2;
3819
3820                         /* Is it a good spot ? */
3821                         if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(cave[oy][ox].feat, &r_info[guardian]))
3822                         {
3823                                 /* Place the guardian */
3824                                 if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE;
3825                         }
3826
3827                         /* One less try */
3828                         try--;
3829                 }
3830         }
3831
3832         return FALSE;
3833 }
3834
3835
3836 /*
3837  * Attempt to allocate a random monster in the dungeon.
3838  *
3839  * Place the monster at least "dis" distance from the player.
3840  *
3841  * Use "slp" to choose the initial "sleep" status
3842  *
3843  * Use "monster_level" for the monster level
3844  */
3845 bool alloc_monster(int dis, u32b mode)
3846 {
3847         int                     y = 0, x = 0;
3848         int         attempts_left = 10000;
3849
3850         /* Put the Guardian */
3851         if (alloc_guardian()) return TRUE;
3852
3853         /* Find a legal, distant, unoccupied, space */
3854         while (attempts_left--)
3855         {
3856                 /* Pick a location */
3857                 y = randint0(cur_hgt);
3858                 x = randint0(cur_wid);
3859
3860                 /* Require empty floor grid (was "naked") */
3861                 if (dun_level || (wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].terrain != TERRAIN_MOUNTAIN))
3862                 {
3863                         if (!cave_empty_bold2(y, x)) continue;
3864                 }
3865                 else
3866                 {
3867                         if (!cave_empty_bold2(y, x) && (cave[y][x].feat != FEAT_MOUNTAIN)) continue;
3868                 }
3869
3870                 /* Accept far away grids */
3871                 if (distance(y, x, py, px) > dis) break;
3872         }
3873
3874         if (!attempts_left)
3875         {
3876                 if (cheat_xtra || cheat_hear)
3877                 {
3878 #ifdef JP
3879 msg_print("·Ù¹ð¡ª¿·¤¿¤Ê¥â¥ó¥¹¥¿¡¼¤òÇÛÃ֤Ǥ­¤Þ¤»¤ó¡£¾®¤µ¤¤³¬¤Ç¤¹¤«¡©");
3880 #else
3881                         msg_print("Warning! Could not allocate a new monster. Small level?");
3882 #endif
3883
3884                 }
3885
3886                 return (FALSE);
3887         }
3888
3889
3890 #ifdef MONSTER_HORDES
3891         if (randint1(5000) <= dun_level)
3892         {
3893                 if (alloc_horde(y, x))
3894                 {
3895 #ifdef JP
3896                         if (cheat_hear) msg_format("¥â¥ó¥¹¥¿¡¼¤ÎÂç·²(%c)", summon_kin_type);
3897 #else
3898                         if (cheat_hear) msg_format("Monster horde (%c).", summon_kin_type);
3899 #endif
3900
3901                         return (TRUE);
3902                 }
3903         }
3904         else
3905         {
3906 #endif /* MONSTER_HORDES */
3907
3908                 /* Attempt to place the monster, allow groups */
3909                 if (place_monster(y, x, (mode | PM_ALLOW_GROUP))) return (TRUE);
3910
3911 #ifdef MONSTER_HORDES
3912         }
3913 #endif /* MONSTER_HORDES */
3914
3915         /* Nope */
3916         return (FALSE);
3917 }
3918
3919
3920
3921
3922 /*
3923  * Hack -- help decide if a monster race is "okay" to summon
3924  */
3925 static bool summon_specific_okay(int r_idx)
3926 {
3927         monster_race *r_ptr = &r_info[r_idx];
3928
3929         /* Hack - Only summon dungeon monsters */
3930         if (!monster_dungeon(r_idx)) return (FALSE);
3931
3932         /* Hack -- identify the summoning monster */
3933         if (summon_specific_who > 0)
3934         {
3935                 monster_type *m_ptr = &m_list[summon_specific_who];
3936
3937                 /* Do not summon enemies */
3938
3939                 /* Friendly vs. opposite aligned normal or pet */
3940                 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
3941
3942                 /* Hostile vs. non-hostile */
3943                 if (is_hostile(m_ptr) != summon_specific_hostile) return FALSE;
3944         }
3945         /* Use the player's alignment */
3946         else if (summon_specific_who < 0)
3947         {
3948                 /* Do not summon enemies of the pets */
3949                 if (monster_has_hostile_align(NULL, 10, -10, r_ptr))
3950                 {
3951                         if (!one_in_(ABS(p_ptr->align) / 2 + 1)) return FALSE;
3952                 }
3953         }
3954
3955         /* Hack -- no specific type specified */
3956         if (!summon_specific_type) return (TRUE);
3957
3958         if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7))) return FALSE;
3959
3960         if ((summon_specific_who < 0) &&
3961             ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) &&
3962             monster_has_hostile_align(NULL, 10, -10, r_ptr))
3963                 return FALSE;
3964
3965         if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[dungeon_type].flags1 & DF1_CHAMELEON)) return TRUE;
3966
3967         return (summon_specific_aux(r_idx));
3968 }
3969
3970
3971 /*
3972  * Place a monster (of the specified "type") near the given
3973  * location.  Return TRUE if a monster was actually summoned.
3974  *
3975  * We will attempt to place the monster up to 10 times before giving up.
3976  *
3977  * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
3978  * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
3979  * Note: None of the other summon codes will ever summon Unique's.
3980  *
3981  * This function has been changed.  We now take the "monster level"
3982  * of the summoning monster as a parameter, and use that, along with
3983  * the current dungeon level, to help determine the level of the
3984  * desired monster.  Note that this is an upper bound, and also
3985  * tends to "prefer" monsters of that level.  Currently, we use
3986  * the average of the dungeon and monster levels, and then add
3987  * five to allow slight increases in monster power.
3988  *
3989  * Note that we use the new "monster allocation table" creation code
3990  * to restrict the "get_mon_num()" function to the set of "legal"
3991  * monsters, making this function much faster and more reliable.
3992  *
3993  * Note that this function may not succeed, though this is very rare.
3994  */
3995 bool summon_specific(int who, int y1, int x1, int lev, int type, u32b mode)
3996 {
3997         int x, y, r_idx;
3998
3999         if (p_ptr->inside_arena) return (FALSE);
4000
4001         if (!mon_scatter(&y, &x, y1, x1, 2)) return FALSE;
4002
4003         /* Save the summoner */
4004         summon_specific_who = who;
4005
4006         /* Save the "summon" type */
4007         summon_specific_type = type;
4008
4009         summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
4010
4011         /* Save the hostility */
4012         summon_specific_hostile = (!(mode & PM_FORCE_FRIENDLY) && !(is_friendly_idx(who)) && !(mode & PM_FORCE_PET));
4013
4014         /* Prepare allocation table */
4015         get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
4016
4017         /* Pick a monster, using the level calculation */
4018         r_idx = get_mon_num((dun_level + lev) / 2 + 5);
4019
4020         /* Handle failure */
4021         if (!r_idx)
4022         {
4023                 summon_specific_type = 0;
4024                 return (FALSE);
4025         }
4026
4027         if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
4028
4029         /* Attempt to place the monster (awake, allow groups) */
4030         if (!place_monster_aux(who, y, x, r_idx, mode))
4031         {
4032                 summon_specific_type = 0;
4033                 return (FALSE);
4034         }
4035
4036         summon_specific_type = 0;
4037         /* Success */
4038         return (TRUE);
4039 }
4040
4041 /* A "dangerous" function, creates a pet of the specified type */
4042 bool summon_named_creature (int who, int oy, int ox, int r_idx, u32b mode)
4043 {
4044         int x, y;
4045
4046         /* Paranoia */
4047         /* if (!r_idx) return; */
4048
4049         /* Prevent illegal monsters */
4050         if (r_idx >= max_r_idx) return FALSE;
4051
4052         if (p_ptr->inside_arena) return FALSE;
4053
4054         if (!mon_scatter(&y, &x, oy, ox, 2)) return FALSE;
4055
4056         /* Place it (allow groups) */
4057         return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
4058 }
4059
4060
4061 /*
4062  * Let the given monster attempt to reproduce.
4063  *
4064  * Note that "reproduction" REQUIRES empty space.
4065  */
4066 bool multiply_monster(int m_idx, bool clone, u32b mode)
4067 {
4068         monster_type    *m_ptr = &m_list[m_idx];
4069
4070         int y, x;
4071
4072         if (!mon_scatter(&y, &x, m_ptr->fy, m_ptr->fx, 1))
4073                 return FALSE;
4074
4075         if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
4076
4077         /* Create a new monster (awake, no groups) */
4078         if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE)))
4079                 return FALSE;
4080
4081         if (clone)
4082         {
4083                 m_list[hack_m_idx_ii].smart |= SM_CLONED;
4084                 m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
4085         }
4086
4087         /* Hack -- Shadower spawns Shadower */
4088         if (m_ptr->mflag2 & MFLAG2_KAGE) m_list[hack_m_idx_ii].mflag2 |= MFLAG2_KAGE;
4089
4090         /* Hack -- Appearance transfer */
4091         if (!is_original_ap(m_ptr)) m_list[hack_m_idx_ii].ap_r_idx = m_ptr->ap_r_idx;
4092
4093         return TRUE;
4094 }
4095
4096
4097
4098
4099
4100 /*
4101  * Dump a message describing a monster's reaction to damage
4102  *
4103  * Technically should attempt to treat "Beholder"'s as jelly's
4104  */
4105 void message_pain(int m_idx, int dam)
4106 {
4107         long oldhp, newhp, tmp;
4108         int percentage;
4109
4110         monster_type *m_ptr = &m_list[m_idx];
4111         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4112
4113         char m_name[80];
4114
4115
4116         /* Get the monster name */
4117         monster_desc(m_name, m_ptr, 0);
4118
4119         /* Notice non-damage */
4120         if (dam == 0)
4121         {
4122 #ifdef JP
4123                 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Æ¤¤¤Ê¤¤¡£", m_name);
4124 #else
4125                 msg_format("%^s is unharmed.", m_name);
4126 #endif
4127
4128                 return;
4129         }
4130
4131         /* Note -- subtle fix -CFT */
4132         newhp = (long)(m_ptr->hp);
4133         oldhp = newhp + (long)(dam);
4134         tmp = (newhp * 100L) / oldhp;
4135         percentage = (int)(tmp);
4136
4137
4138         /* Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs */
4139         if (strchr(",ejmvwQ", r_ptr->d_char))
4140         {
4141 #ifdef JP
4142                 if (percentage > 95)
4143                         msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4144                 else if (percentage > 75)
4145                         msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4146                 else if (percentage > 50)
4147                         msg_format("%^s¤Ï½Ì¤³¤Þ¤Ã¤¿¡£", m_name);
4148                 else if (percentage > 35)
4149                         msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4150                 else if (percentage > 20)
4151                         msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4152                 else if (percentage > 10)
4153                         msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4154                 else
4155                         msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4156 #else
4157                 if (percentage > 95)
4158                         msg_format("%^s barely notices.", m_name);
4159                 else if (percentage > 75)
4160                         msg_format("%^s flinches.", m_name);
4161                 else if (percentage > 50)
4162                         msg_format("%^s squelches.", m_name);
4163                 else if (percentage > 35)
4164                         msg_format("%^s quivers in pain.", m_name);
4165                 else if (percentage > 20)
4166                         msg_format("%^s writhes about.", m_name);
4167                 else if (percentage > 10)
4168                         msg_format("%^s writhes in agony.", m_name);
4169                 else
4170                         msg_format("%^s jerks limply.", m_name);
4171 #endif
4172
4173         }
4174
4175
4176         /* Fish */
4177         else if (strchr("l", r_ptr->d_char))
4178         {
4179                 if (percentage > 95)
4180 #ifdef JP
4181 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4182 #else
4183                         msg_format("%^s barely notices.", m_name);
4184 #endif
4185                 else if (percentage > 75)
4186 #ifdef JP
4187 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4188 #else
4189                         msg_format("%^s flinches.", m_name);
4190 #endif
4191                 else if (percentage > 50)
4192 #ifdef JP
4193 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4194 #else
4195                         msg_format("%^s hesitates.", m_name);
4196 #endif
4197                 else if (percentage > 35)
4198 #ifdef JP
4199 msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4200 #else
4201                         msg_format("%^s quivers in pain.", m_name);
4202 #endif
4203                 else if (percentage > 20)
4204 #ifdef JP
4205 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4206 #else
4207                         msg_format("%^s writhes about.", m_name);
4208 #endif
4209                 else if (percentage > 10)
4210 #ifdef JP
4211 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4212 #else
4213                         msg_format("%^s writhes in agony.", m_name);
4214 #endif
4215                 else
4216 #ifdef JP
4217 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4218 #else
4219                         msg_format("%^s jerks limply.", m_name);
4220 #endif
4221         }
4222
4223
4224         /* Golems, Walls, Doors, Stairs */
4225         else if (strchr("g#+<>", r_ptr->d_char))
4226         {
4227                 if (percentage > 95)
4228 #ifdef JP
4229 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4230 #else
4231                         msg_format("%^s ignores the attack.", m_name);
4232 #endif
4233                 else if (percentage > 75)
4234 #ifdef JP
4235 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4236 #else
4237                         msg_format("%^s shrugs off the attack.", m_name);
4238 #endif
4239                 else if (percentage > 50)
4240 #ifdef JP
4241 msg_format("%^s¤ÏÍëÌĤΤ褦¤ËËʤ¨¤¿¡£", m_name);
4242 #else
4243                         msg_format("%^s roars thunderously.", m_name);
4244 #endif
4245                 else if (percentage > 35)
4246 #ifdef JP
4247 msg_format("%^s¤Ï¶ì¤·¤²¤ËËʤ¨¤¿¡£", m_name);
4248 #else
4249                         msg_format("%^s rumbles.", m_name);
4250 #endif
4251                 else if (percentage > 20)
4252 #ifdef JP
4253 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4254 #else
4255                         msg_format("%^s grunts.", m_name);
4256 #endif
4257                 else if (percentage > 10)
4258 #ifdef JP
4259 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4260 #else
4261                         msg_format("%^s hesitates.", m_name);
4262 #endif
4263                 else
4264 #ifdef JP
4265 msg_format("%^s¤Ï¤¯¤·¤ã¤¯¤·¤ã¤Ë¤Ê¤Ã¤¿¡£", m_name);
4266 #else
4267                         msg_format("%^s crumples.", m_name);
4268 #endif
4269         }
4270
4271
4272         /* Snakes, Hydrae, Reptiles, Mimics */
4273         else if (strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char))
4274         {
4275                 if (percentage > 95)
4276 #ifdef JP
4277 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4278 #else
4279                         msg_format("%^s barely notices.", m_name);
4280 #endif
4281                 else if (percentage > 75)
4282 #ifdef JP
4283 msg_format("%^s¤Ï¥·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4284 #else
4285                         msg_format("%^s hisses.", m_name);
4286 #endif
4287                 else if (percentage > 50)
4288 #ifdef JP
4289 msg_format("%^s¤ÏÅܤäÆƬ¤ò¾å¤²¤¿¡£", m_name);
4290 #else
4291                         msg_format("%^s rears up in anger.", m_name);
4292 #endif
4293                 else if (percentage > 35)
4294 #ifdef JP
4295 msg_format("%^s¤ÏÌÔÁ³¤È°Ò³Å¤·¤¿¡£", m_name);
4296 #else
4297                         msg_format("%^s hisses furiously.", m_name);
4298 #endif
4299                 else if (percentage > 20)
4300 #ifdef JP
4301 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4302 #else
4303                         msg_format("%^s writhes about.", m_name);
4304 #endif
4305                 else if (percentage > 10)
4306 #ifdef JP
4307 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4308 #else
4309                         msg_format("%^s writhes in agony.", m_name);
4310 #endif
4311                 else
4312 #ifdef JP
4313 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4314 #else
4315                         msg_format("%^s jerks limply.", m_name);
4316 #endif
4317         }
4318
4319
4320         /* Felines */
4321         else if (strchr("f", r_ptr->d_char))
4322         {
4323                 if (percentage > 95)
4324 #ifdef JP
4325 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4326 #else
4327                         msg_format("%^s shrugs off the attack.", m_name);
4328 #endif
4329                 else if (percentage > 75)
4330 #ifdef JP
4331 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4332 #else
4333                         msg_format("%^s roars.", m_name);
4334 #endif
4335                 else if (percentage > 50)
4336 #ifdef JP
4337 msg_format("%^s¤ÏÅܤäÆËʤ¨¤¿¡£", m_name);
4338 #else
4339                         msg_format("%^s growls angrily.", m_name);
4340 #endif
4341                 else if (percentage > 35)
4342 #ifdef JP
4343 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4344 #else
4345                         msg_format("%^s hisses with pain.", m_name);
4346 #endif
4347                 else if (percentage > 20)
4348 #ifdef JP
4349 msg_format("%^s¤ÏÄˤߤǼ塹¤·¤¯ÌĤ¤¤¿¡£", m_name);
4350 #else
4351                         msg_format("%^s mewls in pain.", m_name);
4352 #endif
4353                 else if (percentage > 10)
4354 #ifdef JP
4355 msg_format("%^s¤Ï¶ìÄˤˤ¦¤á¤¤¤¿¡£", m_name);
4356 #else
4357                         msg_format("%^s hisses in agony.", m_name);
4358 #endif
4359                 else
4360 #ifdef JP
4361 msg_format("%s¤Ï°¥¤ì¤ÊÌĤ­À¼¤ò½Ð¤·¤¿¡£", m_name);
4362 #else
4363                         msg_format("%^s mewls pitifully.", m_name);
4364 #endif
4365         }
4366
4367
4368         /* Ants, Centipedes, Flies, Insects, Beetles, Spiders */
4369         else if (strchr("acFIKS", r_ptr->d_char))
4370         {
4371                 if (percentage > 95)
4372 #ifdef JP
4373 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4374 #else
4375                         msg_format("%^s ignores the attack.", m_name);
4376 #endif
4377                 else if (percentage > 75)
4378 #ifdef JP
4379 msg_format("%^s¤Ï¥­¡¼¥­¡¼ÌĤ¤¤¿¡£", m_name);
4380 #else
4381                         msg_format("%^s chitters.", m_name);
4382 #endif
4383
4384                 else if (percentage > 50)
4385 #ifdef JP
4386 msg_format("%^s¤Ï¥è¥í¥è¥íƨ¤²²ó¤Ã¤¿¡£", m_name);
4387 #else
4388                         msg_format("%^s scuttles about.", m_name);
4389 #endif
4390
4391                 else if (percentage > 35)
4392 #ifdef JP
4393 msg_format("%^s¤Ï¤¦¤ë¤µ¤¯ÌĤ¤¤¿¡£", m_name);
4394 #else
4395                         msg_format("%^s twitters.", m_name);
4396 #endif
4397
4398                 else if (percentage > 20)
4399 #ifdef JP
4400 msg_format("%^s¤ÏÄˤߤËáÛÚ»¤·¤¿¡£", m_name);
4401 #else
4402                         msg_format("%^s jerks in pain.", m_name);
4403 #endif
4404
4405                 else if (percentage > 10)
4406 #ifdef JP
4407 msg_format("%^s¤Ï¶ìÄˤÇáÛÚ»¤·¤¿¡£", m_name);
4408 #else
4409                         msg_format("%^s jerks in agony.", m_name);
4410 #endif
4411
4412                 else
4413 #ifdef JP
4414 msg_format("%^s¤Ï¥Ô¥¯¥Ô¥¯¤Ò¤­¤Ä¤Ã¤¿¡£", m_name);
4415 #else
4416                         msg_format("%^s twitches.", m_name);
4417 #endif
4418
4419         }
4420
4421
4422         /* Birds */
4423         else if (strchr("B", r_ptr->d_char))
4424         {
4425                 if (percentage > 95)
4426 #ifdef JP
4427 msg_format("%^s¤Ï¤µ¤¨¤º¤Ã¤¿¡£", m_name);
4428 #else
4429                         msg_format("%^s chirps.", m_name);
4430 #endif
4431
4432                 else if (percentage > 75)
4433 #ifdef JP
4434 msg_format("%^s¤Ï¥Ô¡¼¥Ô¡¼ÌĤ¤¤¿¡£", m_name);
4435 #else
4436                         msg_format("%^s twitters.", m_name);
4437 #endif
4438
4439                 else if (percentage > 50)
4440 #ifdef JP
4441 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ¤¤¿¡£", m_name);
4442 #else
4443                         msg_format("%^s squawks.", m_name);
4444 #endif
4445
4446                 else if (percentage > 35)
4447 #ifdef JP
4448 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ­¤ï¤á¤¤¤¿¡£", m_name);
4449 #else
4450                         msg_format("%^s chatters.", m_name);
4451 #endif
4452
4453                 else if (percentage > 20)
4454 #ifdef JP
4455 msg_format("%^s¤Ï¶ì¤·¤ó¤À¡£", m_name);
4456 #else
4457                         msg_format("%^s jeers.", m_name);
4458 #endif
4459
4460                 else if (percentage > 10)
4461 #ifdef JP
4462 msg_format("%^s¤Ï¤Î¤¿¤¦¤Á²ó¤Ã¤¿¡£", m_name);
4463 #else
4464                         msg_format("%^s flutters about.", m_name);
4465 #endif
4466
4467                 else
4468 #ifdef JP
4469 msg_format("%^s¤Ï¥­¡¼¥­¡¼¤ÈÌĤ­¶«¤ó¤À¡£", m_name);
4470 #else
4471                         msg_format("%^s squeaks.", m_name);
4472 #endif
4473
4474         }
4475
4476
4477         /* Dragons, Demons, High Undead */
4478         else if (strchr("duDLUW", r_ptr->d_char))
4479         {
4480                 if (percentage > 95)
4481 #ifdef JP
4482 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4483 #else
4484                         msg_format("%^s ignores the attack.", m_name);
4485 #endif
4486
4487                 else if (percentage > 75)
4488 #ifdef JP
4489 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4490 #else
4491                         msg_format("%^s flinches.", m_name);
4492 #endif
4493
4494                 else if (percentage > 50)
4495 #ifdef JP
4496 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4497 #else
4498                         msg_format("%^s hisses in pain.", m_name);
4499 #endif
4500
4501                 else if (percentage > 35)
4502 #ifdef JP
4503 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4504 #else
4505                         msg_format("%^s snarls with pain.", m_name);
4506 #endif
4507
4508                 else if (percentage > 20)
4509 #ifdef JP
4510 msg_format("%^s¤ÏÄˤߤËËʤ¨¤¿¡£", m_name);
4511 #else
4512                         msg_format("%^s roars with pain.", m_name);
4513 #endif
4514
4515                 else if (percentage > 10)
4516 #ifdef JP
4517 msg_format("%^s¤Ï¶ì¤·¤²¤Ë¶«¤ó¤À¡£", m_name);
4518 #else
4519                         msg_format("%^s gasps.", m_name);
4520 #endif
4521
4522                 else
4523 #ifdef JP
4524 msg_format("%^s¤Ï¼å¡¹¤·¤¯¤¦¤Ê¤Ã¤¿¡£", m_name);
4525 #else
4526                         msg_format("%^s snarls feebly.", m_name);
4527 #endif
4528
4529         }
4530
4531
4532         /* Skeletons */
4533         else if (strchr("s", r_ptr->d_char))
4534         {
4535                 if (percentage > 95)
4536 #ifdef JP
4537 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4538 #else
4539                         msg_format("%^s ignores the attack.", m_name);
4540 #endif
4541
4542                 else if (percentage > 75)
4543 #ifdef JP
4544 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4545 #else
4546                         msg_format("%^s shrugs off the attack.", m_name);
4547 #endif
4548
4549                 else if (percentage > 50)
4550 #ifdef JP
4551 msg_format("%^s¤Ï¥«¥¿¥«¥¿¤È¾Ð¤Ã¤¿¡£", m_name);
4552 #else
4553                         msg_format("%^s rattles.", m_name);
4554 #endif
4555
4556                 else if (percentage > 35)
4557 #ifdef JP
4558 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4559 #else
4560                         msg_format("%^s stumbles.", m_name);
4561 #endif
4562
4563                 else if (percentage > 20)
4564 #ifdef JP
4565 msg_format("%^s¤Ï¥«¥¿¥«¥¿¸À¤Ã¤¿¡£", m_name);
4566 #else
4567                         msg_format("%^s rattles.", m_name);
4568 #endif
4569
4570                 else if (percentage > 10)
4571 #ifdef JP
4572 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4573 #else
4574                         msg_format("%^s staggers.", m_name);
4575 #endif
4576
4577                 else
4578 #ifdef JP
4579 msg_format("%^s¤Ï¥¬¥¿¥¬¥¿¸À¤Ã¤¿¡£", m_name);
4580 #else
4581                         msg_format("%^s clatters.", m_name);
4582 #endif
4583
4584         }
4585
4586
4587         /* Zombies */
4588         else if (strchr("z", r_ptr->d_char))
4589         {
4590                 if (percentage > 95)
4591 #ifdef JP
4592 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4593 #else
4594                         msg_format("%^s ignores the attack.", m_name);
4595 #endif
4596
4597                 else if (percentage > 75)
4598 #ifdef JP
4599 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4600 #else
4601                         msg_format("%^s shrugs off the attack.", m_name);
4602 #endif
4603
4604                 else if (percentage > 50)
4605 #ifdef JP
4606 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4607 #else
4608                         msg_format("%^s groans.", m_name);
4609 #endif
4610
4611                 else if (percentage > 35)
4612 #ifdef JP
4613 msg_format("%s¤Ï¶ì¤·¤²¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4614 #else
4615                         msg_format("%^s moans.", m_name);
4616 #endif
4617
4618                 else if (percentage > 20)
4619 #ifdef JP
4620 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4621 #else
4622                         msg_format("%^s hesitates.", m_name);
4623 #endif
4624
4625                 else if (percentage > 10)
4626 #ifdef JP
4627 msg_format("%^s¤Ï¤¦¤Ê¤Ã¤¿¡£", m_name);
4628 #else
4629                         msg_format("%^s grunts.", m_name);
4630 #endif
4631
4632                 else
4633 #ifdef JP
4634 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4635 #else
4636                         msg_format("%^s staggers.", m_name);
4637 #endif
4638
4639         }
4640
4641
4642         /* Ghosts */
4643         else if (strchr("G", r_ptr->d_char))
4644
4645         {
4646                 if (percentage > 95)
4647 #ifdef JP
4648 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4649 #else
4650                         msg_format("%^s ignores the attack.", m_name);
4651 #endif
4652
4653                 else if (percentage > 75)
4654 #ifdef JP
4655 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4656 #else
4657                         msg_format("%^s shrugs off the attack.", m_name);
4658 #endif
4659
4660                 else if (percentage > 50)
4661 #ifdef JP
4662 msg_format("%s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4663 #else
4664                         msg_format("%^s moans.", m_name);
4665 #endif
4666
4667                 else if (percentage > 35)
4668 #ifdef JP
4669 msg_format("%^s¤Ïµã¤­¤ï¤á¤¤¤¿¡£", m_name);
4670 #else
4671                         msg_format("%^s wails.", m_name);
4672 #endif
4673
4674                 else if (percentage > 20)
4675 #ifdef JP
4676 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4677 #else
4678                         msg_format("%^s howls.", m_name);
4679 #endif
4680
4681                 else if (percentage > 10)
4682 #ifdef JP
4683 msg_format("%s¤Ï¼å¡¹¤·¤¯¤¦¤á¤¤¤¿¡£", m_name);
4684 #else
4685                         msg_format("%^s moans softly.", m_name);
4686 #endif
4687
4688                 else
4689 #ifdef JP
4690 msg_format("%^s¤Ï¤«¤¹¤«¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4691 #else
4692                         msg_format("%^s sighs.", m_name);
4693 #endif
4694
4695         }
4696
4697
4698         /* Dogs and Hounds */
4699         else if (strchr("CZ", r_ptr->d_char))
4700         {
4701 #ifdef JP
4702                 if (percentage > 95)
4703                         msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4704                 else if (percentage > 75)
4705                         msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4706                 else if (percentage > 50)
4707                         msg_format("%^s¤ÏÄˤߤǥ­¥ã¥ó¥­¥ã¥óËʤ¨¤¿¡£", m_name);
4708                 else if (percentage > 35)
4709                         msg_format("%^s¤ÏÄˤߤÇÌĤ­¤ï¤á¤¤¤¿¡£", m_name);
4710                 else if (percentage > 20)
4711                         msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÌĤ­¤ï¤á¤¤¤¿¡£", m_name);
4712                 else if (percentage > 10)
4713                         msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4714                 else
4715                         msg_format("%^s¤Ï¼å¡¹¤·¤¯Ëʤ¨¤¿¡£", m_name);
4716 #else
4717                 if (percentage > 95)
4718                         msg_format("%^s shrugs off the attack.", m_name);
4719                 else if (percentage > 75)
4720                         msg_format("%^s snarls with pain.", m_name);
4721                 else if (percentage > 50)
4722                         msg_format("%^s yelps in pain.", m_name);
4723                 else if (percentage > 35)
4724                         msg_format("%^s howls in pain.", m_name);
4725                 else if (percentage > 20)
4726                         msg_format("%^s howls in agony.", m_name);
4727                 else if (percentage > 10)
4728                         msg_format("%^s writhes in agony.", m_name);
4729                 else
4730                         msg_format("%^s yelps feebly.", m_name);
4731 #endif
4732
4733         }
4734
4735         /* One type of monsters (ignore,squeal,shriek) */
4736         else if (strchr("Xbilqrt", r_ptr->d_char))
4737         {
4738 #ifdef JP
4739                 if (percentage > 95)
4740                         msg_format("%^s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4741                 else if (percentage > 75)
4742                         msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4743                 else if (percentage > 50)
4744                         msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4745                 else if (percentage > 35)
4746                         msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4747                 else if (percentage > 20)
4748                         msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4749                 else if (percentage > 10)
4750                         msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4751                 else
4752                         msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4753 #else
4754                 if (percentage > 95)
4755                         msg_format("%^s ignores the attack.", m_name);
4756                 else if (percentage > 75)
4757                         msg_format("%^s grunts with pain.", m_name);
4758                 else if (percentage > 50)
4759                         msg_format("%^s squeals in pain.", m_name);
4760                 else if (percentage > 35)
4761                         msg_format("%^s shrieks in pain.", m_name);
4762                 else if (percentage > 20)
4763                         msg_format("%^s shrieks in agony.", m_name);
4764                 else if (percentage > 10)
4765                         msg_format("%^s writhes in agony.", m_name);
4766                 else
4767                         msg_format("%^s cries out feebly.", m_name);
4768 #endif
4769
4770         }
4771
4772         /* Another type of monsters (shrug,cry,scream) */
4773         else
4774         {
4775 #ifdef JP
4776                 if (percentage > 95)
4777                         msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4778                 else if (percentage > 75)
4779                         msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4780                 else if (percentage > 50)
4781                         msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4782                 else if (percentage > 35)
4783                         msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4784                 else if (percentage > 20)
4785                         msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4786                 else if (percentage > 10)
4787                         msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4788                 else
4789                         msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4790 #else
4791                 if (percentage > 95)
4792                         msg_format("%^s shrugs off the attack.", m_name);
4793                 else if (percentage > 75)
4794                         msg_format("%^s grunts with pain.", m_name);
4795                 else if (percentage > 50)
4796                         msg_format("%^s cries out in pain.", m_name);
4797                 else if (percentage > 35)
4798                         msg_format("%^s screams in pain.", m_name);
4799                 else if (percentage > 20)
4800                         msg_format("%^s screams in agony.", m_name);
4801                 else if (percentage > 10)
4802                         msg_format("%^s writhes in agony.", m_name);
4803                 else
4804                         msg_format("%^s cries out feebly.", m_name);
4805 #endif
4806
4807         }
4808 }
4809
4810
4811 /*
4812  * Learn about an "observed" resistance.
4813  */
4814 void update_smart_learn(int m_idx, int what)
4815 {
4816 #ifdef DRS_SMART_OPTIONS
4817
4818         monster_type *m_ptr = &m_list[m_idx];
4819
4820         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4821
4822
4823         /* Not allowed to learn */
4824         if (!smart_learn) return;
4825
4826         /* Too stupid to learn anything */
4827         if (r_ptr->flags2 & (RF2_STUPID)) return;
4828
4829         /* Not intelligent, only learn sometimes */
4830         if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
4831
4832
4833         /* XXX XXX XXX */
4834
4835         /* Analyze the knowledge */
4836         switch (what)
4837         {
4838         case DRS_ACID:
4839                 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
4840                 if (IS_OPPOSE_ACID()) m_ptr->smart |= (SM_OPP_ACID);
4841                 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
4842                 break;
4843
4844         case DRS_ELEC:
4845                 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
4846                 if (IS_OPPOSE_ELEC()) m_ptr->smart |= (SM_OPP_ELEC);
4847                 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
4848                 break;
4849
4850         case DRS_FIRE:
4851                 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
4852                 if (IS_OPPOSE_FIRE()) m_ptr->smart |= (SM_OPP_FIRE);
4853                 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
4854                 break;
4855
4856         case DRS_COLD:
4857                 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
4858                 if (IS_OPPOSE_COLD()) m_ptr->smart |= (SM_OPP_COLD);
4859                 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
4860                 break;
4861
4862         case DRS_POIS:
4863                 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
4864                 if (IS_OPPOSE_POIS()) m_ptr->smart |= (SM_OPP_POIS);
4865                 break;
4866
4867
4868         case DRS_NETH:
4869                 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
4870                 break;
4871
4872         case DRS_LITE:
4873                 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
4874                 break;
4875
4876         case DRS_DARK:
4877                 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
4878                 break;
4879
4880         case DRS_FEAR:
4881                 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
4882                 break;
4883
4884         case DRS_CONF:
4885                 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
4886                 break;
4887
4888         case DRS_CHAOS:
4889                 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
4890                 break;
4891
4892         case DRS_DISEN:
4893                 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
4894                 break;
4895
4896         case DRS_BLIND:
4897                 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
4898                 break;
4899
4900         case DRS_NEXUS:
4901                 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
4902                 break;
4903
4904         case DRS_SOUND:
4905                 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
4906                 break;
4907
4908         case DRS_SHARD:
4909                 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
4910                 break;
4911
4912         case DRS_FREE:
4913                 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
4914                 break;
4915
4916         case DRS_MANA:
4917                 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
4918                 break;
4919
4920         case DRS_REFLECT:
4921                 if (p_ptr->reflect) m_ptr-> smart |= (SM_IMM_REFLECT);
4922                 break;
4923         }
4924
4925 #endif /* DRS_SMART_OPTIONS */
4926
4927 }
4928
4929
4930 /*
4931  * Place the player in the dungeon XXX XXX
4932  */
4933 bool player_place(int y, int x)
4934 {
4935         /* Paranoia XXX XXX */
4936         if (cave[y][x].m_idx != 0) return FALSE;
4937
4938         /* Save player location */
4939         py = y;
4940         px = x;
4941
4942         /* Success */
4943         return TRUE;
4944 }
4945
4946
4947 /*
4948  * Drop all items carried by a monster
4949  */
4950 void monster_drop_carried_objects(monster_type *m_ptr)
4951 {
4952         s16b this_o_idx, next_o_idx = 0;
4953         object_type forge;
4954         object_type *o_ptr;
4955         object_type *q_ptr;
4956
4957
4958         /* Drop objects being carried */
4959         for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4960         {
4961                 /* Acquire object */
4962                 o_ptr = &o_list[this_o_idx];
4963
4964                 /* Acquire next object */
4965                 next_o_idx = o_ptr->next_o_idx;
4966
4967                 /* Get local object */
4968                 q_ptr = &forge;
4969
4970                 /* Copy the object */
4971                 object_copy(q_ptr, o_ptr);
4972
4973                 /* Forget monster */
4974                 q_ptr->held_m_idx = 0;
4975
4976                 /* Delete the object */
4977                 delete_object_idx(this_o_idx);
4978
4979                 /* Drop it */
4980                 (void)drop_near(q_ptr, -1, m_ptr->fy, m_ptr->fx);
4981         }
4982
4983         /* Forget objects */
4984         m_ptr->hold_o_idx = 0;
4985 }