OSDN Git Service

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