OSDN Git Service

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