OSDN Git Service

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