OSDN Git Service

モンスターの状態変化処理を標準ターンで行う際に, 処理の必要のある状態
[hengband/hengband.git] / src / monster2.c
1 /* File: monster2.c */
2
3 /*
4  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
5  *
6  * This software may be copied and distributed for educational, research,
7  * and not for profit purposes provided that this copyright and statement
8  * are included in all such copies.  Other copyrights may also apply.
9  */
10
11 /* Purpose: misc code for monsters */
12
13 #include "angband.h"
14
15 #define HORDE_NOGOOD 0x01
16 #define HORDE_NOEVIL 0x02
17
18 cptr horror_desc[MAX_SAN_HORROR] =
19 {
20 #ifdef JP
21         "´÷¤Þ¤ï¤·¤¤",
22         "ÄìÃΤì¤Ì",
23         "¤¾¤Ã¤È¤¹¤ë",
24         "ÇËÌÇŪ¤Ê",
25         "ËÁÆÂŪ¤Ê",
26
27         "¤¤¤ä¤Ê",
28         "¶²¤í¤·¤¤",
29         "ÉÔ·é¤Ê",
30         "ÍƼϤΤʤ¤",
31         "¤ª¤¾¤Þ¤·¤¤",
32
33         "ÃϹö¤Î",
34         "¿È¤ÎÌÓ¤â¤è¤À¤Ä",
35         "ÃϹö¤Î",
36         "´÷¤Þ¤ï¤·¤¤",
37         "°­Ì´¤Î¤è¤¦¤Ê",
38
39         "·ù°­¤ò´¶¤¸¤ë",
40         "ȳÅö¤¿¤ê¤Ê",
41         "¶²¤¤",
42         "ÉÔ¾ô¤Ê",
43         "¸À¤¦¤â¤ª¤¾¤Þ¤·¤¤",
44 #else
45         "abominable",
46         "abysmal",
47         "appalling",
48         "baleful",
49         "blasphemous",
50
51         "disgusting",
52         "dreadful",
53         "filthy",
54         "grisly",
55         "hideous",
56
57         "hellish",
58         "horrible",
59         "infernal",
60         "loathsome",
61         "nightmarish",
62
63         "repulsive",
64         "sacrilegious",
65         "terrible",
66         "unclean",
67         "unspeakable",
68 #endif
69
70 };
71
72 cptr funny_desc[MAX_SAN_FUNNY] =
73 {
74 #ifdef JP
75         "´ÖÈ´¤±¤Ê",
76         "³ê·Î¤Ê",
77         "¤Ð¤«¤é¤·¤¤",
78         "̵̣´¥Áç¤Ê",
79         "Çϼ¯¤²¤¿",
80
81         "¾Ð¤¨¤ë",
82         "¤Ð¤«¤Ð¤«¤·¤¤",
83         "¤Ö¤Ã¤È¤ó¤À",
84         "¤¤¤«¤·¤¿",
85         "¥Ý¥¹¥È¥â¥À¥ó¤Ê",
86
87         "¥Õ¥¡¥ó¥¿¥¹¥Æ¥£¥Ã¥¯¤Ê",
88         "¥À¥À¥¤¥º¥àŪ¤Ê",
89         "¥­¥å¥Ó¥º¥àŪ¤Ê",
90         "±§ÃèŪ¤Ê",
91         "Âî±Û¤·¤¿",
92
93         "Íý²òÉÔǽ¤Ê",
94         "¤â¤Î¤¹¤´¤¤",
95         "¶Ã¤¯¤Ù¤­",
96         "¿®¤¸¤é¤ì¤Ê¤¤",
97         "¥«¥ª¥Æ¥£¥Ã¥¯¤Ê",
98
99         "ÌîÀ­Åª¤Ê",
100         "Èó¾ï¼±¤Ê",
101 #else
102         "silly",
103         "hilarious",
104         "absurd",
105         "insipid",
106         "ridiculous",
107
108         "laughable",
109         "ludicrous",
110         "far-out",
111         "groovy",
112         "postmodern",
113
114         "fantastic",
115         "dadaistic",
116         "cubistic",
117         "cosmic",
118         "awesome",
119
120         "incomprehensible",
121         "fabulous",
122         "amazing",
123         "incredible",
124         "chaotic",
125
126         "wild",
127         "preposterous",
128 #endif
129
130 };
131
132 cptr funny_comments[MAX_SAN_COMMENT] =
133 {
134 #ifdef JP
135   /* nuke me */
136         "ºÇ¹â¤À¤¼¡ª",
137         "¤¦¤Ò¤ç¡¼¡ª",
138         "¤¤¤«¤¹¤¼¡ª",
139         "¤¹¤ó¤Ð¤é¤·¤¤¡ª",
140         "¤Ö¤Ã¤È¤Ó¡¼¡ª"
141 #else
142         "Wow, cosmic, man!",
143         "Rad!",
144         "Groovy!",
145         "Cool!",
146         "Far out!"
147 #endif
148
149 };
150
151
152 /*
153  * Set the target of counter attack
154  */
155 void set_target(monster_type *m_ptr, int y, int x)
156 {
157         m_ptr->target_y = y;
158         m_ptr->target_x = x;
159 }
160
161
162 /*
163  * Reset the target of counter attack
164  */
165 void reset_target(monster_type *m_ptr)
166 {
167         set_target(m_ptr, 0, 0);
168 }
169
170
171 /*
172  *  Extract monster race pointer of a monster's true form
173  */
174 monster_race *real_r_ptr(monster_type *m_ptr)
175 {
176         monster_race *r_ptr = &r_info[m_ptr->r_idx];
177
178         /* Extract real race */
179         if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
180         {
181                 if (r_ptr->flags1 & RF1_UNIQUE)
182                         return &r_info[MON_CHAMELEON_K];
183                 else
184                         return &r_info[MON_CHAMELEON];
185         }
186         else
187         {
188                 return r_ptr;
189         }
190 }
191
192
193 void mproc_add(int m_idx)
194 {
195         m_list[m_idx].mproc_idx = mproc_max;
196         mproc_list[mproc_max++] = m_idx;
197 }
198
199
200 void mproc_remove(int mproc_idx)
201 {
202         m_list[mproc_list[mproc_idx]].mproc_idx = 0;
203         mproc_list[mproc_idx] = mproc_list[--mproc_max];
204 }
205
206
207 /*
208  * Delete a monster by index.
209  *
210  * When a monster is deleted, all of its objects are deleted.
211  */
212 void delete_monster_idx(int i)
213 {
214         int x, y;
215
216         monster_type *m_ptr = &m_list[i];
217
218         monster_race *r_ptr = &r_info[m_ptr->r_idx];
219
220         s16b this_o_idx, next_o_idx = 0;
221
222
223         /* Get location */
224         y = m_ptr->fy;
225         x = m_ptr->fx;
226
227
228         /* Hack -- Reduce the racial counter */
229         real_r_ptr(m_ptr)->cur_num--;
230
231         /* Hack -- count the number of "reproducers" */
232         if (r_ptr->flags2 & (RF2_MULTIPLY)) num_repro--;
233
234         if (m_ptr->mproc_idx) mproc_remove(m_ptr->mproc_idx);
235
236
237         /* Hack -- remove target monster */
238         if (i == target_who) target_who = 0;
239
240         /* Hack -- remove tracked monster */
241         if (i == p_ptr->health_who) health_track(0);
242
243         if (pet_t_m_idx == i ) pet_t_m_idx = 0;
244         if (riding_t_m_idx == i) riding_t_m_idx = 0;
245         if (p_ptr->riding == i) p_ptr->riding = 0;
246
247         /* Monster is gone */
248         cave[y][x].m_idx = 0;
249
250
251         /* Delete objects */
252         for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
253         {
254                 object_type *o_ptr;
255
256                 /* Acquire object */
257                 o_ptr = &o_list[this_o_idx];
258
259                 /* Acquire next object */
260                 next_o_idx = o_ptr->next_o_idx;
261
262                 /*
263                  * o_ptr->held_m_idx is needed in delete_object_idx()
264                  * to prevent calling lite_spot()
265                  */
266
267                 /* Delete the object */
268                 delete_object_idx(this_o_idx);
269         }
270
271
272         /* Wipe the Monster */
273         (void)WIPE(m_ptr, monster_type);
274
275         /* Count monsters */
276         m_cnt--;
277
278         /* Visual update */
279         lite_spot(y, x);
280
281         /* Update some things */
282         if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
283                 p_ptr->update |= (PU_MON_LITE);
284 }
285
286
287 /*
288  * Delete the monster, if any, at a given location
289  */
290 void delete_monster(int y, int x)
291 {
292         cave_type *c_ptr;
293
294         /* Paranoia */
295         if (!in_bounds(y, x)) return;
296
297         /* Check the grid */
298         c_ptr = &cave[y][x];
299
300         /* Delete the monster (if any) */
301         if (c_ptr->m_idx) delete_monster_idx(c_ptr->m_idx);
302 }
303
304
305 /*
306  * Move an object from index i1 to index i2 in the object list
307  */
308 static void compact_monsters_aux(int i1, int i2)
309 {
310         int y, x, i;
311
312         cave_type *c_ptr;
313
314         monster_type *m_ptr;
315
316         s16b this_o_idx, next_o_idx = 0;
317
318
319         /* Do nothing */
320         if (i1 == i2) return;
321
322
323         /* Old monster */
324         m_ptr = &m_list[i1];
325
326         /* Location */
327         y = m_ptr->fy;
328         x = m_ptr->fx;
329
330         /* Cave grid */
331         c_ptr = &cave[y][x];
332
333         /* Update the cave */
334         c_ptr->m_idx = i2;
335
336         /* Repair objects being carried by monster */
337         for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
338         {
339                 object_type *o_ptr;
340
341                 /* Acquire object */
342                 o_ptr = &o_list[this_o_idx];
343
344                 /* Acquire next object */
345                 next_o_idx = o_ptr->next_o_idx;
346
347                 /* Reset monster pointer */
348                 o_ptr->held_m_idx = i2;
349         }
350
351         /* Hack -- Update the target */
352         if (target_who == i1) target_who = i2;
353
354         /* Hack -- Update the target */
355         if (pet_t_m_idx == i1) pet_t_m_idx = i2;
356         if (riding_t_m_idx == i1) riding_t_m_idx = i2;
357
358         /* Hack -- Update the riding */
359         if (p_ptr->riding == i1) p_ptr->riding = i2;
360
361         /* Hack -- Update the health bar */
362         if (p_ptr->health_who == i1) health_track(i2);
363
364         /* Hack -- Update parent index */
365         if (is_pet(m_ptr))
366         {
367                 for (i = 1; i < m_max; i++)
368                 {
369                         monster_type *m2_ptr = &m_list[i];
370
371                         if (m2_ptr->parent_m_idx == i1)
372                                 m2_ptr->parent_m_idx = i2;
373                 }
374         }
375
376         /* Structure copy */
377         COPY(&m_list[i2], &m_list[i1], monster_type);
378
379         /* Wipe the hole */
380         (void)WIPE(&m_list[i1], monster_type);
381
382         if (m_list[i2].mproc_idx) mproc_list[m_list[i2].mproc_idx] = i2;
383 }
384
385
386 /*
387  * Compact and Reorder the monster list
388  *
389  * This function can be very dangerous, use with caution!
390  *
391  * When actually "compacting" monsters, we base the saving throw
392  * on a combination of monster level, distance from player, and
393  * current "desperation".
394  *
395  * After "compacting" (if needed), we "reorder" the monsters into a more
396  * compact order, and we reset the allocation info, and the "live" array.
397  */
398 void compact_monsters(int size)
399 {
400         int             i, num, cnt;
401         int             cur_lev, cur_dis, chance;
402
403         /* Message (only if compacting) */
404 #ifdef JP
405         if (size) msg_print("¥â¥ó¥¹¥¿¡¼¾ðÊó¤ò°µ½Ì¤·¤Æ¤¤¤Þ¤¹...");
406 #else
407         if (size) msg_print("Compacting monsters...");
408 #endif
409
410
411         /* Compact at least 'size' objects */
412         for (num = 0, cnt = 1; num < size; cnt++)
413         {
414                 /* Get more vicious each iteration */
415                 cur_lev = 5 * cnt;
416
417                 /* Get closer each iteration */
418                 cur_dis = 5 * (20 - cnt);
419
420                 /* Check all the monsters */
421                 for (i = 1; i < m_max; i++)
422                 {
423                         monster_type *m_ptr = &m_list[i];
424
425                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
426
427                         /* Paranoia -- skip "dead" monsters */
428                         if (!m_ptr->r_idx) continue;
429
430                         /* Hack -- High level monsters start out "immune" */
431                         if (r_ptr->level > cur_lev) continue;
432
433                         if (i == p_ptr->riding) continue;
434
435                         /* Ignore nearby monsters */
436                         if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
437
438                         /* Saving throw chance */
439                         chance = 90;
440
441                         /* Only compact "Quest" Monsters in emergencies */
442                         if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
443
444                         /* Try not to compact Unique Monsters */
445                         if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
446
447                         /* All monsters get a saving throw */
448                         if (randint0(100) < chance) continue;
449
450                         /* Delete the monster */
451                         delete_monster_idx(i);
452
453                         /* Count the monster */
454                         num++;
455                 }
456         }
457
458
459         /* Excise dead monsters (backwards!) */
460         for (i = m_max - 1; i >= 1; i--)
461         {
462                 /* Get the i'th monster */
463                 monster_type *m_ptr = &m_list[i];
464
465                 /* Skip real monsters */
466                 if (m_ptr->r_idx) continue;
467
468                 /* Move last monster into open hole */
469                 compact_monsters_aux(m_max - 1, i);
470
471                 /* Compress "m_max" */
472                 m_max--;
473         }
474 }
475
476
477 /*
478  * Delete/Remove all the monsters when the player leaves the level
479  *
480  * This is an efficient method of simulating multiple calls to the
481  * "delete_monster()" function, with no visual effects.
482  */
483 void wipe_m_list(void)
484 {
485         int i;
486
487         /* Hack -- if Banor or Lupart dies, stay another dead */
488         if (!r_info[MON_BANORLUPART].max_num)
489         {
490                 if (r_info[MON_BANOR].max_num)
491                 {
492                         r_info[MON_BANOR].max_num = 0;
493                         r_info[MON_BANOR].r_pkills++;
494                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
495                 }
496                 if (r_info[MON_LUPART].max_num)
497                 {
498                         r_info[MON_LUPART].max_num = 0;
499                         r_info[MON_LUPART].r_pkills++;
500                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
501                 }
502         }
503
504         /* Delete all the monsters */
505         for (i = m_max - 1; i >= 1; i--)
506         {
507                 monster_type *m_ptr = &m_list[i];
508
509                 /* Skip dead monsters */
510                 if (!m_ptr->r_idx) continue;
511
512                 /* Monster is gone */
513                 cave[m_ptr->fy][m_ptr->fx].m_idx = 0;
514
515                 /* Wipe the Monster */
516                 (void)WIPE(m_ptr, monster_type);
517
518         }
519
520         /*
521          * Wiping racial counters of all monsters and incrementing of racial
522          * counters of monsters in party_mon[] are required to prevent multiple
523          * generation of unique monster who is the minion of player.
524          */
525
526         /* Hack -- Wipe the racial counter of all monster races */
527         for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
528
529         /* Reset "m_max" */
530         m_max = 1;
531
532         /* Reset "m_cnt" */
533         m_cnt = 0;
534
535         /* Reset "mproc_max" */
536         mproc_max = 1;
537
538         /* Hack -- reset "reproducer" count */
539         num_repro = 0;
540
541         /* Hack -- no more target */
542         target_who = 0;
543         pet_t_m_idx = 0;
544         riding_t_m_idx = 0;
545
546         /* Hack -- no more tracking */
547         health_track(0);
548 }
549
550
551 /*
552  * Acquires and returns the index of a "free" monster.
553  *
554  * This routine should almost never fail, but it *can* happen.
555  */
556 s16b m_pop(void)
557 {
558         int i;
559
560
561         /* Normal allocation */
562         if (m_max < max_m_idx)
563         {
564                 /* Access the next hole */
565                 i = m_max;
566
567                 /* Expand the array */
568                 m_max++;
569
570                 /* Count monsters */
571                 m_cnt++;
572
573                 /* Return the index */
574                 return (i);
575         }
576
577
578         /* Recycle dead monsters */
579         for (i = 1; i < m_max; i++)
580         {
581                 monster_type *m_ptr;
582
583                 /* Acquire monster */
584                 m_ptr = &m_list[i];
585
586                 /* Skip live monsters */
587                 if (m_ptr->r_idx) continue;
588
589                 /* Count monsters */
590                 m_cnt++;
591
592                 /* Use this monster */
593                 return (i);
594         }
595
596
597         /* Warn the player (except during dungeon creation) */
598 #ifdef JP
599         if (character_dungeon) msg_print("¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë¡ª");
600 #else
601         if (character_dungeon) msg_print("Too many monsters!");
602 #endif
603
604
605         /* Try not to crash */
606         return (0);
607 }
608
609
610
611
612 /*
613  * Hack -- the "type" of the current "summon specific"
614  */
615 static int summon_specific_type = 0;
616
617
618 /*
619  * Hack -- the index of the summoning monster
620  */
621 static int summon_specific_who = -1;
622
623
624 static bool summon_unique_okay = FALSE;
625
626
627 static bool summon_specific_aux(int r_idx)
628 {
629         monster_race *r_ptr = &r_info[r_idx];
630         int okay = FALSE;
631
632         /* Check our requirements */
633         switch (summon_specific_type)
634         {
635                 case SUMMON_ANT:
636                 {
637                         okay = (r_ptr->d_char == 'a');
638                         break;
639                 }
640
641                 case SUMMON_SPIDER:
642                 {
643                         okay = (r_ptr->d_char == 'S');
644                         break;
645                 }
646
647                 case SUMMON_HOUND:
648                 {
649                         okay = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z'));
650                         break;
651                 }
652
653                 case SUMMON_HYDRA:
654                 {
655                         okay = (r_ptr->d_char == 'M');
656                         break;
657                 }
658
659                 case SUMMON_ANGEL:
660                 {
661                         okay = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD)));
662                         break;
663                 }
664
665                 case SUMMON_DEMON:
666                 {
667                         okay = (r_ptr->flags3 & RF3_DEMON);
668                         break;
669                 }
670
671                 case SUMMON_UNDEAD:
672                 {
673                         okay = (r_ptr->flags3 & RF3_UNDEAD);
674                         break;
675                 }
676
677                 case SUMMON_DRAGON:
678                 {
679                         okay = (r_ptr->flags3 & RF3_DRAGON);
680                         break;
681                 }
682
683                 case SUMMON_HI_UNDEAD:
684                 {
685                         okay = ((r_ptr->d_char == 'L') ||
686                                 (r_ptr->d_char == 'V') ||
687                                 (r_ptr->d_char == 'W'));
688                         break;
689                 }
690
691                 case SUMMON_HI_DRAGON:
692                 {
693                         okay = (r_ptr->d_char == 'D');
694                         break;
695                 }
696
697                 case SUMMON_HI_DEMON:
698                 {
699                         okay = (((r_ptr->d_char == 'U') ||
700                                  (r_ptr->d_char == 'H') ||
701                                  (r_ptr->d_char == 'B')) &&
702                                 (r_ptr->flags3 & RF3_DEMON)) ? TRUE : FALSE;
703                         break;
704                 }
705
706                 case SUMMON_AMBERITES:
707                 {
708                         okay = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE;
709                         break;
710                 }
711
712                 case SUMMON_UNIQUE:
713                 {
714                         okay = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE;
715                         break;
716                 }
717
718                 case SUMMON_BIZARRE1:
719                 {
720                         okay = (r_ptr->d_char == 'm');
721                         break;
722                 }
723                 case SUMMON_BIZARRE2:
724                 {
725                         okay = (r_ptr->d_char == 'b');
726                         break;
727                 }
728                 case SUMMON_BIZARRE3:
729                 {
730                         okay = (r_ptr->d_char == 'Q');
731                         break;
732                 }
733
734                 case SUMMON_BIZARRE4:
735                 {
736                         okay = (r_ptr->d_char == 'v');
737                         break;
738                 }
739
740                 case SUMMON_BIZARRE5:
741                 {
742                         okay = (r_ptr->d_char == '$');
743                         break;
744                 }
745
746                 case SUMMON_BIZARRE6:
747                 {
748                         okay = ((r_ptr->d_char == '!') ||
749                                  (r_ptr->d_char == '?') ||
750                                  (r_ptr->d_char == '=') ||
751                                  (r_ptr->d_char == '$') ||
752                                  (r_ptr->d_char == '|'));
753                         break;
754                 }
755
756                 case SUMMON_GOLEM:
757                 {
758                         okay = (r_ptr->d_char == 'g');
759                         break;
760                 }
761
762                 case SUMMON_CYBER:
763                 {
764                         okay = ((r_ptr->d_char == 'U') &&
765                                 (r_ptr->flags4 & RF4_ROCKET));
766                         break;
767                 }
768
769
770                 case SUMMON_KIN:
771                 {
772                         okay = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE));
773                         break;
774                 }
775
776                 case SUMMON_DAWN:
777                 {
778                         okay = (r_idx == MON_DAWN);
779                         break;
780                 }
781
782                 case SUMMON_ANIMAL:
783                 {
784                         okay = (r_ptr->flags3 & (RF3_ANIMAL));
785                         break;
786                 }
787
788                 case SUMMON_ANIMAL_RANGER:
789                 {
790                         okay = ((r_ptr->flags3 & (RF3_ANIMAL)) &&
791                                (my_strchr("abcflqrwBCHIJKMRS", r_ptr->d_char)) &&
792                                !(r_ptr->flags3 & (RF3_DRAGON)) &&
793                                !(r_ptr->flags3 & (RF3_EVIL)) &&
794                                !(r_ptr->flags3 & (RF3_UNDEAD)) &&
795                                !(r_ptr->flags3 & (RF3_DEMON)) &&
796                                !(r_ptr->flags2 & (RF2_MULTIPLY)) &&
797                                !(r_ptr->flags4 || r_ptr->flags5 || r_ptr->flags6));
798                         break;
799                 }
800
801                 case SUMMON_HI_DRAGON_LIVING:
802                 {
803                         okay = ((r_ptr->d_char == 'D') && monster_living(r_ptr));
804                         break;
805                 }
806
807                 case SUMMON_LIVING:
808                 {
809                         okay = monster_living(r_ptr);
810                         break;
811                 }
812
813                 case SUMMON_PHANTOM:
814                 {
815                         okay = (r_idx == MON_PHANTOM_B || r_idx == MON_PHANTOM_W);
816                         break;
817                 }
818
819                 case SUMMON_BLUE_HORROR:
820                 {
821                         okay = (r_idx == MON_BLUE_HORROR);
822                         break;
823                 }
824
825                 case SUMMON_ELEMENTAL:
826                 {
827                         okay = (r_ptr->d_char == 'E');
828                         break;
829                 }
830
831                 case SUMMON_VORTEX:
832                 {
833                         okay = (r_ptr->d_char == 'v');
834                         break;
835                 }
836
837                 case SUMMON_HYBRID:
838                 {
839                         okay = (r_ptr->d_char == 'H');
840                         break;
841                 }
842
843                 case SUMMON_BIRD:
844                 {
845                         okay = (r_ptr->d_char == 'B');
846                         break;
847                 }
848
849                 case SUMMON_KAMIKAZE:
850                 {
851                         int i;
852                         for (i = 0; i < 4; i++)
853                                 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
854                         break;
855                 }
856
857                 case SUMMON_KAMIKAZE_LIVING:
858                 {
859                         int i;
860
861                         for (i = 0; i < 4; i++)
862                                 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
863                         okay = (okay && monster_living(r_ptr));
864                         break;
865                 }
866
867                 case SUMMON_MANES:
868                 {
869                         okay = (r_idx == MON_MANES);
870                         break;
871                 }
872
873                 case SUMMON_LOUSE:
874                 {
875                         okay = (r_idx == MON_LOUSE);
876                         break;
877                 }
878
879                 case SUMMON_GUARDIANS:
880                 {
881                         okay = (r_ptr->flags7 & RF7_GUARDIAN);
882                         break;
883                 }
884
885                 case SUMMON_KNIGHTS:
886                 {
887                         okay = ((r_idx == MON_NOV_PALADIN) ||
888                                 (r_idx == MON_NOV_PALADIN_G) ||
889                                 (r_idx == MON_PALADIN) ||
890                                 (r_idx == MON_W_KNIGHT) ||
891                                 (r_idx == MON_ULTRA_PALADIN) ||
892                                 (r_idx == MON_KNI_TEMPLAR));
893                         break;
894                 }
895
896                 case SUMMON_EAGLES:
897                 {
898                         okay = (r_ptr->d_char == 'B' &&
899                                 (r_ptr->flags8 & RF8_WILD_MOUNTAIN) &&
900                                 (r_ptr->flags8 & RF8_WILD_ONLY));
901                         break;
902                 }
903
904                 case SUMMON_PIRANHAS:
905                 {
906                         okay = (r_idx == MON_PIRANHA);
907                         break;
908                 }
909
910                 case SUMMON_ARMAGE_GOOD:
911                 {
912                         okay = (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_GOOD));
913                         break;
914                 }
915
916                 case SUMMON_ARMAGE_EVIL:
917                 {
918                         okay = ((r_ptr->flags3 & RF3_DEMON) ||
919                                 (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_EVIL)));
920                         break;
921                 }
922         }
923
924         /* Result */
925         /* Since okay is int, "return (okay);" is not correct. */
926         return (bool)(okay ? TRUE : FALSE);
927 }
928
929
930 static int chameleon_change_m_idx = 0;
931
932
933 /*
934  * Some dungeon types restrict the possible monsters.
935  * Return TRUE is the monster is OK and FALSE otherwise
936  */
937 static bool restrict_monster_to_dungeon(int r_idx)
938 {
939         dungeon_info_type *d_ptr = &d_info[dungeon_type];
940         monster_race *r_ptr = &r_info[r_idx];
941         byte a;
942
943         if (d_ptr->flags1 & DF1_CHAMELEON)
944         {
945                 if (chameleon_change_m_idx) return TRUE;
946         }
947         if (d_ptr->flags1 & DF1_NO_MAGIC)
948         {
949                 if (r_idx != MON_CHAMELEON &&
950                     r_ptr->freq_spell && 
951                     !(r_ptr->flags4 & RF4_NOMAGIC_MASK) &&
952                     !(r_ptr->flags5 & RF5_NOMAGIC_MASK) &&
953                     !(r_ptr->flags6 & RF6_NOMAGIC_MASK))
954                         return FALSE;
955         }
956         if (d_ptr->flags1 & DF1_NO_MELEE)
957         {
958                 if (r_idx == MON_CHAMELEON) return TRUE;
959                 if (!(r_ptr->flags4 & (RF4_BOLT_MASK | RF4_BEAM_MASK | RF4_BALL_MASK)) &&
960                     !(r_ptr->flags5 & (RF5_BOLT_MASK | RF5_BEAM_MASK | RF5_BALL_MASK | RF5_CAUSE_1 | RF5_CAUSE_2 | RF5_CAUSE_3 | RF5_CAUSE_4 | RF5_MIND_BLAST | RF5_BRAIN_SMASH)) &&
961                     !(r_ptr->flags6 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
962                         return FALSE;
963         }
964         if (d_ptr->flags1 & DF1_BEGINNER)
965         {
966                 if (r_ptr->level > dun_level)
967                         return FALSE;
968         }
969
970         if (d_ptr->special_div >= 64) return TRUE;
971         if (summon_specific_type && !(d_ptr->flags1 & DF1_CHAMELEON)) return TRUE;
972
973         switch (d_ptr->mode)
974         {
975         case DUNGEON_MODE_AND:
976                 if (d_ptr->mflags1)
977                 {
978                         if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
979                                 return FALSE;
980                 }
981                 if (d_ptr->mflags2)
982                 {
983                         if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
984                                 return FALSE;
985                 }
986                 if (d_ptr->mflags3)
987                 {
988                         if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
989                                 return FALSE;
990                 }
991                 if (d_ptr->mflags4)
992                 {
993                         if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
994                                 return FALSE;
995                 }
996                 if (d_ptr->mflags5)
997                 {
998                         if ((d_ptr->mflags5 & r_ptr->flags5) != d_ptr->mflags5)
999                                 return FALSE;
1000                 }
1001                 if (d_ptr->mflags6)
1002                 {
1003                         if ((d_ptr->mflags6 & r_ptr->flags6) != d_ptr->mflags6)
1004                                 return FALSE;
1005                 }
1006                 if (d_ptr->mflags7)
1007                 {
1008                         if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
1009                                 return FALSE;
1010                 }
1011                 if (d_ptr->mflags8)
1012                 {
1013                         if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
1014                                 return FALSE;
1015                 }
1016                 if (d_ptr->mflags9)
1017                 {
1018                         if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
1019                                 return FALSE;
1020                 }
1021                 if (d_ptr->mflagsr)
1022                 {
1023                         if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
1024                                 return FALSE;
1025                 }
1026                 for (a = 0; a < 5; a++)
1027                         if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE;
1028
1029                 return TRUE;
1030
1031         case DUNGEON_MODE_NAND:
1032                 if (d_ptr->mflags1)
1033                 {
1034                         if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
1035                                 return TRUE;
1036                 }
1037                 if (d_ptr->mflags2)
1038                 {
1039                         if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
1040                                 return TRUE;
1041                 }
1042                 if (d_ptr->mflags3)
1043                 {
1044                         if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
1045                                 return TRUE;
1046                 }
1047                 if (d_ptr->mflags4)
1048                 {
1049                         if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
1050                                 return TRUE;
1051                 }
1052                 if (d_ptr->mflags5)
1053                 {
1054                         if ((d_ptr->mflags5 & r_ptr->flags5) != d_ptr->mflags5)
1055                                 return TRUE;
1056                 }
1057                 if (d_ptr->mflags6)
1058                 {
1059                         if ((d_ptr->mflags6 & r_ptr->flags6) != d_ptr->mflags6)
1060                                 return TRUE;
1061                 }
1062                 if (d_ptr->mflags7)
1063                 {
1064                         if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
1065                                 return TRUE;
1066                 }
1067                 if (d_ptr->mflags8)
1068                 {
1069                         if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
1070                                 return TRUE;
1071                 }
1072                 if (d_ptr->mflags9)
1073                 {
1074                         if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
1075                                 return TRUE;
1076                 }
1077                 if (d_ptr->mflagsr)
1078                 {
1079                         if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
1080                                 return TRUE;
1081                 }
1082                 for (a = 0; a < 5; a++)
1083                         if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return TRUE;
1084
1085                 return FALSE;
1086
1087         case DUNGEON_MODE_OR:
1088                 if (r_ptr->flags1 & d_ptr->mflags1) return TRUE;
1089                 if (r_ptr->flags2 & d_ptr->mflags2) return TRUE;
1090                 if (r_ptr->flags3 & d_ptr->mflags3) return TRUE;
1091                 if (r_ptr->flags4 & d_ptr->mflags4) return TRUE;
1092                 if (r_ptr->flags5 & d_ptr->mflags5) return TRUE;
1093                 if (r_ptr->flags6 & d_ptr->mflags6) return TRUE;
1094                 if (r_ptr->flags7 & d_ptr->mflags7) return TRUE;
1095                 if (r_ptr->flags8 & d_ptr->mflags8) return TRUE;
1096                 if (r_ptr->flags9 & d_ptr->mflags9) return TRUE;
1097                 if (r_ptr->flagsr & d_ptr->mflagsr) return TRUE;
1098                 for (a = 0; a < 5; a++)
1099                         if (d_ptr->r_char[a] == r_ptr->d_char) return TRUE;
1100
1101                 return FALSE;
1102
1103         case DUNGEON_MODE_NOR:
1104                 if (r_ptr->flags1 & d_ptr->mflags1) return FALSE;
1105                 if (r_ptr->flags2 & d_ptr->mflags2) return FALSE;
1106                 if (r_ptr->flags3 & d_ptr->mflags3) return FALSE;
1107                 if (r_ptr->flags4 & d_ptr->mflags4) return FALSE;
1108                 if (r_ptr->flags5 & d_ptr->mflags5) return FALSE;
1109                 if (r_ptr->flags6 & d_ptr->mflags6) return FALSE;
1110                 if (r_ptr->flags7 & d_ptr->mflags7) return FALSE;
1111                 if (r_ptr->flags8 & d_ptr->mflags8) return FALSE;
1112                 if (r_ptr->flags9 & d_ptr->mflags9) return FALSE;
1113                 if (r_ptr->flagsr & d_ptr->mflagsr) return FALSE;
1114                 for (a = 0; a < 5; a++)
1115                         if (d_ptr->r_char[a] == r_ptr->d_char) return FALSE;
1116
1117                 return TRUE;
1118         }
1119
1120         return TRUE;
1121 }
1122
1123 /*
1124  * Apply a "monster restriction function" to the "monster allocation table"
1125  */
1126 errr get_mon_num_prep(monster_hook_type monster_hook,
1127                                           monster_hook_type monster_hook2)
1128 {
1129         int i;
1130
1131         /* Todo: Check the hooks for non-changes */
1132
1133         /* Set the new hooks */
1134         get_mon_num_hook = monster_hook;
1135         get_mon_num2_hook = monster_hook2;
1136
1137         /* Scan the allocation table */
1138         for (i = 0; i < alloc_race_size; i++)
1139         {
1140                 monster_race    *r_ptr;
1141                 
1142                 /* Get the entry */
1143                 alloc_entry *entry = &alloc_race_table[i];
1144
1145                 entry->prob2 = 0;
1146                 r_ptr = &r_info[entry->index];
1147
1148                 /* Skip monsters which don't pass the restriction */
1149                 if ((get_mon_num_hook && !((*get_mon_num_hook)(entry->index))) ||
1150                     (get_mon_num2_hook && !((*get_mon_num2_hook)(entry->index))))
1151                         continue;
1152
1153                 if (!p_ptr->inside_battle && !chameleon_change_m_idx &&
1154                     summon_specific_type != SUMMON_GUARDIANS)
1155                 {
1156                         /* Hack -- don't create questors */
1157                         if (r_ptr->flags1 & RF1_QUESTOR)
1158                                 continue;
1159
1160                         if (r_ptr->flags7 & RF7_GUARDIAN)
1161                                 continue;
1162
1163                         /* Depth Monsters never appear out of depth */
1164                         if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) &&
1165                             (r_ptr->level > dun_level))
1166                                 continue;
1167                 }
1168
1169                 /* Accept this monster */
1170                 entry->prob2 = entry->prob1;
1171
1172                 if (dun_level && (!p_ptr->inside_quest || is_fixed_quest_idx(p_ptr->inside_quest)) && !restrict_monster_to_dungeon(entry->index) && !p_ptr->inside_battle)
1173                 {
1174                         int hoge = entry->prob2 * d_info[dungeon_type].special_div;
1175                         entry->prob2 = hoge / 64;
1176                         if (randint0(64) < (hoge & 0x3f)) entry->prob2++;
1177                 }
1178         }
1179
1180         /* Success */
1181         return (0);
1182 }
1183
1184
1185 static int mysqrt(int n)
1186 {
1187         int tmp = n>>1;
1188         int tasu = 10;
1189         int kaeriti = 1;
1190
1191         if (!tmp)
1192         {
1193                 if (n) return 1;
1194                 else return 0;
1195         }
1196
1197         while(tmp)
1198         {
1199                 if ((n/tmp) < tmp)
1200                 {
1201                         tmp >>= 1;
1202                 }
1203                 else break;
1204         }
1205         kaeriti = tmp;
1206         while(tasu)
1207         {
1208                 if ((n/tmp) < tmp)
1209                 {
1210                         tasu--;
1211                         tmp = kaeriti;
1212                 }
1213                 else
1214                 {
1215                         kaeriti = tmp;
1216                         tmp += tasu;
1217                 }
1218         }
1219         return kaeriti;
1220 }
1221
1222 /*
1223  * Choose a monster race that seems "appropriate" to the given level
1224  *
1225  * This function uses the "prob2" field of the "monster allocation table",
1226  * and various local information, to calculate the "prob3" field of the
1227  * same table, which is then used to choose an "appropriate" monster, in
1228  * a relatively efficient manner.
1229  *
1230  * Note that "town" monsters will *only* be created in the town, and
1231  * "normal" monsters will *never* be created in the town, unless the
1232  * "level" is "modified", for example, by polymorph or summoning.
1233  *
1234  * There is a small chance (1/50) of "boosting" the given depth by
1235  * a small amount (up to four levels), except in the town.
1236  *
1237  * It is (slightly) more likely to acquire a monster of the given level
1238  * than one of a lower level.  This is done by choosing several monsters
1239  * appropriate to the given level and keeping the "hardest" one.
1240  *
1241  * Note that if no monsters are "appropriate", then this function will
1242  * fail, and return zero, but this should *almost* never happen.
1243  */
1244 s16b get_mon_num(int level)
1245 {
1246         int                     i, j, p;
1247
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_NAZGUL))) &&
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  *
1476  * Useful Modes:
1477  *  0x00 --> Full nominative name ("the kobold") or "it"
1478  *  MD_INDEF_HIDDEN --> Full nominative name ("the kobold") or "something"
1479  *  MD_ASSUME_VISIBLE --> Genocide resistance name ("the kobold")
1480  *  MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE --> Killing name ("a kobold")
1481  *  MD_PRON_VISIBLE | MD_POSSESSIVE
1482  *    --> Possessive, genderized if visable ("his") or "its"
1483  *  MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE
1484  *    --> Reflexive, genderized if visable ("himself") or "itself"
1485  */
1486 void monster_desc(char *desc, monster_type *m_ptr, int mode)
1487 {
1488         cptr            res;
1489         monster_race    *r_ptr;
1490
1491         cptr            name;
1492         char            buf[128];
1493         char            silly_name[1024];
1494         bool            seen, pron;
1495         bool            named = FALSE;
1496
1497         r_ptr = &r_info[m_ptr->ap_r_idx];
1498
1499         /* Mode of MD_TRUE_NAME will reveal Chameleon's true name */
1500         if (mode & MD_TRUE_NAME) name = (r_name + real_r_ptr(m_ptr)->name);
1501         else name = (r_name + r_ptr->name);
1502
1503         /* Are we hallucinating? (Idea from Nethack...) */
1504         if (p_ptr->image && !(mode & MD_IGNORE_HALLU))
1505         {
1506                 if (one_in_(2))
1507                 {
1508 #ifdef JP
1509                         if (!get_rnd_line("silly_j.txt", m_ptr->r_idx, silly_name))
1510 #else
1511                         if (!get_rnd_line("silly.txt", m_ptr->r_idx, silly_name))
1512 #endif
1513
1514                                 named = TRUE;
1515                 }
1516
1517                 if (!named)
1518                 {
1519                         monster_race *hallu_race;
1520
1521                         do
1522                         {
1523                                 hallu_race = &r_info[randint1(max_r_idx - 1)];
1524                         }
1525                         while (hallu_race->flags1 & RF1_UNIQUE);
1526
1527                         strcpy(silly_name, (r_name + hallu_race->name));
1528                 }
1529
1530                 /* Better not strcpy it, or we could corrupt r_info... */
1531                 name = silly_name;
1532         }
1533
1534         /* Can we "see" it (exists + forced, or visible + not unforced) */
1535         seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml)));
1536
1537         /* Sexed Pronouns (seen and allowed, or unseen and allowed) */
1538         pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN))));
1539
1540
1541         /* First, try using pronouns, or describing hidden monsters */
1542         if (!seen || pron)
1543         {
1544                 /* an encoding of the monster "sex" */
1545                 int kind = 0x00;
1546
1547                 /* Extract the gender (if applicable) */
1548                 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1549                 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1550
1551                 /* Ignore the gender (if desired) */
1552                 if (!m_ptr || !pron) kind = 0x00;
1553
1554
1555                 /* Assume simple result */
1556 #ifdef JP
1557                 res = "²¿¤«";
1558 #else
1559                 res = "it";
1560 #endif
1561
1562
1563                 /* Brute force: split on the possibilities */
1564                 switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE)))
1565                 {
1566                         /* Neuter, or unknown */
1567 #ifdef JP
1568                         case 0x00:                                                    res = "²¿¤«"; break;
1569                         case 0x00 + (MD_OBJECTIVE):                                   res = "²¿¤«"; break;
1570                         case 0x00 + (MD_POSSESSIVE):                                  res = "²¿¤«¤Î"; break;
1571                         case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "²¿¤«¼«¿È"; break;
1572                         case 0x00 + (MD_INDEF_HIDDEN):                                res = "²¿¤«"; break;
1573                         case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "²¿¤«"; break;
1574                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "²¿¤«"; break;
1575                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "¤½¤ì¼«¿È"; break;
1576 #else
1577                         case 0x00:                                                    res = "it"; break;
1578                         case 0x00 + (MD_OBJECTIVE):                                   res = "it"; break;
1579                         case 0x00 + (MD_POSSESSIVE):                                  res = "its"; break;
1580                         case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "itself"; break;
1581                         case 0x00 + (MD_INDEF_HIDDEN):                                res = "something"; break;
1582                         case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "something"; break;
1583                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "something's"; break;
1584                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1585 #endif
1586
1587
1588                         /* Male (assume human if vague) */
1589 #ifdef JP
1590                         case 0x10:                                                    res = "Èà"; break;
1591                         case 0x10 + (MD_OBJECTIVE):                                   res = "Èà"; break;
1592                         case 0x10 + (MD_POSSESSIVE):                                  res = "Èà¤Î"; break;
1593                         case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "È༫¿È"; break;
1594                         case 0x10 + (MD_INDEF_HIDDEN):                                res = "狼"; break;
1595                         case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "狼"; break;
1596                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "狼¤Î"; break;
1597                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "È༫¿È"; break;
1598 #else
1599                         case 0x10:                                                    res = "he"; break;
1600                         case 0x10 + (MD_OBJECTIVE):                                   res = "him"; break;
1601                         case 0x10 + (MD_POSSESSIVE):                                  res = "his"; break;
1602                         case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "himself"; break;
1603                         case 0x10 + (MD_INDEF_HIDDEN):                                res = "someone"; break;
1604                         case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "someone"; break;
1605                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "someone's"; break;
1606                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1607 #endif
1608
1609
1610                         /* Female (assume human if vague) */
1611 #ifdef JP
1612                         case 0x20:                                                    res = "Èà½÷"; break;
1613                         case 0x20 + (MD_OBJECTIVE):                                   res = "Èà½÷"; break;
1614                         case 0x20 + (MD_POSSESSIVE):                                  res = "Èà½÷¤Î"; break;
1615                         case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "Èà½÷¼«¿È"; break;
1616                         case 0x20 + (MD_INDEF_HIDDEN):                                res = "狼"; break;
1617                         case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "狼"; break;
1618                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "狼¤Î"; break;
1619                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "Èà½÷¼«¿È"; break;
1620 #else
1621                         case 0x20:                                                    res = "she"; break;
1622                         case 0x20 + (MD_OBJECTIVE):                                   res = "her"; break;
1623                         case 0x20 + (MD_POSSESSIVE):                                  res = "her"; break;
1624                         case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE):                   res = "herself"; break;
1625                         case 0x20 + (MD_INDEF_HIDDEN):                                res = "someone"; break;
1626                         case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE):                 res = "someone"; break;
1627                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE):                res = "someone's"; break;
1628                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1629 #endif
1630                 }
1631
1632                 /* Copy the result */
1633                 (void)strcpy(desc, res);
1634         }
1635
1636
1637         /* Handle visible monsters, "reflexive" request */
1638         else if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE))
1639         {
1640                 /* The monster is visible, so use its gender */
1641 #ifdef JP
1642                 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, "Èà½÷¼«¿È");
1643                 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, "È༫¿È");
1644                 else strcpy(desc, "¤½¤ì¼«¿È");
1645 #else
1646                 if (r_ptr->flags1 & RF1_FEMALE) strcpy(desc, "herself");
1647                 else if (r_ptr->flags1 & RF1_MALE) strcpy(desc, "himself");
1648                 else strcpy(desc, "itself");
1649 #endif
1650         }
1651
1652
1653         /* Handle all other visible monster requests */
1654         else
1655         {
1656                 /* Tanuki? */
1657                 if (is_pet(m_ptr) && m_ptr->ap_r_idx != m_ptr->r_idx)
1658                 {
1659 #ifdef JP
1660                         char *t;
1661                         strcpy(buf, name);
1662                         t = buf;
1663                         while(strncmp(t, "¡Ù", 2) && *t) t++;
1664                         if (*t)
1665                         {
1666                                 *t = '\0';
1667                                 (void)sprintf(desc, "%s¡©¡Ù", buf);
1668                         }
1669                         else
1670                                 (void)sprintf(desc, "%s¡©", name);
1671 #else
1672                         (void)sprintf(desc, "%s?", name);
1673 #endif
1674                 }
1675                 else
1676
1677                 /* It could be a Unique */
1678                 if ((r_ptr->flags1 & RF1_UNIQUE) && !(p_ptr->image && !(mode & MD_IGNORE_HALLU)))
1679                 {
1680                         /* Start with the name (thus nominative and objective) */
1681                         if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME))
1682                         {
1683 #ifdef JP
1684                                 char *t;
1685                                 strcpy(buf, name);
1686                                 t = buf;
1687                                 while (strncmp(t, "¡Ù", 2) && *t) t++;
1688                                 if (*t)
1689                                 {
1690                                         *t = '\0';
1691                                         (void)sprintf(desc, "%s¡©¡Ù", buf);
1692                                 }
1693                                 else
1694                                         (void)sprintf(desc, "%s¡©", name);
1695 #else
1696                                 (void)sprintf(desc, "%s?", name);
1697 #endif
1698                         }
1699
1700                         /* Inside monster arena, and it is not your mount */
1701                         else if (p_ptr->inside_battle &&
1702                                  !(p_ptr->riding && (&m_list[p_ptr->riding] == m_ptr)))
1703                         {
1704                                 /* It is a fake unique monster */
1705 #ifdef JP
1706                                 (void)sprintf(desc, "%s¤â¤É¤­", name);
1707 #else
1708                                 (void)sprintf(desc, "fake %s", name);
1709 #endif
1710                         }
1711
1712                         else
1713                         {
1714                                 (void)strcpy(desc, name);
1715                         }
1716                 }
1717
1718                 /* It could be an indefinite monster */
1719                 else if (mode & MD_INDEF_VISIBLE)
1720                 {
1721                         /* XXX Check plurality for "some" */
1722
1723                         /* Indefinite monsters need an indefinite article */
1724 #ifdef JP
1725                         (void)strcpy(desc, "");
1726 #else
1727                         (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1728 #endif
1729
1730                         (void)strcat(desc, name);
1731                 }
1732
1733                 /* It could be a normal, definite, monster */
1734                 else
1735                 {
1736                         /* Definite monsters need a definite article */
1737                         if (is_pet(m_ptr))
1738 #ifdef JP
1739                                 (void)strcpy(desc, "¤¢¤Ê¤¿¤Î");
1740 #else
1741                                 (void)strcpy(desc, "your ");
1742 #endif
1743
1744                         else
1745 #ifdef JP
1746                                 (void)strcpy(desc, "");
1747 #else
1748                                 (void)strcpy(desc, "the ");
1749 #endif
1750
1751                         (void)strcat(desc, name);
1752                 }
1753
1754                 if (m_ptr->nickname)
1755                 {
1756 #ifdef JP
1757                         sprintf(buf,"¡Ö%s¡×",quark_str(m_ptr->nickname));
1758 #else
1759                         sprintf(buf," called %s",quark_str(m_ptr->nickname));
1760 #endif
1761                         strcat(desc,buf);
1762                 }
1763
1764                 if (p_ptr->riding && (&m_list[p_ptr->riding] == m_ptr))
1765                 {
1766 #ifdef JP
1767                         strcat(desc,"(¾èÇÏÃæ)");
1768 #else
1769                         strcat(desc,"(riding)");
1770 #endif
1771                 }
1772
1773                 if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1774                 {
1775                         if (r_ptr->flags1 & RF1_UNIQUE)
1776                         {
1777 #ifdef JP
1778                                 strcat(desc,"(¥«¥á¥ì¥ª¥ó¤Î²¦)");
1779 #else
1780                                 strcat(desc,"(Chameleon Lord)");
1781 #endif
1782                         }
1783                         else
1784                         {
1785 #ifdef JP
1786                                 strcat(desc,"(¥«¥á¥ì¥ª¥ó)");
1787 #else
1788                                 strcat(desc,"(Chameleon)");
1789 #endif
1790                         }
1791                 }
1792
1793                 if ((mode & MD_IGNORE_HALLU) && m_ptr->ap_r_idx != m_ptr->r_idx)
1794                 {
1795                         strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1796                 }
1797
1798                 /* Handle the Possessive as a special afterthought */
1799                 if (mode & MD_POSSESSIVE)
1800                 {
1801                         /* XXX Check for trailing "s" */
1802                         
1803                         /* Simply append "apostrophe" and "s" */
1804 #ifdef JP
1805                         (void)strcat(desc, "¤Î");
1806 #else
1807                         (void)strcat(desc, "'s");
1808 #endif
1809                 }
1810         }
1811 }
1812
1813
1814
1815
1816 /*
1817  * Learn about a monster (by "probing" it)
1818  *
1819  * Return the number of new flags learnt.  -Mogami-
1820  */
1821 int lore_do_probe(int r_idx)
1822 {
1823         monster_race *r_ptr = &r_info[r_idx];
1824         int i, n = 0;
1825         byte tmp_byte;
1826
1827         /* Maximal info about awareness */
1828         if (r_ptr->r_wake != MAX_UCHAR) n++;
1829         if (r_ptr->r_ignore != MAX_UCHAR) n++;
1830         r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1831
1832         /* Observe "maximal" attacks */
1833         for (i = 0; i < 4; i++)
1834         {
1835                 /* Examine "actual" blows */
1836                 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1837                 {
1838                         /* Maximal observations */
1839                         if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1840                         r_ptr->r_blows[i] = MAX_UCHAR;
1841                 }
1842         }
1843
1844         /* Maximal drops */
1845         tmp_byte =
1846                 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1847                  ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1848                  ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1849                  ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1850                  ((r_ptr->flags1 & RF1_DROP_90)  ? 1 : 0) +
1851                  ((r_ptr->flags1 & RF1_DROP_60)  ? 1 : 0));
1852
1853         /* Only "valid" drops */
1854         if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1855         {
1856                 if (r_ptr->r_drop_item != tmp_byte) n++;
1857                 r_ptr->r_drop_item = tmp_byte;
1858         }
1859         if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1860         {
1861                 if (r_ptr->r_drop_gold != tmp_byte) n++;
1862                 r_ptr->r_drop_gold = tmp_byte;
1863         }
1864
1865         /* Observe many spells */
1866         if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1867         r_ptr->r_cast_spell = MAX_UCHAR;
1868
1869         /* Count unknown flags */
1870         for (i = 0; i < 32; i++)
1871         {
1872                 if (!(r_ptr->r_flags1 & (1L << i)) &&
1873                     (r_ptr->flags1 & (1L << i))) n++;
1874                 if (!(r_ptr->r_flags2 & (1L << i)) &&
1875                     (r_ptr->flags2 & (1L << i))) n++;
1876                 if (!(r_ptr->r_flags3 & (1L << i)) &&
1877                     (r_ptr->flags3 & (1L << i))) n++;
1878                 if (!(r_ptr->r_flags4 & (1L << i)) &&
1879                     (r_ptr->flags4 & (1L << i))) n++;
1880                 if (!(r_ptr->r_flags5 & (1L << i)) &&
1881                     (r_ptr->flags5 & (1L << i))) n++;
1882                 if (!(r_ptr->r_flags6 & (1L << i)) &&
1883                     (r_ptr->flags6 & (1L << i))) n++;
1884                 if (!(r_ptr->r_flagsr & (1L << i)) &&
1885                     (r_ptr->flagsr & (1L << i))) n++;
1886
1887                 /* r_flags7 is actually unused */
1888 #if 0
1889                 if (!(r_ptr->r_flags7 & (1L << i)) &&
1890                     (r_ptr->flags7 & (1L << i))) n++;
1891 #endif
1892         }
1893
1894         /* Know all the flags */
1895         r_ptr->r_flags1 = r_ptr->flags1;
1896         r_ptr->r_flags2 = r_ptr->flags2;
1897         r_ptr->r_flags3 = r_ptr->flags3;
1898         r_ptr->r_flags4 = r_ptr->flags4;
1899         r_ptr->r_flags5 = r_ptr->flags5;
1900         r_ptr->r_flags6 = r_ptr->flags6;
1901         r_ptr->r_flagsr = r_ptr->flagsr;
1902
1903         /* r_flags7 is actually unused */
1904         /* r_ptr->r_flags7 = r_ptr->flags7; */
1905
1906         /* Know about evolution */
1907         if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1908         r_ptr->r_xtra1 |= MR1_SINKA;
1909
1910         /* Update monster recall window */
1911         if (p_ptr->monster_race_idx == r_idx)
1912         {
1913                 /* Window stuff */
1914                 p_ptr->window |= (PW_MONSTER);
1915         }
1916
1917         /* Return the number of new flags learnt */
1918         return n;
1919 }
1920
1921
1922 /*
1923  * Take note that the given monster just dropped some treasure
1924  *
1925  * Note that learning the "GOOD"/"GREAT" flags gives information
1926  * about the treasure (even when the monster is killed for the first
1927  * time, such as uniques, and the treasure has not been examined yet).
1928  *
1929  * This "indirect" method is used to prevent the player from learning
1930  * exactly how much treasure a monster can drop from observing only
1931  * a single example of a drop.  This method actually observes how much
1932  * gold and items are dropped, and remembers that information to be
1933  * described later by the monster recall code.
1934  */
1935 void lore_treasure(int m_idx, int num_item, int num_gold)
1936 {
1937         monster_type *m_ptr = &m_list[m_idx];
1938
1939         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1940
1941         /* If the monster doesn't have original appearance, don't note */
1942         if (!is_original_ap(m_ptr)) return;
1943
1944         /* Note the number of things dropped */
1945         if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1946         if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1947
1948         /* Hack -- memorize the good/great flags */
1949         if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1950         if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1951
1952         /* Update monster recall window */
1953         if (p_ptr->monster_race_idx == m_ptr->r_idx)
1954         {
1955                 /* Window stuff */
1956                 p_ptr->window |= (PW_MONSTER);
1957         }
1958 }
1959
1960
1961
1962 void sanity_blast(monster_type *m_ptr, bool necro)
1963 {
1964         bool happened = FALSE;
1965         int power = 100;
1966
1967         if (p_ptr->inside_battle || !character_dungeon) return;
1968
1969         if (!necro)
1970         {
1971                 char            m_name[80];
1972                 monster_race    *r_ptr = &r_info[m_ptr->ap_r_idx];
1973
1974                 power = r_ptr->level / 2;
1975
1976                 monster_desc(m_name, m_ptr, 0);
1977
1978                 if (!(r_ptr->flags1 & RF1_UNIQUE))
1979                 {
1980                         if (r_ptr->flags1 & RF1_FRIENDS)
1981                         power /= 2;
1982                 }
1983                 else power *= 2;
1984
1985                 if (!hack_mind)
1986                         return; /* No effect yet, just loaded... */
1987
1988                 if (!m_ptr->ml)
1989                         return; /* Cannot see it for some reason */
1990
1991                 if (!(r_ptr->flags2 & RF2_ELDRITCH_HORROR))
1992                         return; /* oops */
1993
1994
1995
1996                 if (is_pet(m_ptr))
1997                         return; /* Pet eldritch horrors are safe most of the time */
1998
1999                 if (randint1(100) > power) return;
2000
2001                 if (saving_throw(p_ptr->skill_sav - power))
2002                 {
2003                         return; /* Save, no adverse effects */
2004                 }
2005
2006                 if (p_ptr->image)
2007                 {
2008                         /* Something silly happens... */
2009 #ifdef JP
2010                         msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2011                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2012 #else
2013                         msg_format("You behold the %s visage of %s!",
2014                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2015 #endif
2016
2017
2018                         if (one_in_(3))
2019                         {
2020                                 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
2021                                 p_ptr->image = p_ptr->image + randint1(r_ptr->level);
2022                         }
2023
2024                         return; /* Never mind; we can't see it clearly enough */
2025                 }
2026
2027                 /* Something frightening happens... */
2028 #ifdef JP
2029                 msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2030                         horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2031 #else
2032                 msg_format("You behold the %s visage of %s!",
2033                         horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2034 #endif
2035
2036                 r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
2037
2038                 /* Demon characters are unaffected */
2039                 if (prace_is_(RACE_IMP) || prace_is_(RACE_DEMON) || (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) return;
2040                 if (p_ptr->wizard) return;
2041
2042                 /* Undead characters are 50% likely to be unaffected */
2043                 if (prace_is_(RACE_SKELETON) || prace_is_(RACE_ZOMBIE)
2044                         || prace_is_(RACE_VAMPIRE) || prace_is_(RACE_SPECTRE) ||
2045                     (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD))
2046                 {
2047                         if (saving_throw(25 + p_ptr->lev)) return;
2048                 }
2049         }
2050         else
2051         {
2052 #ifdef JP
2053 msg_print("¥Í¥¯¥í¥Î¥ß¥³¥ó¤òÆɤó¤ÇÀµµ¤¤ò¼º¤Ã¤¿¡ª");
2054 #else
2055                 msg_print("Your sanity is shaken by reading the Necronomicon!");
2056 #endif
2057
2058         }
2059
2060         if (!saving_throw(p_ptr->skill_sav - power)) /* Mind blast */
2061         {
2062                 if (!p_ptr->resist_conf)
2063                 {
2064                         (void)set_confused(p_ptr->confused + randint0(4) + 4);
2065                 }
2066                 if (!p_ptr->resist_chaos && one_in_(3))
2067                 {
2068                         (void)set_image(p_ptr->image + randint0(250) + 150);
2069                 }
2070                 return;
2071         }
2072
2073         if (!saving_throw(p_ptr->skill_sav - power)) /* Lose int & wis */
2074         {
2075                 do_dec_stat(A_INT);
2076                 do_dec_stat(A_WIS);
2077                 return;
2078         }
2079
2080         if (!saving_throw(p_ptr->skill_sav - power)) /* Brain smash */
2081         {
2082                 if (!p_ptr->resist_conf)
2083                 {
2084                         (void)set_confused(p_ptr->confused + randint0(4) + 4);
2085                 }
2086                 if (!p_ptr->free_act)
2087                 {
2088                         (void)set_paralyzed(p_ptr->paralyzed + randint0(4) + 4);
2089                 }
2090                 while (randint0(100) > p_ptr->skill_sav)
2091                         (void)do_dec_stat(A_INT);
2092                 while (randint0(100) > p_ptr->skill_sav)
2093                         (void)do_dec_stat(A_WIS);
2094                 if (!p_ptr->resist_chaos)
2095                 {
2096                         (void)set_image(p_ptr->image + randint0(250) + 150);
2097                 }
2098                 return;
2099         }
2100
2101         if (!saving_throw(p_ptr->skill_sav - power)) /* Amnesia */
2102         {
2103
2104                 if (lose_all_info())
2105 #ifdef JP
2106 msg_print("¤¢¤Þ¤ê¤Î¶²ÉݤËÁ´¤Æ¤Î¤³¤È¤ò˺¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª");
2107 #else
2108                         msg_print("You forget everything in your utmost terror!");
2109 #endif
2110
2111                 return;
2112         }
2113
2114         if (saving_throw(p_ptr->skill_sav - power))
2115         {
2116                 return;
2117         }
2118
2119         /* Else gain permanent insanity */
2120         if ((p_ptr->muta3 & MUT3_MORONIC) && /*(p_ptr->muta2 & MUT2_BERS_RAGE) &&*/
2121                 ((p_ptr->muta2 & MUT2_COWARDICE) || (p_ptr->resist_fear)) &&
2122                 ((p_ptr->muta2 & MUT2_HALLU) || (p_ptr->resist_chaos)))
2123         {
2124                 /* The poor bastard already has all possible insanities! */
2125                 return;
2126         }
2127
2128         while (!happened)
2129         {
2130                 switch (randint1(21))
2131                 {
2132                         case 1:
2133                                 if (!(p_ptr->muta3 & MUT3_MORONIC) && one_in_(5))
2134                                 {
2135                                         if ((p_ptr->stat_use[A_INT] < 4) && (p_ptr->stat_use[A_WIS] < 4))
2136                                         {
2137 #ifdef JP
2138 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¤è¤¦¤Êµ¤¤¬¤·¤¿¡£¤·¤«¤·¤½¤ì¤Ï¸µ¡¹¤À¤Ã¤¿¡£");
2139 #else
2140                                                 msg_print("You turn into an utter moron!");
2141 #endif
2142                                         }
2143                                         else
2144                                         {
2145 #ifdef JP
2146 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¡ª");
2147 #else
2148                                                 msg_print("You turn into an utter moron!");
2149 #endif
2150                                         }
2151
2152                                         if (p_ptr->muta3 & MUT3_HYPER_INT)
2153                                         {
2154 #ifdef JP
2155 msg_print("¤¢¤Ê¤¿¤ÎǾ¤ÏÀ¸ÂÎ¥³¥ó¥Ô¥å¡¼¥¿¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2156 #else
2157                                                 msg_print("Your brain is no longer a living computer.");
2158 #endif
2159
2160                                                 p_ptr->muta3 &= ~(MUT3_HYPER_INT);
2161                                         }
2162                                         p_ptr->muta3 |= MUT3_MORONIC;
2163                                         happened = TRUE;
2164                                 }
2165                                 break;
2166                         case 2:
2167                         case 3:
2168                         case 4:
2169                         case 5:
2170                         case 6:
2171                         case 7:
2172                         case 8:
2173                         case 9:
2174                         case 10:
2175                         case 11:
2176                                 if (!(p_ptr->muta2 & MUT2_COWARDICE) && !p_ptr->resist_fear)
2177                                 {
2178 #ifdef JP
2179 msg_print("¤¢¤Ê¤¿¤Ï¥Ñ¥é¥Î¥¤¥¢¤Ë¤Ê¤Ã¤¿¡ª");
2180 #else
2181                                         msg_print("You become paranoid!");
2182 #endif
2183
2184
2185                                         /* Duh, the following should never happen, but anyway... */
2186                                         if (p_ptr->muta3 & MUT3_FEARLESS)
2187                                         {
2188 #ifdef JP
2189 msg_print("¤¢¤Ê¤¿¤Ï¤â¤¦¶²¤ìÃΤ餺¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2190 #else
2191                                                 msg_print("You are no longer fearless.");
2192 #endif
2193
2194                                                 p_ptr->muta3 &= ~(MUT3_FEARLESS);
2195                                         }
2196
2197                                         p_ptr->muta2 |= MUT2_COWARDICE;
2198                                         happened = TRUE;
2199                                 }
2200                                 break;
2201                         case 12:
2202                         case 13:
2203                         case 14:
2204                         case 15:
2205                         case 16:
2206                         case 17:
2207                         case 18:
2208                         case 19:
2209                         case 20:
2210                         case 21:
2211                                 if (!(p_ptr->muta2 & MUT2_HALLU) && !p_ptr->resist_chaos)
2212                                 {
2213 #ifdef JP
2214 msg_print("¸¸³Ð¤ò¤Ò¤­µ¯¤³¤¹Àº¿ÀºøÍð¤Ë´Ù¤Ã¤¿¡ª");
2215 #else
2216                                         msg_print("You are afflicted by a hallucinatory insanity!");
2217 #endif
2218
2219                                         p_ptr->muta2 |= MUT2_HALLU;
2220                                         happened = TRUE;
2221                                 }
2222                                 break;
2223                         default:
2224                                 if (!(p_ptr->muta2 & MUT2_BERS_RAGE))
2225                                 {
2226 #ifdef JP
2227 msg_print("·ãÎõ¤Ê´¶¾ð¤Îȯºî¤Ë¤ª¤½¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡ª");
2228 #else
2229                                         msg_print("You become subject to fits of berserk rage!");
2230 #endif
2231
2232                                         p_ptr->muta2 |= MUT2_BERS_RAGE;
2233                                         happened = TRUE;
2234                                 }
2235                                 break;
2236                 }
2237         }
2238
2239         p_ptr->update |= PU_BONUS;
2240         handle_stuff();
2241 }
2242
2243
2244 /*
2245  * This function updates the monster record of the given monster
2246  *
2247  * This involves extracting the distance to the player (if requested),
2248  * and then checking for visibility (natural, infravision, see-invis,
2249  * telepathy), updating the monster visibility flag, redrawing (or
2250  * erasing) the monster when its visibility changes, and taking note
2251  * of any interesting monster flags (cold-blooded, invisible, etc).
2252  *
2253  * Note the new "mflag" field which encodes several monster state flags,
2254  * including "view" for when the monster is currently in line of sight,
2255  * and "mark" for when the monster is currently visible via detection.
2256  *
2257  * The only monster fields that are changed here are "cdis" (the
2258  * distance from the player), "ml" (visible to the player), and
2259  * "mflag" (to maintain the "MFLAG_VIEW" flag).
2260  *
2261  * Note the special "update_monsters()" function which can be used to
2262  * call this function once for every monster.
2263  *
2264  * Note the "full" flag which requests that the "cdis" field be updated,
2265  * this is only needed when the monster (or the player) has moved.
2266  *
2267  * Every time a monster moves, we must call this function for that
2268  * monster, and update the distance, and the visibility.  Every time
2269  * the player moves, we must call this function for every monster, and
2270  * update the distance, and the visibility.  Whenever the player "state"
2271  * changes in certain ways ("blindness", "infravision", "telepathy",
2272  * and "see invisible"), we must call this function for every monster,
2273  * and update the visibility.
2274  *
2275  * Routines that change the "illumination" of a grid must also call this
2276  * function for any monster in that grid, since the "visibility" of some
2277  * monsters may be based on the illumination of their grid.
2278  *
2279  * Note that this function is called once per monster every time the
2280  * player moves.  When the player is running, this function is one
2281  * of the primary bottlenecks, along with "update_view()" and the
2282  * "process_monsters()" code, so efficiency is important.
2283  *
2284  * Note the optimized "inline" version of the "distance()" function.
2285  *
2286  * A monster is "visible" to the player if (1) it has been detected
2287  * by the player, (2) it is close to the player and the player has
2288  * telepathy, or (3) it is close to the player, and in line of sight
2289  * of the player, and it is "illuminated" by some combination of
2290  * infravision, torch light, or permanent light (invisible monsters
2291  * are only affected by "light" if the player can see invisible).
2292  *
2293  * Monsters which are not on the current panel may be "visible" to
2294  * the player, and their descriptions will include an "offscreen"
2295  * reference.  Currently, offscreen monsters cannot be targetted
2296  * or viewed directly, but old targets will remain set.  XXX XXX
2297  *
2298  * The player can choose to be disturbed by several things, including
2299  * "disturb_move" (monster which is viewable moves in some way), and
2300  * "disturb_near" (monster which is "easily" viewable moves in some
2301  * way).  Note that "moves" includes "appears" and "disappears".
2302  */
2303 void update_mon(int m_idx, bool full)
2304 {
2305         monster_type *m_ptr = &m_list[m_idx];
2306
2307         monster_race *r_ptr = &r_info[m_ptr->r_idx];
2308
2309         bool do_disturb = disturb_move;
2310
2311         int d;
2312
2313         /* Current location */
2314         int fy = m_ptr->fy;
2315         int fx = m_ptr->fx;
2316
2317         /* Seen at all */
2318         bool flag = FALSE;
2319
2320         /* Seen by vision */
2321         bool easy = FALSE;
2322
2323         /* Non-Ninja player in the darkness */
2324         bool in_darkness = (d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto;
2325
2326         /* Do disturb? */
2327         if (disturb_high)
2328         {
2329                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2330
2331                 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
2332                         do_disturb = TRUE;
2333         }
2334
2335         /* Compute distance */
2336         if (full)
2337         {
2338                 /* Distance components */
2339                 int dy = (py > fy) ? (py - fy) : (fy - py);
2340                 int dx = (px > fx) ? (px - fx) : (fx - px);
2341
2342                 /* Approximate distance */
2343                 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2344
2345                 /* Restrict distance */
2346                 if (d > 255) d = 255;
2347
2348                 if (!d) d = 1;
2349
2350                 /* Save the distance */
2351                 m_ptr->cdis = d;
2352         }
2353
2354         /* Extract distance */
2355         else
2356         {
2357                 /* Extract the distance */
2358                 d = m_ptr->cdis;
2359         }
2360
2361
2362         /* Detected */
2363         if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
2364
2365
2366         /* Nearby */
2367         if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
2368         {
2369                 if (!in_darkness || (d <= MAX_SIGHT / 4))
2370                 {
2371                         if (p_ptr->special_defense & KATA_MUSOU)
2372                         {
2373                                 /* Detectable */
2374                                 flag = TRUE;
2375
2376                                 if (is_original_ap(m_ptr))
2377                                 {
2378                                         /* Hack -- Memorize mental flags */
2379                                         if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2380                                         if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2381                                 }
2382                         }
2383
2384                         /* Basic telepathy */
2385                         else if (p_ptr->telepathy)
2386                         {
2387                                 /* Empty mind, no telepathy */
2388                                 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
2389                                 {
2390                                         /* Memorize flags */
2391                                         if (is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
2392                                 }
2393
2394                                 /* Weird mind, occasional telepathy */
2395                                 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
2396                                 {
2397                                         /* One in ten individuals are detectable */
2398                                         if ((m_idx % 10) == 5)
2399                                         {
2400                                                 /* Detectable */
2401                                                 flag = TRUE;
2402
2403                                                 if (is_original_ap(m_ptr))
2404                                                 {
2405                                                         /* Memorize flags */
2406                                                         r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
2407
2408                                                         /* Hack -- Memorize mental flags */
2409                                                         if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2410                                                         if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2411                                                 }
2412                                         }
2413                                 }
2414
2415                                 /* Normal mind, allow telepathy */
2416                                 else
2417                                 {
2418                                         /* Detectable */
2419                                         flag = TRUE;
2420
2421                                         if (is_original_ap(m_ptr))
2422                                         {
2423                                                 /* Hack -- Memorize mental flags */
2424                                                 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2425                                                 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2426                                         }
2427                                 }
2428                         }
2429
2430                         /* Magical sensing */
2431                         if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
2432                         {
2433                                 flag = TRUE;
2434                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_ANIMAL);
2435                         }
2436
2437                         /* Magical sensing */
2438                         if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
2439                         {
2440                                 flag = TRUE;
2441                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_UNDEAD);
2442                         }
2443
2444                         /* Magical sensing */
2445                         if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
2446                         {
2447                                 flag = TRUE;
2448                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_DEMON);
2449                         }
2450
2451                         /* Magical sensing */
2452                         if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
2453                         {
2454                                 flag = TRUE;
2455                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_ORC);
2456                         }
2457
2458                         /* Magical sensing */
2459                         if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
2460                         {
2461                                 flag = TRUE;
2462                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_TROLL);
2463                         }
2464
2465                         /* Magical sensing */
2466                         if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
2467                         {
2468                                 flag = TRUE;
2469                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_GIANT);
2470                         }
2471
2472                         /* Magical sensing */
2473                         if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
2474                         {
2475                                 flag = TRUE;
2476                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_DRAGON);
2477                         }
2478
2479                         /* Magical sensing */
2480                         if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
2481                         {
2482                                 flag = TRUE;
2483                                 if (is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_HUMAN);
2484                         }
2485
2486                         /* Magical sensing */
2487                         if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
2488                         {
2489                                 flag = TRUE;
2490                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_EVIL);
2491                         }
2492
2493                         /* Magical sensing */
2494                         if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
2495                         {
2496                                 flag = TRUE;
2497                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_GOOD);
2498                         }
2499
2500                         /* Magical sensing */
2501                         if ((p_ptr->esp_nonliving) &&
2502                             ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
2503                         {
2504                                 flag = TRUE;
2505                                 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_NONLIVING);
2506                         }
2507
2508                         /* Magical sensing */
2509                         if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
2510                         {
2511                                 flag = TRUE;
2512                                 if (is_original_ap(m_ptr)) r_ptr->r_flags1 |= (RF1_UNIQUE);
2513                         }
2514                 }
2515
2516                 /* Normal line of sight, and not blind */
2517                 if (player_has_los_bold(fy, fx) && !p_ptr->blind)
2518                 {
2519                         bool do_invisible = FALSE;
2520                         bool do_cold_blood = FALSE;
2521
2522                         /* Use "infravision" */
2523                         if (d <= p_ptr->see_infra)
2524                         {
2525                                 /* Handle "cold blooded" monsters */
2526                                 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
2527                                 {
2528                                         /* Take note */
2529                                         do_cold_blood = TRUE;
2530                                 }
2531
2532                                 /* Handle "warm blooded" monsters */
2533                                 else
2534                                 {
2535                                         /* Easy to see */
2536                                         easy = flag = TRUE;
2537                                 }
2538                         }
2539
2540                         /* Use "illumination" */
2541                         if (player_can_see_bold(fy, fx))
2542                         {
2543                                 /* Handle "invisible" monsters */
2544                                 if (r_ptr->flags2 & (RF2_INVISIBLE))
2545                                 {
2546                                         /* Take note */
2547                                         do_invisible = TRUE;
2548
2549                                         /* See invisible */
2550                                         if (p_ptr->see_inv)
2551                                         {
2552                                                 /* Easy to see */
2553                                                 easy = flag = TRUE;
2554                                         }
2555                                 }
2556
2557                                 /* Handle "normal" monsters */
2558                                 else
2559                                 {
2560                                         /* Easy to see */
2561                                         easy = flag = TRUE;
2562                                 }
2563                         }
2564
2565                         /* Visible */
2566                         if (flag)
2567                         {
2568                                 if (is_original_ap(m_ptr))
2569                                 {
2570                                         /* Memorize flags */
2571                                         if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2572                                         if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2573                                 }
2574                         }
2575                 }
2576         }
2577
2578
2579         /* The monster is now visible */
2580         if (flag)
2581         {
2582                 /* It was previously unseen */
2583                 if (!m_ptr->ml)
2584                 {
2585                         /* Mark as visible */
2586                         m_ptr->ml = TRUE;
2587
2588                         /* Draw the monster */
2589                         lite_spot(fy, fx);
2590
2591                         /* Update health bar as needed */
2592                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2593                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2594
2595                         /* Hack -- Count "fresh" sightings */
2596                         if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2597                                 r_info[MON_KAGE].r_sights++;
2598                         else if (m_ptr->ap_r_idx == m_ptr->r_idx && 
2599                                  r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
2600
2601                         /* Eldritch Horror */
2602                         if (r_ptr->flags2 & RF2_ELDRITCH_HORROR)
2603                         {
2604                                 sanity_blast(m_ptr, FALSE);
2605                         }
2606
2607                         /* Disturb on appearance */
2608                         if (disturb_near && (projectable(m_ptr->fy, m_ptr->fx, py, px) && projectable(py, px, m_ptr->fy, m_ptr->fx)))
2609                         {
2610                                 if (disturb_pets || is_hostile(m_ptr))
2611                                         disturb(1, 0);
2612                         }
2613                 }
2614         }
2615
2616         /* The monster is not visible */
2617         else
2618         {
2619                 /* It was previously seen */
2620                 if (m_ptr->ml)
2621                 {
2622                         /* Mark as not visible */
2623                         m_ptr->ml = FALSE;
2624
2625                         /* Erase the monster */
2626                         lite_spot(fy, fx);
2627
2628                         /* Update health bar as needed */
2629                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2630                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2631
2632                         /* Disturb on disappearance */
2633                         if (do_disturb)
2634                         {
2635                                 if (disturb_pets || is_hostile(m_ptr))
2636                                         disturb(1, 0);
2637                         }
2638                 }
2639         }
2640
2641
2642         /* The monster is now easily visible */
2643         if (easy)
2644         {
2645                 /* Change */
2646                 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2647                 {
2648                         /* Mark as easily visible */
2649                         m_ptr->mflag |= (MFLAG_VIEW);
2650
2651                         /* Disturb on appearance */
2652                         if (do_disturb)
2653                         {
2654                                 if (disturb_pets || is_hostile(m_ptr))
2655                                         disturb(1, 0);
2656                         }
2657                 }
2658         }
2659
2660         /* The monster is not easily visible */
2661         else
2662         {
2663                 /* Change */
2664                 if (m_ptr->mflag & (MFLAG_VIEW))
2665                 {
2666                         /* Mark as not easily visible */
2667                         m_ptr->mflag &= ~(MFLAG_VIEW);
2668
2669                         /* Disturb on disappearance */
2670                         if (do_disturb)
2671                         {
2672                                 if (disturb_pets || is_hostile(m_ptr))
2673                                         disturb(1, 0);
2674                         }
2675                 }
2676         }
2677 }
2678
2679
2680 /*
2681  * This function simply updates all the (non-dead) monsters (see above).
2682  */
2683 void update_monsters(bool full)
2684 {
2685         int i;
2686
2687         /* Update each (live) monster */
2688         for (i = 1; i < m_max; i++)
2689         {
2690                 monster_type *m_ptr = &m_list[i];
2691
2692                 /* Skip dead monsters */
2693                 if (!m_ptr->r_idx) continue;
2694
2695                 /* Update the monster */
2696                 update_mon(i, full);
2697         }
2698 }
2699
2700
2701 /*
2702  * Hack -- the index of the summoning monster
2703  */
2704 static bool monster_hook_chameleon_lord(int r_idx)
2705 {
2706         monster_race *r_ptr = &r_info[r_idx];
2707         monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2708         monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2709
2710         if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2711         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2712
2713         if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2714
2715         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))
2716                 return FALSE;
2717
2718         if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2719
2720         /* Not born */
2721         if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2722         {
2723                 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
2724         }
2725
2726         /* Born now */
2727         else if (summon_specific_who > 0)
2728         {
2729                 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2730         }
2731
2732         return TRUE;
2733 }
2734
2735 static bool monster_hook_chameleon(int r_idx)
2736 {
2737         monster_race *r_ptr = &r_info[r_idx];
2738         monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2739         monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2740
2741         if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2742         if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2743         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2744         
2745         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))
2746                 return FALSE;
2747
2748         if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2749
2750         /* Not born */
2751         if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2752         {
2753                 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2754                 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2755                 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2756         }
2757
2758         /* Born now */
2759         else if (summon_specific_who > 0)
2760         {
2761                 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2762         }
2763
2764         return (*(get_monster_hook()))(r_idx);
2765 }
2766
2767
2768 void choose_new_monster(int m_idx, bool born, int r_idx)
2769 {
2770         int oldmaxhp;
2771         monster_type *m_ptr = &m_list[m_idx];
2772         monster_race *r_ptr;
2773         char old_m_name[80];
2774         bool old_unique = FALSE;
2775         int old_r_idx = m_ptr->r_idx;
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
2817         if ((r_info[old_r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) ||
2818             (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)))
2819                 p_ptr->update |= (PU_MON_LITE);
2820
2821         if (born)
2822         {
2823                 /* Sub-alignment of a chameleon */
2824                 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2825                 {
2826                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2827                         if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2828                         if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2829                 }
2830                 return;
2831         }
2832
2833         if (m_idx == p_ptr->riding)
2834         {
2835                 char m_name[80];
2836                 monster_desc(m_name, m_ptr, 0);
2837 #ifdef JP
2838                 msg_format("ÆÍÁ³%s¤¬ÊѿȤ·¤¿¡£", old_m_name);
2839 #else
2840                 msg_format("Suddenly, %s transforms!", old_m_name);
2841 #endif
2842                 if (!(r_ptr->flags7 & RF7_RIDING))
2843 #ifdef JP
2844                         if (rakuba(0, TRUE)) msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2845 #else
2846                         if (rakuba(0, TRUE)) msg_format("You have fallen from %s.", m_name);
2847 #endif
2848         }
2849
2850         /* Extract the monster base speed */
2851         m_ptr->mspeed = get_mspeed(r_ptr);
2852
2853         oldmaxhp = m_ptr->max_maxhp;
2854         /* Assign maximal hitpoints */
2855         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2856         {
2857                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2858         }
2859         else
2860         {
2861                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2862         }
2863         m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2864         m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2865 }
2866
2867
2868 /*
2869  *  Hook for Tanuki
2870  */
2871 static bool monster_hook_tanuki(int r_idx)
2872 {
2873         monster_race *r_ptr = &r_info[r_idx];
2874
2875         if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2876         if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2877         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2878         if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2879         
2880         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))
2881                 return FALSE;
2882
2883         return (*(get_monster_hook()))(r_idx);
2884 }
2885
2886
2887 /*
2888  *  Set initial racial appearance of a monster
2889  */
2890 static int initial_r_appearance(int r_idx)
2891 {
2892         int attempts = 1000;
2893
2894         int ap_r_idx;
2895         int min = MIN(base_level-5, 50);
2896
2897         if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2898                 return r_idx;
2899
2900         get_mon_num_prep(monster_hook_tanuki, NULL);
2901
2902         while (--attempts)
2903         {
2904                 ap_r_idx = get_mon_num(base_level + 10);
2905                 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2906         }
2907
2908         return r_idx;
2909 }
2910
2911
2912 /*
2913  * Get initial monster speed
2914  */
2915 byte get_mspeed(monster_race *r_ptr)
2916 {
2917         /* Extract the monster base speed */
2918         int mspeed = r_ptr->speed;
2919
2920         /* Hack -- small racial variety */
2921         if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
2922         {
2923                 /* Allow some small variation per monster */
2924                 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2925                 if (i) mspeed += rand_spread(0, i);
2926         }
2927
2928         if (mspeed > 199) mspeed = 199;
2929
2930         return (byte)mspeed;
2931 }
2932
2933
2934 /*
2935  * Attempt to place a monster of the given race at the given location.
2936  *
2937  * To give the player a sporting chance, any monster that appears in
2938  * line-of-sight and is extremely dangerous can be marked as
2939  * "FORCE_SLEEP", which will cause them to be placed with low energy,
2940  * which often (but not always) lets the player move before they do.
2941  *
2942  * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2943  *
2944  * XXX XXX XXX Use special "here" and "dead" flags for unique monsters,
2945  * remove old "cur_num" and "max_num" fields.
2946  *
2947  * XXX XXX XXX Actually, do something similar for artifacts, to simplify
2948  * the "preserve" mode, and to make the "what artifacts" flag more useful.
2949  *
2950  * This is the only function which may place a monster in the dungeon,
2951  * except for the savefile loading code.
2952  */
2953 static bool place_monster_one(int who, int y, int x, int r_idx, u32b mode)
2954 {
2955         /* Access the location */
2956         cave_type               *c_ptr = &cave[y][x];
2957
2958         monster_type    *m_ptr;
2959
2960         monster_race    *r_ptr = &r_info[r_idx];
2961
2962         cptr            name = (r_name + r_ptr->name);
2963
2964         /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
2965         if (p_ptr->wild_mode) return FALSE;
2966
2967         /* Verify location */
2968         if (!in_bounds(y, x)) return (FALSE);
2969
2970         /* Paranoia */
2971         if (!r_idx) return (FALSE);
2972
2973         /* Paranoia */
2974         if (!r_ptr->name) return (FALSE);
2975
2976         if (!(mode & PM_IGNORE_TERRAIN))
2977         {
2978                 /* Not on the Pattern */
2979                 if (pattern_tile(y, x)) return FALSE;
2980
2981                 /* Require empty space (if not ghostly) */
2982                 if (!monster_can_enter(y, x, r_ptr, 0)) return FALSE;
2983         }
2984
2985         if (!p_ptr->inside_battle)
2986         {
2987                 /* Hack -- "unique" monsters must be "unique" */
2988                 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
2989                      (r_ptr->flags7 & (RF7_NAZGUL))) &&
2990                     (r_ptr->cur_num >= r_ptr->max_num))
2991                 {
2992                         /* Cannot create */
2993                         return (FALSE);
2994                 }
2995
2996                 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
2997                     (r_ptr->cur_num >= 1))
2998                 {
2999                         return (FALSE);
3000                 }
3001
3002                 if (r_idx == MON_BANORLUPART)
3003                 {
3004                         if (r_info[MON_BANOR].cur_num > 0) return FALSE;
3005                         if (r_info[MON_LUPART].cur_num > 0) return FALSE;
3006                 }
3007
3008                 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
3009                 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (dun_level < r_ptr->level) &&
3010                     (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
3011                 {
3012                         /* Cannot create */
3013                         return (FALSE);
3014                 }
3015         }
3016
3017         if (quest_number(dun_level))
3018         {
3019                 int hoge = quest_number(dun_level);
3020                 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
3021                 {
3022                         if(r_idx == quest[hoge].r_idx)
3023                         {
3024                                 int number_mon, i2, j2;
3025                                 number_mon = 0;
3026
3027                                 /* Count all quest monsters */
3028                                 for (i2 = 0; i2 < cur_wid; ++i2)
3029                                         for (j2 = 0; j2 < cur_hgt; j2++)
3030                                                 if (cave[j2][i2].m_idx > 0)
3031                                                         if (m_list[cave[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
3032                                                                 number_mon++;
3033                                 if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
3034                                         return FALSE;
3035                         }
3036                 }
3037         }
3038
3039         if (is_glyph_grid(c_ptr))
3040         {
3041                 if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
3042                 {
3043                         /* Describe observable breakage */
3044                         if (c_ptr->info & CAVE_MARK)
3045                         {
3046 #ifdef JP
3047 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3048 #else
3049                                 msg_print("The rune of protection is broken!");
3050 #endif
3051
3052                         }
3053
3054                         /* Forget the rune */
3055                         c_ptr->info &= ~(CAVE_MARK);
3056
3057                         /* Break the rune */
3058                         c_ptr->info &= ~(CAVE_OBJECT);
3059                         c_ptr->mimic = 0;
3060
3061                         /* Notice */
3062                         note_spot(y, x);
3063                 }
3064                 else return FALSE;
3065         }
3066
3067         /* Powerful monster */
3068         if (r_ptr->level > dun_level)
3069         {
3070                 /* Unique monsters */
3071                 if (r_ptr->flags1 & (RF1_UNIQUE))
3072                 {
3073                         /* Message for cheaters */
3074 #ifdef JP
3075                         if (cheat_hear) msg_format("¿¼ÁؤΥæ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3076 #else
3077                         if (cheat_hear) msg_format("Deep Unique (%s).", name);
3078 #endif
3079                 }
3080
3081                 /* Normal monsters */
3082                 else
3083                 {
3084                         /* Message for cheaters */
3085 #ifdef JP
3086                         if (cheat_hear) msg_format("¿¼ÁؤΥâ¥ó¥¹¥¿¡¼ (%s)¡£", name);
3087 #else
3088                         if (cheat_hear) msg_format("Deep Monster (%s).", name);
3089 #endif
3090                 }
3091         }
3092
3093         /* Note the monster */
3094         else if (r_ptr->flags1 & (RF1_UNIQUE))
3095         {
3096                 /* Unique monsters induce message */
3097 #ifdef JP
3098                 if (cheat_hear) msg_format("¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3099 #else
3100                 if (cheat_hear) msg_format("Unique (%s).", name);
3101 #endif
3102
3103         }
3104
3105         if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL) || (r_ptr->level < 10)) mode &= ~PM_KAGE;
3106
3107         /* Make a new monster */
3108         c_ptr->m_idx = m_pop();
3109         hack_m_idx_ii = c_ptr->m_idx;
3110
3111         /* Mega-Hack -- catch "failure" */
3112         if (!c_ptr->m_idx) return (FALSE);
3113
3114
3115         /* Get a new monster record */
3116         m_ptr = &m_list[c_ptr->m_idx];
3117
3118         /* Save the race */
3119         m_ptr->r_idx = r_idx;
3120         m_ptr->ap_r_idx = initial_r_appearance(r_idx);
3121
3122         /* Sub-alignment of a monster */
3123         if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
3124                 m_ptr->sub_align = m_list[who].sub_align;
3125         else
3126         {
3127                 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3128                 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
3129                 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
3130         }
3131
3132         /* Place the monster at the location */
3133         m_ptr->fy = y;
3134         m_ptr->fx = x;
3135
3136
3137         /* No "damage" yet */
3138         m_ptr->stunned = 0;
3139         m_ptr->confused = 0;
3140         m_ptr->monfear = 0;
3141
3142         /* Unknown distance */
3143         m_ptr->cdis = 0;
3144
3145         reset_target(m_ptr);
3146
3147         m_ptr->nickname = 0;
3148
3149         m_ptr->exp = 0;
3150
3151         /* No flags */
3152         m_ptr->mflag = 0;
3153         m_ptr->mflag2 = 0;
3154
3155
3156         /* Your pet summons its pet. */
3157         if (who > 0 && is_pet(&m_list[who]))
3158         {
3159                 mode |= PM_FORCE_PET;
3160                 m_ptr->parent_m_idx = who;
3161         }
3162         else
3163         {
3164                 m_ptr->parent_m_idx = 0;
3165         }
3166
3167         if (r_ptr->flags7 & RF7_CHAMELEON)
3168         {
3169                 choose_new_monster(c_ptr->m_idx, TRUE, 0);
3170                 r_ptr = &r_info[m_ptr->r_idx];
3171                 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
3172
3173                 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
3174                 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
3175                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3176         }
3177         else if ((mode & PM_KAGE) && !(mode & PM_FORCE_PET))
3178         {
3179                 m_ptr->ap_r_idx = MON_KAGE;
3180                 m_ptr->mflag2 |= MFLAG2_KAGE;
3181         }
3182
3183         if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
3184
3185         /* Not visible */
3186         m_ptr->ml = FALSE;
3187
3188         /* Pet? */
3189         if (mode & PM_FORCE_PET)
3190         {
3191                 set_pet(m_ptr);
3192         }
3193         /* Friendly? */
3194         else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
3195                  (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
3196         {
3197                 if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
3198         }
3199
3200         /* Assume no sleeping */
3201         m_ptr->csleep = 0;
3202
3203         /* Enforce sleeping if needed */
3204         if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
3205         {
3206                 int val = r_ptr->sleep;
3207                 m_ptr->csleep = ((val * 2) + randint1(val * 10));
3208         }
3209
3210         /* Assign maximal hitpoints */
3211         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
3212         {
3213                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
3214         }
3215         else
3216         {
3217                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
3218         }
3219
3220         /* Monsters have double hitpoints in Nightmare mode */
3221         if (ironman_nightmare)
3222         {
3223                 u32b hp = m_ptr->max_maxhp * 2L;
3224
3225                 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
3226         }
3227
3228         m_ptr->maxhp = m_ptr->max_maxhp;
3229
3230         /* And start out fully healthy */
3231         if (m_ptr->r_idx == MON_WOUNDED_BEAR)
3232                 m_ptr->hp = m_ptr->maxhp / 2;
3233         else m_ptr->hp = m_ptr->maxhp;
3234
3235
3236         /* Extract the monster base speed */
3237         m_ptr->mspeed = get_mspeed(r_ptr);
3238
3239         if (mode & PM_HASTE) m_ptr->fast = 100;
3240
3241         /* Give a random starting energy */
3242         if (!ironman_nightmare)
3243         {
3244                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
3245         }
3246         else
3247         {
3248                 /* Nightmare monsters are more prepared */
3249                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
3250         }
3251
3252         /* Force monster to wait for player, unless in Nightmare mode */
3253         if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
3254         {
3255                 /* Monster is still being nice */
3256                 m_ptr->mflag |= (MFLAG_NICE);
3257
3258                 /* Must repair monsters */
3259                 repair_monsters = TRUE;
3260         }
3261
3262         /* Hack -- see "process_monsters()" */
3263         if (c_ptr->m_idx < hack_m_idx)
3264         {
3265                 /* Monster is still being born */
3266                 m_ptr->mflag |= (MFLAG_BORN);
3267         }
3268
3269
3270         if (r_ptr->flags7 & RF7_SELF_LD_MASK)
3271                 p_ptr->update |= (PU_MON_LITE);
3272         else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !m_ptr->csleep)
3273                 p_ptr->update |= (PU_MON_LITE);
3274
3275         /* Update the monster */
3276         update_mon(c_ptr->m_idx, TRUE);
3277
3278
3279         /* Count the monsters on the level */
3280         real_r_ptr(m_ptr)->cur_num++;
3281
3282         /*
3283          * Memorize location of the unique monster in saved floors.
3284          * A unique monster move from old saved floor.
3285          */
3286         if (character_dungeon &&
3287             ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)))
3288                 real_r_ptr(m_ptr)->floor_id = p_ptr->floor_id;
3289
3290         /* Hack -- Count the number of "reproducers" */
3291         if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
3292
3293         if (need_mproc(m_ptr)) mproc_add(c_ptr->m_idx);
3294         else m_ptr->mproc_idx = 0;
3295
3296         /* Hack -- Notice new multi-hued monsters */
3297         {
3298                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3299                 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
3300                         shimmer_monsters = TRUE;
3301         }
3302
3303         if (p_ptr->warning && character_dungeon)
3304         {
3305                 if (r_ptr->flags1 & RF1_UNIQUE)
3306                 {
3307                         cptr color;
3308                         object_type *o_ptr;
3309                         char o_name[MAX_NLEN];
3310
3311                         if (r_ptr->level > p_ptr->lev + 30)
3312 #ifdef JP
3313                                 color = "¹õ¤¯";
3314 #else
3315                                 color = "black";
3316 #endif
3317                         else if (r_ptr->level > p_ptr->lev + 15)
3318 #ifdef JP
3319                                 color = "»ç¿§¤Ë";
3320 #else
3321                                 color = "purple";
3322 #endif
3323                         else if (r_ptr->level > p_ptr->lev + 5)
3324 #ifdef JP
3325                                 color = "¥ë¥Ó¡¼¿§¤Ë";
3326 #else
3327                                 color = "deep red";
3328 #endif
3329                         else if (r_ptr->level > p_ptr->lev - 5)
3330 #ifdef JP
3331                                 color = "ÀÖ¤¯";
3332 #else
3333                                 color = "red";
3334 #endif
3335                         else if (r_ptr->level > p_ptr->lev - 15)
3336 #ifdef JP
3337                                 color = "¥Ô¥ó¥¯¿§¤Ë";
3338 #else
3339                                 color = "pink";
3340 #endif
3341                         else
3342 #ifdef JP
3343                                 color = "Çò¤¯";
3344 #else
3345                                 color = "white";
3346 #endif
3347
3348                         o_ptr = choose_warning_item();
3349                         if (o_ptr)
3350                         {
3351                                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3352 #ifdef JP
3353                                 msg_format("%s¤Ï%s¸÷¤Ã¤¿¡£", o_name, color);
3354 #else
3355                                 msg_format("%s glows %s.", o_name, color);
3356 #endif
3357                         }
3358                         else
3359                         {
3360 #ifdef JP
3361                                 msg_format("s%¸÷¤ëʪ¤¬Æ¬¤ËÉ⤫¤ó¤À¡£", color);
3362 #else
3363                                 msg_format("An %s image forms in your mind.");
3364 #endif
3365                         }
3366                 }
3367         }
3368
3369         if (is_explosive_rune_grid(c_ptr))
3370         {
3371                 /* Break the ward */
3372                 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3373                 {
3374                         /* Describe observable breakage */
3375                         if (c_ptr->info & CAVE_MARK)
3376                         {
3377 #ifdef JP
3378 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3379 #else
3380                                 msg_print("The rune explodes!");
3381 #endif
3382
3383                                 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);
3384                         }
3385                 }
3386                 else
3387                 {
3388 #ifdef JP
3389 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3390 #else
3391                         msg_print("An explosive rune was disarmed.");
3392 #endif
3393                 }
3394
3395                 /* Forget the rune */
3396                 c_ptr->info &= ~(CAVE_MARK);
3397
3398                 /* Break the rune */
3399                 c_ptr->info &= ~(CAVE_OBJECT);
3400                 c_ptr->mimic = 0;
3401
3402                 note_spot(y, x);
3403                 lite_spot(y, x);
3404         }
3405
3406         /* Success */
3407         return (TRUE);
3408 }
3409
3410
3411 /*
3412  *  improved version of scatter() for place monster
3413  */
3414
3415 #define MON_SCAT_MAXD 10
3416
3417 static bool mon_scatter(int r_idx, int *yp, int *xp, int y, int x, int max_dist)
3418 {
3419         int place_x[MON_SCAT_MAXD];
3420         int place_y[MON_SCAT_MAXD];
3421         int num[MON_SCAT_MAXD];
3422         int i;
3423         int nx, ny;
3424
3425         if (max_dist >= MON_SCAT_MAXD)
3426                 return FALSE;
3427
3428         for (i = 0; i < MON_SCAT_MAXD; i++)
3429                 num[i] = 0;
3430
3431         for (nx = x - max_dist; nx <= x + max_dist; nx++)
3432         {
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 projection" */
3439                         if (!projectable(y, x, ny, nx)) continue;
3440
3441                         if (r_idx > 0)
3442                         {
3443                                 monster_race *r_ptr = &r_info[r_idx];
3444
3445                                 /* Require empty space (if not ghostly) */
3446                                 if (!monster_can_enter(ny, nx, r_ptr, 0))
3447                                         continue;
3448                         }
3449                         else
3450                         {
3451                                 /* Walls and Monsters block flow */
3452                                 if (!cave_empty_bold2(ny, nx)) continue;
3453
3454                                 /* ... nor on the Pattern */
3455                                 if (pattern_tile(ny, nx)) continue;
3456                         }
3457
3458                         i = distance(y, x, ny, nx);
3459
3460                         if (i > max_dist)
3461                                 continue;
3462
3463                         num[i]++;
3464
3465                         /* random swap */
3466                         if (one_in_(num[i]))
3467                         {
3468                                 place_x[i] = nx;
3469                                 place_y[i] = ny;
3470                         }
3471                 }
3472         }
3473
3474         i = 0;
3475         while (i < MON_SCAT_MAXD && 0 == num[i])
3476                 i++;
3477         if (i >= MON_SCAT_MAXD)
3478                 return FALSE;
3479
3480         *xp = place_x[i];
3481         *yp = place_y[i];
3482
3483         return TRUE;
3484 }
3485
3486
3487 /*
3488  * Maximum size of a group of monsters
3489  */
3490 #define GROUP_MAX       32
3491
3492
3493 /*
3494  * Attempt to place a "group" of monsters around the given location
3495  */
3496 static bool place_monster_group(int who, int y, int x, int r_idx, u32b mode)
3497 {
3498         monster_race *r_ptr = &r_info[r_idx];
3499
3500         int n, i;
3501         int total = 0, extra = 0;
3502
3503         int hack_n = 0;
3504
3505         byte hack_y[GROUP_MAX];
3506         byte hack_x[GROUP_MAX];
3507
3508
3509         /* Pick a group size */
3510         total = randint1(10);
3511
3512         /* Hard monsters, small groups */
3513         if (r_ptr->level > dun_level)
3514         {
3515                 extra = r_ptr->level - dun_level;
3516                 extra = 0 - randint1(extra);
3517         }
3518
3519         /* Easy monsters, large groups */
3520         else if (r_ptr->level < dun_level)
3521         {
3522                 extra = dun_level - r_ptr->level;
3523                 extra = randint1(extra);
3524         }
3525
3526         /* Hack -- limit group reduction */
3527         if (extra > 9) extra = 9;
3528
3529         /* Modify the group size */
3530         total += extra;
3531
3532         /* Minimum size */
3533         if (total < 1) total = 1;
3534
3535         /* Maximum size */
3536         if (total > GROUP_MAX) total = GROUP_MAX;
3537
3538
3539         /* Start on the monster */
3540         hack_n = 1;
3541         hack_x[0] = x;
3542         hack_y[0] = y;
3543
3544         /* Puddle monsters, breadth first, up to total */
3545         for (n = 0; (n < hack_n) && (hack_n < total); n++)
3546         {
3547                 /* Grab the location */
3548                 int hx = hack_x[n];
3549                 int hy = hack_y[n];
3550
3551                 /* Check each direction, up to total */
3552                 for (i = 0; (i < 8) && (hack_n < total); i++)
3553                 {
3554                         int mx, my;
3555
3556                         scatter(&my, &mx, hy, hx, 4, 0);
3557
3558                         /* Walls and Monsters block flow */
3559                         if (!cave_empty_bold2(my, mx)) continue;
3560
3561                         /* Attempt to place another monster */
3562                         if (place_monster_one(who, my, mx, r_idx, mode))
3563                         {
3564                                 /* Add it to the "hack" set */
3565                                 hack_y[hack_n] = my;
3566                                 hack_x[hack_n] = mx;
3567                                 hack_n++;
3568                         }
3569                 }
3570         }
3571
3572
3573         /* Success */
3574         return (TRUE);
3575 }
3576
3577
3578 /*
3579  * Hack -- help pick an escort type
3580  */
3581 static int place_monster_idx = 0;
3582 static int place_monster_m_idx = 0;
3583
3584 /*
3585  * Hack -- help pick an escort type
3586  */
3587 static bool place_monster_okay(int r_idx)
3588 {
3589         monster_race *r_ptr = &r_info[place_monster_idx];
3590         monster_type *m_ptr = &m_list[place_monster_m_idx];
3591
3592         monster_race *z_ptr = &r_info[r_idx];
3593
3594         /* Hack - Escorts have to have the same dungeon flag */
3595         if (mon_hook_dungeon(place_monster_idx) != mon_hook_dungeon(r_idx)) return (FALSE);
3596
3597         /* Require similar "race" */
3598         if (z_ptr->d_char != r_ptr->d_char) return (FALSE);
3599
3600         /* Skip more advanced monsters */
3601         if (z_ptr->level > r_ptr->level) return (FALSE);
3602
3603         /* Skip unique monsters */
3604         if (z_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3605
3606         /* Paranoia -- Skip identical monsters */
3607         if (place_monster_idx == r_idx) return (FALSE);
3608
3609         /* Skip different alignment */
3610         if (monster_has_hostile_align(m_ptr, 0, 0, z_ptr)) return FALSE;
3611
3612         if (r_ptr->flags7 & RF7_FRIENDLY)
3613         {
3614                 if (monster_has_hostile_align(NULL, 1, -1, z_ptr)) return FALSE;
3615         }
3616
3617         if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3618                 return FALSE;
3619
3620         /* Okay */
3621         return (TRUE);
3622 }
3623
3624
3625 /*
3626  * Attempt to place a monster of the given race at the given location
3627  *
3628  * Note that certain monsters are now marked as requiring "friends".
3629  * These monsters, if successfully placed, and if the "grp" parameter
3630  * is TRUE, will be surrounded by a "group" of identical monsters.
3631  *
3632  * Note that certain monsters are now marked as requiring an "escort",
3633  * which is a collection of monsters with similar "race" but lower level.
3634  *
3635  * Some monsters induce a fake "group" flag on their escorts.
3636  *
3637  * Note the "bizarre" use of non-recursion to prevent annoying output
3638  * when running a code profiler.
3639  *
3640  * Note the use of the new "monster allocation table" code to restrict
3641  * the "get_mon_num()" function to "legal" escort types.
3642  */
3643 bool place_monster_aux(int who, int y, int x, int r_idx, u32b mode)
3644 {
3645         int             i;
3646         monster_race    *r_ptr = &r_info[r_idx];
3647
3648         if (!(mode & PM_NO_KAGE) && one_in_(333))
3649                 mode |= PM_KAGE;
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], 0))
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)
3862                 {
3863                         if (!cave_empty_bold2(y, x)) continue;
3864                 }
3865                 else
3866                 {
3867                         if (!cave_empty_bold(y, x)) 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 (!mon_hook_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         /* Use the player's alignment */
3943         else if (summon_specific_who < 0)
3944         {
3945                 /* Do not summon enemies of the pets */
3946                 if (monster_has_hostile_align(NULL, 10, -10, r_ptr))
3947                 {
3948                         if (!one_in_(ABS(p_ptr->align) / 2 + 1)) return FALSE;
3949                 }
3950         }
3951
3952         /* Hack -- no specific type specified */
3953         if (!summon_specific_type) return (TRUE);
3954
3955         if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL))) return FALSE;
3956
3957         if ((summon_specific_who < 0) &&
3958             ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
3959             monster_has_hostile_align(NULL, 10, -10, r_ptr))
3960                 return FALSE;
3961
3962         if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[dungeon_type].flags1 & DF1_CHAMELEON)) return TRUE;
3963
3964         return (summon_specific_aux(r_idx));
3965 }
3966
3967
3968 /*
3969  * Place a monster (of the specified "type") near the given
3970  * location.  Return TRUE if a monster was actually summoned.
3971  *
3972  * We will attempt to place the monster up to 10 times before giving up.
3973  *
3974  * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
3975  * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
3976  * Note: None of the other summon codes will ever summon Unique's.
3977  *
3978  * This function has been changed.  We now take the "monster level"
3979  * of the summoning monster as a parameter, and use that, along with
3980  * the current dungeon level, to help determine the level of the
3981  * desired monster.  Note that this is an upper bound, and also
3982  * tends to "prefer" monsters of that level.  Currently, we use
3983  * the average of the dungeon and monster levels, and then add
3984  * five to allow slight increases in monster power.
3985  *
3986  * Note that we use the new "monster allocation table" creation code
3987  * to restrict the "get_mon_num()" function to the set of "legal"
3988  * monsters, making this function much faster and more reliable.
3989  *
3990  * Note that this function may not succeed, though this is very rare.
3991  */
3992 bool summon_specific(int who, int y1, int x1, int lev, int type, u32b mode)
3993 {
3994         int x, y, r_idx;
3995
3996         if (p_ptr->inside_arena) return (FALSE);
3997
3998         if (!mon_scatter(0, &y, &x, y1, x1, 2)) return FALSE;
3999
4000         /* Save the summoner */
4001         summon_specific_who = who;
4002
4003         /* Save the "summon" type */
4004         summon_specific_type = type;
4005
4006         summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
4007
4008         /* Prepare allocation table */
4009         get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
4010
4011         /* Pick a monster, using the level calculation */
4012         r_idx = get_mon_num((dun_level + lev) / 2 + 5);
4013
4014         /* Handle failure */
4015         if (!r_idx)
4016         {
4017                 summon_specific_type = 0;
4018                 return (FALSE);
4019         }
4020
4021         if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
4022
4023         /* Attempt to place the monster (awake, allow groups) */
4024         if (!place_monster_aux(who, y, x, r_idx, mode))
4025         {
4026                 summon_specific_type = 0;
4027                 return (FALSE);
4028         }
4029
4030         summon_specific_type = 0;
4031         /* Success */
4032         return (TRUE);
4033 }
4034
4035 /* A "dangerous" function, creates a pet of the specified type */
4036 bool summon_named_creature (int who, int oy, int ox, int r_idx, u32b mode)
4037 {
4038         int x, y;
4039
4040         /* Paranoia */
4041         /* if (!r_idx) return; */
4042
4043         /* Prevent illegal monsters */
4044         if (r_idx >= max_r_idx) return FALSE;
4045
4046         if (p_ptr->inside_arena) return FALSE;
4047
4048         if (!mon_scatter(r_idx, &y, &x, oy, ox, 2)) return FALSE;
4049
4050         /* Place it (allow groups) */
4051         return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
4052 }
4053
4054
4055 /*
4056  * Let the given monster attempt to reproduce.
4057  *
4058  * Note that "reproduction" REQUIRES empty space.
4059  */
4060 bool multiply_monster(int m_idx, bool clone, u32b mode)
4061 {
4062         monster_type    *m_ptr = &m_list[m_idx];
4063
4064         int y, x;
4065
4066         if (!mon_scatter(m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
4067                 return FALSE;
4068
4069         if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
4070
4071         /* Hack -- Shadower spawns Shadower */
4072         if (m_ptr->mflag2 & MFLAG2_KAGE) mode |= PM_KAGE;
4073
4074         /* Create a new monster (awake, no groups) */
4075         if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE)))
4076                 return FALSE;
4077
4078         /* Hack -- Transfer "clone" flag */
4079         if (clone || (m_ptr->smart & SM_CLONED))
4080         {
4081                 m_list[hack_m_idx_ii].smart |= SM_CLONED;
4082                 m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
4083         }
4084
4085         /* Hack -- Appearance transfer */
4086         if (!is_original_ap(m_ptr)) m_list[hack_m_idx_ii].ap_r_idx = m_ptr->ap_r_idx;
4087
4088         return TRUE;
4089 }
4090
4091
4092
4093
4094
4095 /*
4096  * Dump a message describing a monster's reaction to damage
4097  *
4098  * Technically should attempt to treat "Beholder"'s as jelly's
4099  */
4100 void message_pain(int m_idx, int dam)
4101 {
4102         long oldhp, newhp, tmp;
4103         int percentage;
4104
4105         monster_type *m_ptr = &m_list[m_idx];
4106         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4107
4108         char m_name[80];
4109
4110
4111         /* Get the monster name */
4112         monster_desc(m_name, m_ptr, 0);
4113
4114         /* Notice non-damage */
4115         if (dam == 0)
4116         {
4117 #ifdef JP
4118                 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Æ¤¤¤Ê¤¤¡£", m_name);
4119 #else
4120                 msg_format("%^s is unharmed.", m_name);
4121 #endif
4122
4123                 return;
4124         }
4125
4126         /* Note -- subtle fix -CFT */
4127         newhp = (long)(m_ptr->hp);
4128         oldhp = newhp + (long)(dam);
4129         tmp = (newhp * 100L) / oldhp;
4130         percentage = (int)(tmp);
4131
4132
4133         /* Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs */
4134         if (my_strchr(",ejmvwQ", r_ptr->d_char))
4135         {
4136 #ifdef JP
4137                 if (percentage > 95)
4138                         msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4139                 else if (percentage > 75)
4140                         msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4141                 else if (percentage > 50)
4142                         msg_format("%^s¤Ï½Ì¤³¤Þ¤Ã¤¿¡£", m_name);
4143                 else if (percentage > 35)
4144                         msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4145                 else if (percentage > 20)
4146                         msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4147                 else if (percentage > 10)
4148                         msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4149                 else
4150                         msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4151 #else
4152                 if (percentage > 95)
4153                         msg_format("%^s barely notices.", m_name);
4154                 else if (percentage > 75)
4155                         msg_format("%^s flinches.", m_name);
4156                 else if (percentage > 50)
4157                         msg_format("%^s squelches.", m_name);
4158                 else if (percentage > 35)
4159                         msg_format("%^s quivers in pain.", m_name);
4160                 else if (percentage > 20)
4161                         msg_format("%^s writhes about.", m_name);
4162                 else if (percentage > 10)
4163                         msg_format("%^s writhes in agony.", m_name);
4164                 else
4165                         msg_format("%^s jerks limply.", m_name);
4166 #endif
4167
4168         }
4169
4170
4171         /* Fish */
4172         else if (my_strchr("l", r_ptr->d_char))
4173         {
4174                 if (percentage > 95)
4175 #ifdef JP
4176 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4177 #else
4178                         msg_format("%^s barely notices.", m_name);
4179 #endif
4180                 else if (percentage > 75)
4181 #ifdef JP
4182 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4183 #else
4184                         msg_format("%^s flinches.", m_name);
4185 #endif
4186                 else if (percentage > 50)
4187 #ifdef JP
4188 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4189 #else
4190                         msg_format("%^s hesitates.", m_name);
4191 #endif
4192                 else if (percentage > 35)
4193 #ifdef JP
4194 msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4195 #else
4196                         msg_format("%^s quivers in pain.", m_name);
4197 #endif
4198                 else if (percentage > 20)
4199 #ifdef JP
4200 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4201 #else
4202                         msg_format("%^s writhes about.", m_name);
4203 #endif
4204                 else if (percentage > 10)
4205 #ifdef JP
4206 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4207 #else
4208                         msg_format("%^s writhes in agony.", m_name);
4209 #endif
4210                 else
4211 #ifdef JP
4212 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4213 #else
4214                         msg_format("%^s jerks limply.", m_name);
4215 #endif
4216         }
4217
4218
4219         /* Golems, Walls, Doors, Stairs */
4220         else if (my_strchr("g#+<>", r_ptr->d_char))
4221         {
4222                 if (percentage > 95)
4223 #ifdef JP
4224 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4225 #else
4226                         msg_format("%^s ignores the attack.", m_name);
4227 #endif
4228                 else if (percentage > 75)
4229 #ifdef JP
4230 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4231 #else
4232                         msg_format("%^s shrugs off the attack.", m_name);
4233 #endif
4234                 else if (percentage > 50)
4235 #ifdef JP
4236 msg_format("%^s¤ÏÍëÌĤΤ褦¤ËËʤ¨¤¿¡£", m_name);
4237 #else
4238                         msg_format("%^s roars thunderously.", m_name);
4239 #endif
4240                 else if (percentage > 35)
4241 #ifdef JP
4242 msg_format("%^s¤Ï¶ì¤·¤²¤ËËʤ¨¤¿¡£", m_name);
4243 #else
4244                         msg_format("%^s rumbles.", m_name);
4245 #endif
4246                 else if (percentage > 20)
4247 #ifdef JP
4248 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4249 #else
4250                         msg_format("%^s grunts.", m_name);
4251 #endif
4252                 else if (percentage > 10)
4253 #ifdef JP
4254 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4255 #else
4256                         msg_format("%^s hesitates.", m_name);
4257 #endif
4258                 else
4259 #ifdef JP
4260 msg_format("%^s¤Ï¤¯¤·¤ã¤¯¤·¤ã¤Ë¤Ê¤Ã¤¿¡£", m_name);
4261 #else
4262                         msg_format("%^s crumples.", m_name);
4263 #endif
4264         }
4265
4266
4267         /* Snakes, Hydrae, Reptiles, Mimics */
4268         else if (my_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char))
4269         {
4270                 if (percentage > 95)
4271 #ifdef JP
4272 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4273 #else
4274                         msg_format("%^s barely notices.", m_name);
4275 #endif
4276                 else if (percentage > 75)
4277 #ifdef JP
4278 msg_format("%^s¤Ï¥·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4279 #else
4280                         msg_format("%^s hisses.", m_name);
4281 #endif
4282                 else if (percentage > 50)
4283 #ifdef JP
4284 msg_format("%^s¤ÏÅܤäÆƬ¤ò¾å¤²¤¿¡£", m_name);
4285 #else
4286                         msg_format("%^s rears up in anger.", m_name);
4287 #endif
4288                 else if (percentage > 35)
4289 #ifdef JP
4290 msg_format("%^s¤ÏÌÔÁ³¤È°Ò³Å¤·¤¿¡£", m_name);
4291 #else
4292                         msg_format("%^s hisses furiously.", m_name);
4293 #endif
4294                 else if (percentage > 20)
4295 #ifdef JP
4296 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4297 #else
4298                         msg_format("%^s writhes about.", m_name);
4299 #endif
4300                 else if (percentage > 10)
4301 #ifdef JP
4302 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4303 #else
4304                         msg_format("%^s writhes in agony.", m_name);
4305 #endif
4306                 else
4307 #ifdef JP
4308 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4309 #else
4310                         msg_format("%^s jerks limply.", m_name);
4311 #endif
4312         }
4313
4314
4315         /* Felines */
4316         else if (my_strchr("f", r_ptr->d_char))
4317         {
4318                 if (percentage > 95)
4319 #ifdef JP
4320 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4321 #else
4322                         msg_format("%^s shrugs off the attack.", m_name);
4323 #endif
4324                 else if (percentage > 75)
4325 #ifdef JP
4326 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4327 #else
4328                         msg_format("%^s roars.", m_name);
4329 #endif
4330                 else if (percentage > 50)
4331 #ifdef JP
4332 msg_format("%^s¤ÏÅܤäÆËʤ¨¤¿¡£", m_name);
4333 #else
4334                         msg_format("%^s growls angrily.", m_name);
4335 #endif
4336                 else if (percentage > 35)
4337 #ifdef JP
4338 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4339 #else
4340                         msg_format("%^s hisses with pain.", m_name);
4341 #endif
4342                 else if (percentage > 20)
4343 #ifdef JP
4344 msg_format("%^s¤ÏÄˤߤǼ塹¤·¤¯ÌĤ¤¤¿¡£", m_name);
4345 #else
4346                         msg_format("%^s mewls in pain.", m_name);
4347 #endif
4348                 else if (percentage > 10)
4349 #ifdef JP
4350 msg_format("%^s¤Ï¶ìÄˤˤ¦¤á¤¤¤¿¡£", m_name);
4351 #else
4352                         msg_format("%^s hisses in agony.", m_name);
4353 #endif
4354                 else
4355 #ifdef JP
4356 msg_format("%s¤Ï°¥¤ì¤ÊÌĤ­À¼¤ò½Ð¤·¤¿¡£", m_name);
4357 #else
4358                         msg_format("%^s mewls pitifully.", m_name);
4359 #endif
4360         }
4361
4362
4363         /* Ants, Centipedes, Flies, Insects, Beetles, Spiders */
4364         else if (my_strchr("acFIKS", r_ptr->d_char))
4365         {
4366                 if (percentage > 95)
4367 #ifdef JP
4368 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4369 #else
4370                         msg_format("%^s ignores the attack.", m_name);
4371 #endif
4372                 else if (percentage > 75)
4373 #ifdef JP
4374 msg_format("%^s¤Ï¥­¡¼¥­¡¼ÌĤ¤¤¿¡£", m_name);
4375 #else
4376                         msg_format("%^s chitters.", m_name);
4377 #endif
4378
4379                 else if (percentage > 50)
4380 #ifdef JP
4381 msg_format("%^s¤Ï¥è¥í¥è¥íƨ¤²²ó¤Ã¤¿¡£", m_name);
4382 #else
4383                         msg_format("%^s scuttles about.", m_name);
4384 #endif
4385
4386                 else if (percentage > 35)
4387 #ifdef JP
4388 msg_format("%^s¤Ï¤¦¤ë¤µ¤¯ÌĤ¤¤¿¡£", m_name);
4389 #else
4390                         msg_format("%^s twitters.", m_name);
4391 #endif
4392
4393                 else if (percentage > 20)
4394 #ifdef JP
4395 msg_format("%^s¤ÏÄˤߤËáÛÚ»¤·¤¿¡£", m_name);
4396 #else
4397                         msg_format("%^s jerks in pain.", m_name);
4398 #endif
4399
4400                 else if (percentage > 10)
4401 #ifdef JP
4402 msg_format("%^s¤Ï¶ìÄˤÇáÛÚ»¤·¤¿¡£", m_name);
4403 #else
4404                         msg_format("%^s jerks in agony.", m_name);
4405 #endif
4406
4407                 else
4408 #ifdef JP
4409 msg_format("%^s¤Ï¥Ô¥¯¥Ô¥¯¤Ò¤­¤Ä¤Ã¤¿¡£", m_name);
4410 #else
4411                         msg_format("%^s twitches.", m_name);
4412 #endif
4413
4414         }
4415
4416
4417         /* Birds */
4418         else if (my_strchr("B", r_ptr->d_char))
4419         {
4420                 if (percentage > 95)
4421 #ifdef JP
4422 msg_format("%^s¤Ï¤µ¤¨¤º¤Ã¤¿¡£", m_name);
4423 #else
4424                         msg_format("%^s chirps.", m_name);
4425 #endif
4426
4427                 else if (percentage > 75)
4428 #ifdef JP
4429 msg_format("%^s¤Ï¥Ô¡¼¥Ô¡¼ÌĤ¤¤¿¡£", m_name);
4430 #else
4431                         msg_format("%^s twitters.", m_name);
4432 #endif
4433
4434                 else if (percentage > 50)
4435 #ifdef JP
4436 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ¤¤¿¡£", m_name);
4437 #else
4438                         msg_format("%^s squawks.", m_name);
4439 #endif
4440
4441                 else if (percentage > 35)
4442 #ifdef JP
4443 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ­¤ï¤á¤¤¤¿¡£", m_name);
4444 #else
4445                         msg_format("%^s chatters.", m_name);
4446 #endif
4447
4448                 else if (percentage > 20)
4449 #ifdef JP
4450 msg_format("%^s¤Ï¶ì¤·¤ó¤À¡£", m_name);
4451 #else
4452                         msg_format("%^s jeers.", m_name);
4453 #endif
4454
4455                 else if (percentage > 10)
4456 #ifdef JP
4457 msg_format("%^s¤Ï¤Î¤¿¤¦¤Á²ó¤Ã¤¿¡£", m_name);
4458 #else
4459                         msg_format("%^s flutters about.", m_name);
4460 #endif
4461
4462                 else
4463 #ifdef JP
4464 msg_format("%^s¤Ï¥­¡¼¥­¡¼¤ÈÌĤ­¶«¤ó¤À¡£", m_name);
4465 #else
4466                         msg_format("%^s squeaks.", m_name);
4467 #endif
4468
4469         }
4470
4471
4472         /* Dragons, Demons, High Undead */
4473         else if (my_strchr("duDLUW", r_ptr->d_char))
4474         {
4475                 if (percentage > 95)
4476 #ifdef JP
4477 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4478 #else
4479                         msg_format("%^s ignores the attack.", m_name);
4480 #endif
4481
4482                 else if (percentage > 75)
4483 #ifdef JP
4484 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4485 #else
4486                         msg_format("%^s flinches.", m_name);
4487 #endif
4488
4489                 else if (percentage > 50)
4490 #ifdef JP
4491 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4492 #else
4493                         msg_format("%^s hisses in pain.", m_name);
4494 #endif
4495
4496                 else if (percentage > 35)
4497 #ifdef JP
4498 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4499 #else
4500                         msg_format("%^s snarls with pain.", m_name);
4501 #endif
4502
4503                 else if (percentage > 20)
4504 #ifdef JP
4505 msg_format("%^s¤ÏÄˤߤËËʤ¨¤¿¡£", m_name);
4506 #else
4507                         msg_format("%^s roars with pain.", m_name);
4508 #endif
4509
4510                 else if (percentage > 10)
4511 #ifdef JP
4512 msg_format("%^s¤Ï¶ì¤·¤²¤Ë¶«¤ó¤À¡£", m_name);
4513 #else
4514                         msg_format("%^s gasps.", m_name);
4515 #endif
4516
4517                 else
4518 #ifdef JP
4519 msg_format("%^s¤Ï¼å¡¹¤·¤¯¤¦¤Ê¤Ã¤¿¡£", m_name);
4520 #else
4521                         msg_format("%^s snarls feebly.", m_name);
4522 #endif
4523
4524         }
4525
4526
4527         /* Skeletons */
4528         else if (my_strchr("s", r_ptr->d_char))
4529         {
4530                 if (percentage > 95)
4531 #ifdef JP
4532 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4533 #else
4534                         msg_format("%^s ignores the attack.", m_name);
4535 #endif
4536
4537                 else if (percentage > 75)
4538 #ifdef JP
4539 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4540 #else
4541                         msg_format("%^s shrugs off the attack.", m_name);
4542 #endif
4543
4544                 else if (percentage > 50)
4545 #ifdef JP
4546 msg_format("%^s¤Ï¥«¥¿¥«¥¿¤È¾Ð¤Ã¤¿¡£", m_name);
4547 #else
4548                         msg_format("%^s rattles.", m_name);
4549 #endif
4550
4551                 else if (percentage > 35)
4552 #ifdef JP
4553 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4554 #else
4555                         msg_format("%^s stumbles.", m_name);
4556 #endif
4557
4558                 else if (percentage > 20)
4559 #ifdef JP
4560 msg_format("%^s¤Ï¥«¥¿¥«¥¿¸À¤Ã¤¿¡£", m_name);
4561 #else
4562                         msg_format("%^s rattles.", m_name);
4563 #endif
4564
4565                 else if (percentage > 10)
4566 #ifdef JP
4567 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4568 #else
4569                         msg_format("%^s staggers.", m_name);
4570 #endif
4571
4572                 else
4573 #ifdef JP
4574 msg_format("%^s¤Ï¥¬¥¿¥¬¥¿¸À¤Ã¤¿¡£", m_name);
4575 #else
4576                         msg_format("%^s clatters.", m_name);
4577 #endif
4578
4579         }
4580
4581
4582         /* Zombies */
4583         else if (my_strchr("z", r_ptr->d_char))
4584         {
4585                 if (percentage > 95)
4586 #ifdef JP
4587 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4588 #else
4589                         msg_format("%^s ignores the attack.", m_name);
4590 #endif
4591
4592                 else if (percentage > 75)
4593 #ifdef JP
4594 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4595 #else
4596                         msg_format("%^s shrugs off the attack.", m_name);
4597 #endif
4598
4599                 else if (percentage > 50)
4600 #ifdef JP
4601 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4602 #else
4603                         msg_format("%^s groans.", m_name);
4604 #endif
4605
4606                 else if (percentage > 35)
4607 #ifdef JP
4608 msg_format("%s¤Ï¶ì¤·¤²¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4609 #else
4610                         msg_format("%^s moans.", m_name);
4611 #endif
4612
4613                 else if (percentage > 20)
4614 #ifdef JP
4615 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4616 #else
4617                         msg_format("%^s hesitates.", m_name);
4618 #endif
4619
4620                 else if (percentage > 10)
4621 #ifdef JP
4622 msg_format("%^s¤Ï¤¦¤Ê¤Ã¤¿¡£", m_name);
4623 #else
4624                         msg_format("%^s grunts.", m_name);
4625 #endif
4626
4627                 else
4628 #ifdef JP
4629 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4630 #else
4631                         msg_format("%^s staggers.", m_name);
4632 #endif
4633
4634         }
4635
4636
4637         /* Ghosts */
4638         else if (my_strchr("G", r_ptr->d_char))
4639
4640         {
4641                 if (percentage > 95)
4642 #ifdef JP
4643 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4644 #else
4645                         msg_format("%^s ignores the attack.", m_name);
4646 #endif
4647
4648                 else if (percentage > 75)
4649 #ifdef JP
4650 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4651 #else
4652                         msg_format("%^s shrugs off the attack.", m_name);
4653 #endif
4654
4655                 else if (percentage > 50)
4656 #ifdef JP
4657 msg_format("%s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4658 #else
4659                         msg_format("%^s moans.", m_name);
4660 #endif
4661
4662                 else if (percentage > 35)
4663 #ifdef JP
4664 msg_format("%^s¤Ïµã¤­¤ï¤á¤¤¤¿¡£", m_name);
4665 #else
4666                         msg_format("%^s wails.", m_name);
4667 #endif
4668
4669                 else if (percentage > 20)
4670 #ifdef JP
4671 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4672 #else
4673                         msg_format("%^s howls.", m_name);
4674 #endif
4675
4676                 else if (percentage > 10)
4677 #ifdef JP
4678 msg_format("%s¤Ï¼å¡¹¤·¤¯¤¦¤á¤¤¤¿¡£", m_name);
4679 #else
4680                         msg_format("%^s moans softly.", m_name);
4681 #endif
4682
4683                 else
4684 #ifdef JP
4685 msg_format("%^s¤Ï¤«¤¹¤«¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4686 #else
4687                         msg_format("%^s sighs.", m_name);
4688 #endif
4689
4690         }
4691
4692
4693         /* Dogs and Hounds */
4694         else if (my_strchr("CZ", r_ptr->d_char))
4695         {
4696 #ifdef JP
4697                 if (percentage > 95)
4698                         msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4699                 else if (percentage > 75)
4700                         msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4701                 else if (percentage > 50)
4702                         msg_format("%^s¤ÏÄˤߤǥ­¥ã¥ó¥­¥ã¥óËʤ¨¤¿¡£", m_name);
4703                 else if (percentage > 35)
4704                         msg_format("%^s¤ÏÄˤߤÇÌĤ­¤ï¤á¤¤¤¿¡£", m_name);
4705                 else if (percentage > 20)
4706                         msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÌĤ­¤ï¤á¤¤¤¿¡£", m_name);
4707                 else if (percentage > 10)
4708                         msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4709                 else
4710                         msg_format("%^s¤Ï¼å¡¹¤·¤¯Ëʤ¨¤¿¡£", m_name);
4711 #else
4712                 if (percentage > 95)
4713                         msg_format("%^s shrugs off the attack.", m_name);
4714                 else if (percentage > 75)
4715                         msg_format("%^s snarls with pain.", m_name);
4716                 else if (percentage > 50)
4717                         msg_format("%^s yelps in pain.", m_name);
4718                 else if (percentage > 35)
4719                         msg_format("%^s howls in pain.", m_name);
4720                 else if (percentage > 20)
4721                         msg_format("%^s howls in agony.", m_name);
4722                 else if (percentage > 10)
4723                         msg_format("%^s writhes in agony.", m_name);
4724                 else
4725                         msg_format("%^s yelps feebly.", m_name);
4726 #endif
4727
4728         }
4729
4730         /* One type of monsters (ignore,squeal,shriek) */
4731         else if (my_strchr("Xbilqrt", r_ptr->d_char))
4732         {
4733 #ifdef JP
4734                 if (percentage > 95)
4735                         msg_format("%^s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4736                 else if (percentage > 75)
4737                         msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4738                 else if (percentage > 50)
4739                         msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4740                 else if (percentage > 35)
4741                         msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4742                 else if (percentage > 20)
4743                         msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4744                 else if (percentage > 10)
4745                         msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4746                 else
4747                         msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4748 #else
4749                 if (percentage > 95)
4750                         msg_format("%^s ignores the attack.", m_name);
4751                 else if (percentage > 75)
4752                         msg_format("%^s grunts with pain.", m_name);
4753                 else if (percentage > 50)
4754                         msg_format("%^s squeals in pain.", m_name);
4755                 else if (percentage > 35)
4756                         msg_format("%^s shrieks in pain.", m_name);
4757                 else if (percentage > 20)
4758                         msg_format("%^s shrieks in agony.", m_name);
4759                 else if (percentage > 10)
4760                         msg_format("%^s writhes in agony.", m_name);
4761                 else
4762                         msg_format("%^s cries out feebly.", m_name);
4763 #endif
4764
4765         }
4766
4767         /* Another type of monsters (shrug,cry,scream) */
4768         else
4769         {
4770 #ifdef JP
4771                 if (percentage > 95)
4772                         msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4773                 else if (percentage > 75)
4774                         msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4775                 else if (percentage > 50)
4776                         msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4777                 else if (percentage > 35)
4778                         msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4779                 else if (percentage > 20)
4780                         msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4781                 else if (percentage > 10)
4782                         msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4783                 else
4784                         msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4785 #else
4786                 if (percentage > 95)
4787                         msg_format("%^s shrugs off the attack.", m_name);
4788                 else if (percentage > 75)
4789                         msg_format("%^s grunts with pain.", m_name);
4790                 else if (percentage > 50)
4791                         msg_format("%^s cries out in pain.", m_name);
4792                 else if (percentage > 35)
4793                         msg_format("%^s screams in pain.", m_name);
4794                 else if (percentage > 20)
4795                         msg_format("%^s screams in agony.", m_name);
4796                 else if (percentage > 10)
4797                         msg_format("%^s writhes in agony.", m_name);
4798                 else
4799                         msg_format("%^s cries out feebly.", m_name);
4800 #endif
4801
4802         }
4803 }
4804
4805
4806 /*
4807  * Learn about an "observed" resistance.
4808  */
4809 void update_smart_learn(int m_idx, int what)
4810 {
4811         monster_type *m_ptr = &m_list[m_idx];
4812
4813         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4814
4815
4816         /* Not allowed to learn */
4817         if (!smart_learn) return;
4818
4819         /* Too stupid to learn anything */
4820         if (r_ptr->flags2 & (RF2_STUPID)) return;
4821
4822         /* Not intelligent, only learn sometimes */
4823         if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
4824
4825
4826         /* XXX XXX XXX */
4827
4828         /* Analyze the knowledge */
4829         switch (what)
4830         {
4831         case DRS_ACID:
4832                 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
4833                 if (IS_OPPOSE_ACID()) m_ptr->smart |= (SM_OPP_ACID);
4834                 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
4835                 break;
4836
4837         case DRS_ELEC:
4838                 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
4839                 if (IS_OPPOSE_ELEC()) m_ptr->smart |= (SM_OPP_ELEC);
4840                 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
4841                 break;
4842
4843         case DRS_FIRE:
4844                 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
4845                 if (IS_OPPOSE_FIRE()) m_ptr->smart |= (SM_OPP_FIRE);
4846                 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
4847                 break;
4848
4849         case DRS_COLD:
4850                 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
4851                 if (IS_OPPOSE_COLD()) m_ptr->smart |= (SM_OPP_COLD);
4852                 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
4853                 break;
4854
4855         case DRS_POIS:
4856                 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
4857                 if (IS_OPPOSE_POIS()) m_ptr->smart |= (SM_OPP_POIS);
4858                 break;
4859
4860
4861         case DRS_NETH:
4862                 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
4863                 break;
4864
4865         case DRS_LITE:
4866                 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
4867                 break;
4868
4869         case DRS_DARK:
4870                 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
4871                 break;
4872
4873         case DRS_FEAR:
4874                 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
4875                 break;
4876
4877         case DRS_CONF:
4878                 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
4879                 break;
4880
4881         case DRS_CHAOS:
4882                 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
4883                 break;
4884
4885         case DRS_DISEN:
4886                 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
4887                 break;
4888
4889         case DRS_BLIND:
4890                 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
4891                 break;
4892
4893         case DRS_NEXUS:
4894                 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
4895                 break;
4896
4897         case DRS_SOUND:
4898                 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
4899                 break;
4900
4901         case DRS_SHARD:
4902                 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
4903                 break;
4904
4905         case DRS_FREE:
4906                 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
4907                 break;
4908
4909         case DRS_MANA:
4910                 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
4911                 break;
4912
4913         case DRS_REFLECT:
4914                 if (p_ptr->reflect) m_ptr-> smart |= (SM_IMM_REFLECT);
4915                 break;
4916         }
4917 }
4918
4919
4920 /*
4921  * Place the player in the dungeon XXX XXX
4922  */
4923 bool player_place(int y, int x)
4924 {
4925         /* Paranoia XXX XXX */
4926         if (cave[y][x].m_idx != 0) return FALSE;
4927
4928         /* Save player location */
4929         py = y;
4930         px = x;
4931
4932         /* Success */
4933         return TRUE;
4934 }
4935
4936
4937 /*
4938  * Drop all items carried by a monster
4939  */
4940 void monster_drop_carried_objects(monster_type *m_ptr)
4941 {
4942         s16b this_o_idx, next_o_idx = 0;
4943         object_type forge;
4944         object_type *o_ptr;
4945         object_type *q_ptr;
4946
4947
4948         /* Drop objects being carried */
4949         for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4950         {
4951                 /* Acquire object */
4952                 o_ptr = &o_list[this_o_idx];
4953
4954                 /* Acquire next object */
4955                 next_o_idx = o_ptr->next_o_idx;
4956
4957                 /* Get local object */
4958                 q_ptr = &forge;
4959
4960                 /* Copy the object */
4961                 object_copy(q_ptr, o_ptr);
4962
4963                 /* Forget monster */
4964                 q_ptr->held_m_idx = 0;
4965
4966                 /* Delete the object */
4967                 delete_object_idx(this_o_idx);
4968
4969                 /* Drop it */
4970                 (void)drop_near(q_ptr, -1, m_ptr->fy, m_ptr->fx);
4971         }
4972
4973         /* Forget objects */
4974         m_ptr->hold_o_idx = 0;
4975 }