OSDN Git Service

typoス、タオ。」
[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 #if 0
2869         /* Hack -- no creation on glyph of warding */
2870         if (cave[y][x].feat == FEAT_GLYPH) return (FALSE);
2871         if (cave[y][x].feat == FEAT_MINOR_GLYPH) return (FALSE);
2872 #endif
2873
2874         /* Nor on the Pattern */
2875         if ((cave[y][x].feat >= FEAT_PATTERN_START)
2876          && (cave[y][x].feat <= FEAT_PATTERN_XTRA2))
2877                 return (FALSE);
2878
2879         if (!(mode & PM_IGNORE_TERRAIN) &&
2880             !monster_can_cross_terrain(cave[y][x].feat, r_ptr))
2881         {
2882                 return FALSE;
2883         }
2884
2885         if (!p_ptr->inside_battle)
2886         {
2887                 /* Hack -- "unique" monsters must be "unique" */
2888                 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
2889                      (r_ptr->flags7 & (RF7_UNIQUE_7))) &&
2890                     (r_ptr->cur_num >= r_ptr->max_num))
2891                 {
2892                         /* Cannot create */
2893                         return (FALSE);
2894                 }
2895                 
2896                 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
2897                     (r_ptr->cur_num >= 1))
2898                 {
2899                         return (FALSE);
2900                 }
2901
2902                 if (r_idx == MON_BANORLUPART)
2903                 {
2904                         if (r_info[MON_BANOR].cur_num > 0) return FALSE;
2905                         if (r_info[MON_LUPART].cur_num > 0) return FALSE;
2906                 }
2907                 
2908                 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
2909                 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (dun_level < r_ptr->level) &&
2910                     (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
2911                 {
2912                         /* Cannot create */
2913                         return (FALSE);
2914                 }
2915         }
2916
2917         if(quest_number(dun_level))
2918         {
2919                 int hoge = quest_number(dun_level);
2920                 if((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
2921                 {
2922                         if(r_idx == quest[hoge].r_idx)
2923                         {
2924                                 int number_mon, i2, j2;
2925                                 number_mon = 0;
2926
2927                                 /* Count all quest monsters */
2928                                 for (i2 = 0; i2 < cur_wid; ++i2)
2929                                         for (j2 = 0; j2 < cur_hgt; j2++)
2930                                                 if (cave[j2][i2].m_idx > 0)
2931                                                         if (m_list[cave[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
2932                                                                 number_mon++;
2933                                 if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
2934                                         return FALSE;
2935                         }
2936                 }
2937         }
2938
2939         /* Access the location */
2940         c_ptr = &cave[y][x];
2941
2942         if (c_ptr->feat == FEAT_GLYPH)
2943         {
2944                 if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
2945                 {
2946                         /* Describe observable breakage */
2947                         if (c_ptr->info & CAVE_MARK)
2948                         {
2949 #ifdef JP
2950 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
2951 #else
2952                                 msg_print("The rune of protection is broken!");
2953 #endif
2954
2955                         }
2956
2957                         /* Forget the rune */
2958                         c_ptr->info &= ~(CAVE_MARK);
2959
2960                         /* Break the rune */
2961                         c_ptr->feat = floor_type[randint0(100)];
2962
2963                         /* Notice */
2964                         note_spot(y, x);
2965                         rune_dam = 1000;
2966                 }
2967                 else return FALSE;
2968         }
2969
2970         /* Powerful monster */
2971         if (r_ptr->level > dun_level)
2972         {
2973                 /* Unique monsters */
2974                 if (r_ptr->flags1 & (RF1_UNIQUE))
2975                 {
2976                         /* Message for cheaters */
2977 #ifdef JP
2978                         if (cheat_hear) msg_format("¿¼ÁؤΥæ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
2979 #else
2980                         if (cheat_hear) msg_format("Deep Unique (%s).", name);
2981 #endif
2982
2983
2984                         /* Boost rating by twice delta-depth */
2985                         rating += (r_ptr->level - dun_level) * 2;
2986                 }
2987
2988                 /* Normal monsters */
2989                 else
2990                 {
2991                         /* Message for cheaters */
2992 #ifdef JP
2993                         if (cheat_hear) msg_format("¿¼ÁؤΥâ¥ó¥¹¥¿¡¼ (%s)¡£", name);
2994 #else
2995                         if (cheat_hear) msg_format("Deep Monster (%s).", name);
2996 #endif
2997
2998
2999                         /* Boost rating by delta-depth */
3000                         rating += (r_ptr->level - dun_level);
3001                 }
3002         }
3003
3004         /* Note the monster */
3005         else if (r_ptr->flags1 & (RF1_UNIQUE))
3006         {
3007                 /* Unique monsters induce message */
3008 #ifdef JP
3009                 if (cheat_hear) msg_format("¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3010 #else
3011                 if (cheat_hear) msg_format("Unique (%s).", name);
3012 #endif
3013
3014         }
3015
3016         if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7) || (r_ptr->level < 10)) is_kage = FALSE;
3017
3018         /* Make a new monster */
3019         c_ptr->m_idx = m_pop();
3020         hack_m_idx_ii = c_ptr->m_idx;
3021
3022         /* Mega-Hack -- catch "failure" */
3023         if (!c_ptr->m_idx) return (FALSE);
3024
3025
3026         /* Get a new monster record */
3027         m_ptr = &m_list[c_ptr->m_idx];
3028
3029         /* Save the race */
3030         m_ptr->r_idx = r_idx;
3031         m_ptr->ap_r_idx = initial_r_appearance(r_idx);
3032
3033         /* Sub-alignment of a monster */
3034         if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
3035                 m_ptr->sub_align = m_list[who].sub_align;
3036         else
3037         {
3038                 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3039                 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
3040                 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
3041         }
3042
3043         /* Place the monster at the location */
3044         m_ptr->fy = y;
3045         m_ptr->fx = x;
3046
3047
3048         /* No "damage" yet */
3049         m_ptr->stunned = 0;
3050         m_ptr->confused = 0;
3051         m_ptr->monfear = 0;
3052
3053         /* Unknown distance */
3054         m_ptr->cdis = 0;
3055
3056         reset_target(m_ptr);
3057
3058         m_ptr->nickname = 0;
3059
3060         m_ptr->exp = 0;
3061
3062         /* No flags */
3063         m_ptr->mflag = 0;
3064         m_ptr->mflag2 = 0;
3065
3066         if (r_ptr->flags7 & RF7_CHAMELEON)
3067         {
3068                 choose_new_monster(c_ptr->m_idx, TRUE, 0);
3069                 r_ptr = &r_info[m_ptr->r_idx];
3070                 m_ptr->mflag2 |= MFLAG_CHAMELEON;
3071                 rating++;
3072
3073                 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
3074                 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
3075                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3076         }
3077         else if (is_kage)
3078         {
3079                 m_ptr->ap_r_idx = MON_KAGE;
3080                 m_ptr->mflag2 |= MFLAG_KAGE;
3081         }
3082
3083         if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG_NOPET;
3084
3085         /* Not visible */
3086         m_ptr->ml = FALSE;
3087
3088         /* Pet? */
3089         if (mode & PM_FORCE_PET)
3090         {
3091                 set_pet(m_ptr);
3092         }
3093         /* Friendly? */
3094         else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
3095                  (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
3096         {
3097                 if (!(p_ptr->align >= 0 && (r_ptr->flags3 & RF3_EVIL)) &&
3098                     !(p_ptr->align < 0 && (r_ptr->flags3 & RF3_GOOD)))
3099                 {
3100                         set_friendly(m_ptr);
3101                 }
3102         }
3103
3104         /* Assume no sleeping */
3105         m_ptr->csleep = 0;
3106
3107         /* Enforce sleeping if needed */
3108         if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
3109         {
3110                 int val = r_ptr->sleep;
3111                 m_ptr->csleep = ((val * 2) + randint1(val * 10));
3112         }
3113
3114         /* Assign maximal hitpoints */
3115         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
3116         {
3117                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
3118         }
3119         else
3120         {
3121                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
3122         }
3123
3124         /* Monsters have double hitpoints in Nightmare mode */
3125         if (ironman_nightmare)
3126         {
3127                 u32b hp = m_ptr->max_maxhp * 2L;
3128
3129                 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
3130         }
3131
3132         m_ptr->maxhp = m_ptr->max_maxhp;
3133
3134         /* And start out fully healthy */
3135         if (m_ptr->r_idx == MON_WOUNDED_BEAR)
3136                 m_ptr->hp = m_ptr->maxhp / 2;
3137         else m_ptr->hp = m_ptr->maxhp;
3138
3139
3140         /* Extract the monster base speed */
3141         m_ptr->mspeed = r_ptr->speed;
3142
3143         /* Hack -- small racial variety */
3144         if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
3145         {
3146                 /* Allow some small variation per monster */
3147           if(one_in_(4)){
3148                 i = extract_energy[r_ptr->speed] / 3;
3149                 if (i) m_ptr->mspeed += rand_spread(0, i);
3150           }
3151           else{
3152                 i = extract_energy[r_ptr->speed] / 10;
3153                 if (i) m_ptr->mspeed += rand_spread(0, i);
3154           }
3155         }
3156
3157         if (mode & PM_HASTE) m_ptr->fast = 100;
3158
3159         if (m_ptr->mspeed > 199) m_ptr->mspeed = 199;
3160
3161         /* Give a random starting energy */
3162         if (!ironman_nightmare)
3163         {
3164                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
3165         }
3166         else
3167         {
3168                 /* Nightmare monsters are more prepared */
3169                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
3170         }
3171
3172         /* Force monster to wait for player, unless in Nightmare mode */
3173         if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
3174         {
3175                 /* Monster is still being nice */
3176                 m_ptr->mflag |= (MFLAG_NICE);
3177
3178                 /* Must repair monsters */
3179                 repair_monsters = TRUE;
3180         }
3181
3182         /* Hack -- see "process_monsters()" */
3183         if (c_ptr->m_idx < hack_m_idx)
3184         {
3185                 /* Monster is still being born */
3186                 m_ptr->mflag |= (MFLAG_BORN);
3187         }
3188
3189
3190         /* Update the monster */
3191         update_mon(c_ptr->m_idx, TRUE);
3192
3193
3194         /* Hack -- Count the monsters on the level */
3195         if (m_ptr->mflag2 & MFLAG_CHAMELEON)
3196                 r_info[r_idx].cur_num++;
3197         else
3198                 r_ptr->cur_num++;
3199
3200
3201         /* Hack -- Count the number of "reproducers" */
3202         if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
3203
3204
3205         /* Hack -- Notice new multi-hued monsters */
3206         if (r_ptr->flags1 & RF1_ATTR_MULTI) shimmer_monsters = TRUE;
3207
3208         if (p_ptr->warning && character_dungeon)
3209         {
3210                 if (r_ptr->flags1 & RF1_UNIQUE)
3211                 {
3212                         cptr color;
3213                         object_type *o_ptr;
3214                         char o_name[MAX_NLEN];
3215
3216                         if (r_ptr->level > p_ptr->lev + 30)
3217 #ifdef JP
3218                                 color = "¹õ¤¯";
3219 #else
3220                                 color = "black";
3221 #endif
3222                         else if (r_ptr->level > p_ptr->lev + 15)
3223 #ifdef JP
3224                                 color = "»ç¿§¤Ë";
3225 #else
3226                                 color = "purple";
3227 #endif
3228                         else if (r_ptr->level > p_ptr->lev + 5)
3229 #ifdef JP
3230                                 color = "¥ë¥Ó¡¼¿§¤Ë";
3231 #else
3232                                 color = "deep red";
3233 #endif
3234                         else if (r_ptr->level > p_ptr->lev - 5)
3235 #ifdef JP
3236                                 color = "ÀÖ¤¯";
3237 #else
3238                                 color = "red";
3239 #endif
3240                         else if (r_ptr->level > p_ptr->lev - 15)
3241 #ifdef JP
3242                                 color = "¥Ô¥ó¥¯¿§¤Ë";
3243 #else
3244                                 color = "pink";
3245 #endif
3246                         else
3247 #ifdef JP
3248                                 color = "Çò¤¯";
3249 #else
3250                                 color = "white";
3251 #endif
3252
3253                         o_ptr = choose_warning_item();
3254                         object_desc(o_name, o_ptr, FALSE, 0);
3255 #ifdef JP
3256                         msg_format("%s¤Ï%s¸÷¤Ã¤¿¡£",o_name, color);
3257 #else
3258                         msg_format("%s glows %s.",o_name, color);
3259 #endif
3260                 }
3261         }
3262
3263         if (c_ptr->feat == FEAT_MINOR_GLYPH)
3264         {
3265                 /* Break the ward */
3266                 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3267                 {
3268                         /* Describe observable breakage */
3269                         if (c_ptr->info & CAVE_MARK)
3270                         {
3271 #ifdef JP
3272 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3273 #else
3274                                 msg_print("The rune explodes!");
3275 #endif
3276
3277                                 project(0, 2, y, x, 2 * (p_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_REF | PROJECT_NO_HANGEKI), -1);
3278                         }
3279                 }
3280                 else
3281                 {
3282 #ifdef JP
3283 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3284 #else
3285                         msg_print("An explosive rune was disarmed.");
3286 #endif
3287                 }
3288
3289                 /* Forget the rune */
3290                 c_ptr->info &= ~(CAVE_MARK);
3291
3292                 /* Break the rune */
3293                 c_ptr->feat = floor_type[randint0(100)];
3294                 note_spot(y, x);
3295                 lite_spot(y, x);
3296         }
3297
3298         /* Success */
3299         return (TRUE);
3300 }
3301
3302
3303 /*
3304  *  improved version of scatter() for place monster
3305  */
3306
3307 #define MON_SCAT_MAXD 10
3308
3309 static bool mon_scatter(int *yp, int *xp, int y, int x, int max_dist)
3310 {
3311         int place_x[MON_SCAT_MAXD];
3312         int place_y[MON_SCAT_MAXD];
3313         int num[MON_SCAT_MAXD];
3314         int i;
3315         int nx, ny;
3316
3317         if (max_dist >= MON_SCAT_MAXD)
3318                 return FALSE;
3319
3320         for (i = 0; i < MON_SCAT_MAXD; i++)
3321                 num[i] = 0;
3322
3323         for (nx = x - max_dist; nx <= x + max_dist; nx++)
3324                 for (ny = y - max_dist; ny <= y + max_dist; ny++)
3325                 {
3326                         /* Ignore annoying locations */
3327                         if (!in_bounds(ny, nx)) continue;
3328                         
3329                         /* Require "line of sight" */
3330                         if (!los(y, x, ny, nx)) continue;
3331                         
3332                         /* Walls and Monsters block flow */
3333                         if (!cave_empty_bold2(ny, nx)) continue;
3334                         if (cave[ny][nx].m_idx) continue;
3335                         if ((ny == py) && (nx == px)) continue;
3336                         
3337 #if 0
3338                         /* Hack -- no summon on glyph of warding */
3339                         if (cave[ny][nx].feat == FEAT_GLYPH) continue;
3340                         if (cave[ny][nx].feat == FEAT_MINOR_GLYPH) continue;
3341 #endif
3342                         
3343                         /* ... nor on the Pattern */
3344                         if ((cave[ny][nx].feat >= FEAT_PATTERN_START) &&
3345                             (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2))
3346                                 continue;
3347                         
3348                         i = distance(y, x, ny, nx);
3349
3350                         if (i > max_dist)
3351                                 continue;
3352                         
3353                         num[i]++;
3354
3355                         /* random swap */
3356                         if(one_in_(num[i]))
3357                         {
3358                                 place_x[i] = nx;
3359                                 place_y[i] = ny;
3360                         }
3361                         
3362                 }
3363
3364         i = 0;
3365         while (i < MON_SCAT_MAXD && 0 == num[i])
3366                 i++;
3367         if (i >= MON_SCAT_MAXD)
3368                 return FALSE;
3369
3370         *xp = place_x[i];
3371         *yp = place_y[i];
3372
3373         return TRUE;
3374 }
3375
3376
3377 /*
3378  * Maximum size of a group of monsters
3379  */
3380 #define GROUP_MAX       32
3381
3382
3383 /*
3384  * Attempt to place a "group" of monsters around the given location
3385  */
3386 static bool place_monster_group(int who, int y, int x, int r_idx, u32b mode)
3387 {
3388         monster_race *r_ptr = &r_info[r_idx];
3389
3390         int old, n, i;
3391         int total = 0, extra = 0;
3392
3393         int hack_n = 0;
3394
3395         byte hack_y[GROUP_MAX];
3396         byte hack_x[GROUP_MAX];
3397
3398
3399         /* Pick a group size */
3400         total = randint1(10);
3401
3402         /* Hard monsters, small groups */
3403         if (r_ptr->level > dun_level)
3404         {
3405                 extra = r_ptr->level - dun_level;
3406                 extra = 0 - randint1(extra);
3407         }
3408
3409         /* Easy monsters, large groups */
3410         else if (r_ptr->level < dun_level)
3411         {
3412                 extra = dun_level - r_ptr->level;
3413                 extra = randint1(extra);
3414         }
3415
3416         /* Hack -- limit group reduction */
3417         if (extra > 9) extra = 9;
3418
3419         /* Modify the group size */
3420         total += extra;
3421
3422         /* Minimum size */
3423         if (total < 1) total = 1;
3424
3425         /* Maximum size */
3426         if (total > GROUP_MAX) total = GROUP_MAX;
3427
3428
3429         /* Save the rating */
3430         old = rating;
3431
3432         /* Start on the monster */
3433         hack_n = 1;
3434         hack_x[0] = x;
3435         hack_y[0] = y;
3436
3437         /* Puddle monsters, breadth first, up to total */
3438         for (n = 0; (n < hack_n) && (hack_n < total); n++)
3439         {
3440                 /* Grab the location */
3441                 int hx = hack_x[n];
3442                 int hy = hack_y[n];
3443
3444                 /* Check each direction, up to total */
3445                 for (i = 0; (i < 8) && (hack_n < total); i++)
3446                 {
3447                         int mx, my;
3448
3449                         scatter(&my, &mx, hy, hx, 4, 0);
3450
3451                         /* Walls and Monsters block flow */
3452                         if (!cave_empty_bold2(my, mx)) continue;
3453
3454                         /* Attempt to place another monster */
3455                         if (place_monster_one(who, my, mx, r_idx, mode))
3456                         {
3457                                 /* Add it to the "hack" set */
3458                                 hack_y[hack_n] = my;
3459                                 hack_x[hack_n] = mx;
3460                                 hack_n++;
3461                         }
3462                 }
3463         }
3464
3465         /* Hack -- restore the rating */
3466         rating = old;
3467
3468
3469         /* Success */
3470         return (TRUE);
3471 }
3472
3473
3474 /*
3475  * Hack -- help pick an escort type
3476  */
3477 static int place_monster_idx = 0;
3478 static int place_monster_m_idx = 0;
3479
3480 /*
3481  * Hack -- help pick an escort type
3482  */
3483 static bool place_monster_okay(int r_idx)
3484 {
3485         monster_race *r_ptr = &r_info[place_monster_idx];
3486         monster_type *m_ptr = &m_list[place_monster_m_idx];
3487
3488         monster_race *z_ptr = &r_info[r_idx];
3489
3490         /* Hack - Escorts have to have the same dungeon flag */
3491         if (monster_dungeon(place_monster_idx) != monster_dungeon(r_idx)) return (FALSE);
3492
3493         /* Require similar "race" */
3494         if (z_ptr->d_char != r_ptr->d_char) return (FALSE);
3495
3496         /* Skip more advanced monsters */
3497         if (z_ptr->level > r_ptr->level) return (FALSE);
3498
3499         /* Skip unique monsters */
3500         if (z_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3501
3502         /* Paranoia -- Skip identical monsters */
3503         if (place_monster_idx == r_idx) return (FALSE);
3504
3505         /* Skip different alignment */
3506         if (((m_ptr->sub_align & SUB_ALIGN_EVIL) && (z_ptr->flags3 & RF3_GOOD)) ||
3507             ((m_ptr->sub_align & SUB_ALIGN_GOOD) && (z_ptr->flags3 & RF3_EVIL)))
3508                 return FALSE;
3509
3510         if (r_ptr->flags7 & RF7_FRIENDLY)
3511         {
3512                 if (((p_ptr->align < 0) && (z_ptr->flags3 & RF3_GOOD)) ||
3513                     ((p_ptr->align > 0) && (z_ptr->flags3 & RF3_EVIL)))
3514                         return FALSE;
3515         }
3516
3517         if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3518                 return FALSE;
3519
3520         /* Okay */
3521         return (TRUE);
3522 }
3523
3524
3525 /*
3526  * Attempt to place a monster of the given race at the given location
3527  *
3528  * Note that certain monsters are now marked as requiring "friends".
3529  * These monsters, if successfully placed, and if the "grp" parameter
3530  * is TRUE, will be surrounded by a "group" of identical monsters.
3531  *
3532  * Note that certain monsters are now marked as requiring an "escort",
3533  * which is a collection of monsters with similar "race" but lower level.
3534  *
3535  * Some monsters induce a fake "group" flag on their escorts.
3536  *
3537  * Note the "bizarre" use of non-recursion to prevent annoying output
3538  * when running a code profiler.
3539  *
3540  * Note the use of the new "monster allocation table" code to restrict
3541  * the "get_mon_num()" function to "legal" escort types.
3542  */
3543 bool place_monster_aux(int who, int y, int x, int r_idx, u32b mode)
3544 {
3545         int             i;
3546         monster_race    *r_ptr = &r_info[r_idx];
3547
3548         if (one_in_(333) && !(mode & PM_NO_KAGE) && !(mode & PM_FORCE_PET))
3549                 is_kage = TRUE;
3550         else
3551                 is_kage = FALSE;
3552
3553         /* Place one monster, or fail */
3554         if (!place_monster_one(who, y, x, r_idx, mode)) return (FALSE);
3555
3556
3557         /* Require the "group" flag */
3558         if (!(mode & PM_ALLOW_GROUP)) return (TRUE);
3559
3560         place_monster_m_idx = hack_m_idx_ii;
3561
3562         /* Friends for certain monsters */
3563         if (r_ptr->flags1 & (RF1_FRIENDS))
3564         {
3565                 /* Attempt to place a group */
3566                 (void)place_monster_group(who, y, x, r_idx, mode);
3567         }
3568
3569
3570         /* Escorts for certain monsters */
3571         if (r_ptr->flags1 & (RF1_ESCORT))
3572         {
3573                 /* Set the escort index */
3574                 place_monster_idx = r_idx;
3575
3576                 /* Try to place several "escorts" */
3577                 for (i = 0; i < 32; i++)
3578                 {
3579                         int nx, ny, z, d = 3;
3580
3581                         /* Pick a location */
3582                         scatter(&ny, &nx, y, x, d, 0);
3583
3584                         /* Require empty grids */
3585                         if (!cave_empty_bold2(ny, nx)) continue;
3586
3587                         /* Prepare allocation table */
3588                         get_mon_num_prep(place_monster_okay, get_monster_hook2(ny, nx));
3589
3590                         /* Pick a random race */
3591                         z = get_mon_num(r_ptr->level);
3592
3593                         /* Handle failure */
3594                         if (!z) break;
3595
3596                         /* Place a single escort */
3597                         (void)place_monster_one(place_monster_m_idx, ny, nx, z, mode);
3598
3599                         /* Place a "group" of escorts if needed */
3600                         if ((r_info[z].flags1 & RF1_FRIENDS) ||
3601                             (r_ptr->flags1 & RF1_ESCORTS))
3602                         {
3603                                 /* Place a group of monsters */
3604                                 (void)place_monster_group(place_monster_m_idx, ny, nx, z, mode);
3605                         }
3606                 }
3607         }
3608
3609         /* Success */
3610         return (TRUE);
3611 }
3612
3613
3614 /*
3615  * Hack -- attempt to place a monster at the given location
3616  *
3617  * Attempt to find a monster appropriate to the "monster_level"
3618  */
3619 bool place_monster(int y, int x, u32b mode)
3620 {
3621         int r_idx;
3622
3623         /* Prepare allocation table */
3624         get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3625
3626         /* Pick a monster */
3627         r_idx = get_mon_num(monster_level);
3628
3629         /* Handle failure */
3630         if (!r_idx) return (FALSE);
3631
3632         /* Attempt to place the monster */
3633         if (place_monster_aux(0, y, x, r_idx, mode)) return (TRUE);
3634
3635         /* Oops */
3636         return (FALSE);
3637 }
3638
3639
3640 #ifdef MONSTER_HORDES
3641
3642 bool alloc_horde(int y, int x)
3643 {
3644         monster_race *r_ptr = NULL;
3645         int r_idx = 0;
3646         int m_idx;
3647         int attempts = 1000;
3648         int cy = y;
3649         int cx = x;
3650
3651         /* Prepare allocation table */
3652         get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3653
3654         while (--attempts)
3655         {
3656                 /* Pick a monster */
3657                 r_idx = get_mon_num(monster_level);
3658
3659                 /* Handle failure */
3660                 if (!r_idx) return (FALSE);
3661
3662                 r_ptr = &r_info[r_idx];
3663
3664                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3665
3666                 if (r_idx == MON_HAGURE) continue;
3667                 break;
3668         }
3669         if (attempts < 1) return FALSE;
3670
3671         if (r_ptr->flags3 & RF3_GOOD) horde_align |= HORDE_NOEVIL;
3672         if (r_ptr->flags3 & RF3_EVIL) horde_align |= HORDE_NOGOOD;
3673
3674         attempts = 1000;
3675
3676         while (--attempts)
3677         {
3678                 /* Attempt to place the monster */
3679                 if (place_monster_aux(0, y, x, r_idx, 0L)) break;
3680         }
3681
3682         if (attempts < 1) {horde_align = 0;return FALSE;}
3683
3684         m_idx = cave[y][x].m_idx;
3685
3686         if (m_list[m_idx].mflag2 & MFLAG_CHAMELEON) r_ptr = &r_info[m_list[m_idx].r_idx];
3687         summon_kin_type = r_ptr->d_char;
3688
3689         for (attempts = randint1(10) + 5; attempts; attempts--)
3690         {
3691                 scatter(&cy, &cx, y, x, 5, 0);
3692
3693                 (void)summon_specific(m_idx, cy, cx, dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
3694
3695                 y = cy;
3696                 x = cx;
3697         }
3698
3699         horde_align = 0;
3700         return TRUE;
3701 }
3702
3703 #endif /* MONSTER_HORDES */
3704
3705
3706
3707 /*
3708  * Attempt to allocate a random monster in the dungeon.
3709  *
3710  * Place the monster at least "dis" distance from the player.
3711  *
3712  * Use "slp" to choose the initial "sleep" status
3713  *
3714  * Use "monster_level" for the monster level
3715  */
3716 bool alloc_monster(int dis, u32b mode)
3717 {
3718         int                     y = 0, x = 0;
3719         int         attempts_left = 10000;
3720         int guardian = d_info[dungeon_type].final_guardian;
3721
3722         /* Put an Guardian */
3723         if(guardian && d_info[dungeon_type].maxdepth == dun_level && r_info[guardian].cur_num < r_info[guardian].max_num )
3724         {
3725                 int oy;
3726                 int ox;
3727                 int try = 4000;
3728
3729                 /* Find a good position */
3730                 while(try)
3731                 {
3732                         /* Get a random spot */
3733                         oy = randint1(cur_hgt - 4) + 2;
3734                         ox = randint1(cur_wid - 4) + 2;
3735
3736                         /* Is it a good spot ? */
3737                         if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(cave[oy][ox].feat, &r_info[guardian]))
3738                         {
3739                                 /* Place the guardian */
3740                                 if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) break;
3741                         }
3742                         /* One less try */
3743                         try--;
3744                 }
3745         }
3746
3747
3748         /* Find a legal, distant, unoccupied, space */
3749         while (attempts_left--)
3750         {
3751                 /* Pick a location */
3752                 y = randint0(cur_hgt);
3753                 x = randint0(cur_wid);
3754
3755                 /* Require empty floor grid (was "naked") */
3756                 if (dun_level || (wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].terrain != TERRAIN_MOUNTAIN))
3757                 {
3758                         if (!cave_empty_bold2(y, x)) continue;
3759                 }
3760                 else
3761                 {
3762                         if (!cave_empty_bold2(y, x) && (cave[y][x].feat != FEAT_MOUNTAIN)) continue;
3763                 }
3764
3765                 /* Accept far away grids */
3766                 if (distance(y, x, py, px) > dis) break;
3767         }
3768
3769         if (!attempts_left)
3770         {
3771                 if (cheat_xtra || cheat_hear)
3772                 {
3773 #ifdef JP
3774 msg_print("·Ù¹ð¡ª¿·¤¿¤Ê¥â¥ó¥¹¥¿¡¼¤òÇÛÃ֤Ǥ­¤Þ¤»¤ó¡£¾®¤µ¤¤³¬¤Ç¤¹¤«¡©");
3775 #else
3776                         msg_print("Warning! Could not allocate a new monster. Small level?");
3777 #endif
3778
3779                 }
3780
3781                 return (FALSE);
3782         }
3783
3784
3785 #ifdef MONSTER_HORDES
3786         if (randint1(5000) <= dun_level)
3787         {
3788                 if (alloc_horde(y, x))
3789                 {
3790 #ifdef JP
3791 if (cheat_hear) msg_print("¥â¥ó¥¹¥¿¡¼¤ÎÂç·²");
3792 #else
3793                         if (cheat_hear) msg_print("Monster horde.");
3794 #endif
3795
3796                         return (TRUE);
3797                 }
3798         }
3799         else
3800         {
3801 #endif /* MONSTER_HORDES */
3802
3803                 /* Attempt to place the monster, allow groups */
3804                 if (place_monster(y, x, (mode | PM_ALLOW_GROUP))) return (TRUE);
3805
3806 #ifdef MONSTER_HORDES
3807         }
3808 #endif /* MONSTER_HORDES */
3809
3810         /* Nope */
3811         return (FALSE);
3812 }
3813
3814
3815
3816
3817 /*
3818  * Hack -- help decide if a monster race is "okay" to summon
3819  */
3820 static bool summon_specific_okay(int r_idx)
3821 {
3822         monster_race *r_ptr = &r_info[r_idx];
3823
3824         /* Hack - Only summon dungeon monsters */
3825         if (!monster_dungeon(r_idx)) return (FALSE);
3826
3827         /* Hack -- identify the summoning monster */
3828         if (summon_specific_who > 0)
3829         {
3830                 monster_type *m_ptr = &m_list[summon_specific_who];
3831
3832                 /* Do not summon enemies */
3833
3834                 /* Friendly vs. opposite aligned normal or pet */
3835                 if (((r_ptr->flags3 & RF3_EVIL) &&
3836                           (m_ptr->sub_align & SUB_ALIGN_GOOD)) ||
3837                          ((r_ptr->flags3 & RF3_GOOD) &&
3838                           (m_ptr->sub_align & SUB_ALIGN_EVIL)))
3839                 {
3840                         return FALSE;
3841                 }
3842
3843                 /* Hostile vs. non-hostile */
3844                 if (is_hostile(m_ptr) != summon_specific_hostile)
3845                 {
3846                         return FALSE;
3847                 }
3848         }
3849         /* Use the player's alignment */
3850         else if (summon_specific_who < 0)
3851         {
3852                 /* Do not summon enemies of the pets */
3853                 if ((p_ptr->align < -9) && (r_ptr->flags3 & RF3_GOOD))
3854                 {
3855                         if (!one_in_((0-p_ptr->align)/2+1)) return FALSE;
3856                 }
3857                 else if ((p_ptr->align > 9) && (r_ptr->flags3 & RF3_EVIL))
3858                 {
3859                         if (!one_in_(p_ptr->align/2+1)) return FALSE;
3860                 }
3861         }
3862
3863         /* Hack -- no specific type specified */
3864         if (!summon_specific_type) return (TRUE);
3865
3866         if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7))) return FALSE;
3867
3868         if ((summon_specific_who < 0) &&
3869             ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) &&
3870             (((p_ptr->align > 9) && (r_ptr->flags3 & RF3_EVIL)) ||
3871              ((p_ptr->align < -9) && (r_ptr->flags3 & RF3_GOOD))))
3872                 return FALSE;
3873
3874         if ((horde_align & HORDE_NOGOOD) && (r_ptr->flags3 & RF3_GOOD)) return FALSE;
3875         if ((horde_align & HORDE_NOEVIL) && (r_ptr->flags3 & RF3_EVIL)) return FALSE;
3876
3877         if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[dungeon_type].flags1 & DF1_CHAMELEON)) return TRUE;
3878
3879         return (summon_specific_aux(r_idx));
3880 }
3881
3882
3883 /*
3884  * Place a monster (of the specified "type") near the given
3885  * location.  Return TRUE if a monster was actually summoned.
3886  *
3887  * We will attempt to place the monster up to 10 times before giving up.
3888  *
3889  * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
3890  * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
3891  * Note: None of the other summon codes will ever summon Unique's.
3892  *
3893  * This function has been changed.  We now take the "monster level"
3894  * of the summoning monster as a parameter, and use that, along with
3895  * the current dungeon level, to help determine the level of the
3896  * desired monster.  Note that this is an upper bound, and also
3897  * tends to "prefer" monsters of that level.  Currently, we use
3898  * the average of the dungeon and monster levels, and then add
3899  * five to allow slight increases in monster power.
3900  *
3901  * Note that we use the new "monster allocation table" creation code
3902  * to restrict the "get_mon_num()" function to the set of "legal"
3903  * monsters, making this function much faster and more reliable.
3904  *
3905  * Note that this function may not succeed, though this is very rare.
3906  */
3907 bool summon_specific(int who, int y1, int x1, int lev, int type, u32b mode)
3908 {
3909         int x, y, r_idx;
3910
3911         if (p_ptr->inside_arena) return (FALSE);
3912
3913         if (!mon_scatter(&y, &x, y1, x1, 2)) return FALSE;
3914
3915         /* Save the summoner */
3916         summon_specific_who = who;
3917
3918         /* Save the "summon" type */
3919         summon_specific_type = type;
3920
3921         summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
3922
3923         /* Save the hostility */
3924         summon_specific_hostile = (!(mode & PM_FORCE_FRIENDLY) && !(is_friendly_idx(who)) && !(mode & PM_FORCE_PET));
3925
3926         /* Prepare allocation table */
3927         get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
3928
3929         /* Pick a monster, using the level calculation */
3930         r_idx = get_mon_num((dun_level + lev) / 2 + 5);
3931
3932         /* Handle failure */
3933         if (!r_idx)
3934         {
3935                 summon_specific_type = 0;
3936                 return (FALSE);
3937         }
3938
3939         if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
3940
3941         /* Attempt to place the monster (awake, allow groups) */
3942         if (!place_monster_aux(who, y, x, r_idx, mode))
3943         {
3944                 summon_specific_type = 0;
3945                 return (FALSE);
3946         }
3947
3948         summon_specific_type = 0;
3949         /* Success */
3950         return (TRUE);
3951 }
3952
3953 /* A "dangerous" function, creates a pet of the specified type */
3954 bool summon_named_creature (int who, int oy, int ox, int r_idx, u32b mode)
3955 {
3956         int x, y;
3957
3958         /* Paranoia */
3959         /* if (!r_idx) return; */
3960
3961         /* Prevent illegal monsters */
3962         if (r_idx >= max_r_idx) return FALSE;
3963
3964         if (p_ptr->inside_arena) return FALSE;
3965
3966         if (!mon_scatter(&y, &x, oy, ox, 2)) return FALSE;
3967
3968         /* Place it (allow groups) */
3969         return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
3970 }
3971
3972
3973 /*
3974  * Let the given monster attempt to reproduce.
3975  *
3976  * Note that "reproduction" REQUIRES empty space.
3977  */
3978 bool multiply_monster(int m_idx, bool clone, u32b mode)
3979 {
3980         monster_type    *m_ptr = &m_list[m_idx];
3981
3982         int y, x;
3983
3984         if (!mon_scatter(&y, &x, m_ptr->fy, m_ptr->fx, 1))
3985                 return FALSE;
3986
3987         if (m_ptr->mflag2 & MFLAG_NOPET) mode |= PM_NO_PET;
3988
3989         /* Create a new monster (awake, no groups) */
3990         if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE)))
3991                 return FALSE;
3992
3993         if (clone)
3994         {
3995                 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3996                 m_list[hack_m_idx_ii].mflag2 |= MFLAG_NOPET;
3997         }
3998
3999         return TRUE;
4000 }
4001
4002
4003
4004
4005
4006 /*
4007  * Dump a message describing a monster's reaction to damage
4008  *
4009  * Technically should attempt to treat "Beholder"'s as jelly's
4010  */
4011 void message_pain(int m_idx, int dam)
4012 {
4013         long oldhp, newhp, tmp;
4014         int percentage;
4015
4016         monster_type *m_ptr = &m_list[m_idx];
4017         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4018
4019         char m_name[80];
4020
4021
4022         /* Get the monster name */
4023         monster_desc(m_name, m_ptr, 0);
4024
4025         /* Notice non-damage */
4026         if (dam == 0)
4027         {
4028 #ifdef JP
4029                 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Æ¤¤¤Ê¤¤¡£", m_name);
4030 #else
4031                 msg_format("%^s is unharmed.", m_name);
4032 #endif
4033
4034                 return;
4035         }
4036
4037         /* Note -- subtle fix -CFT */
4038         newhp = (long)(m_ptr->hp);
4039         oldhp = newhp + (long)(dam);
4040         tmp = (newhp * 100L) / oldhp;
4041         percentage = (int)(tmp);
4042
4043
4044         /* Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs */
4045         if (strchr(",ejmvwQ", r_ptr->d_char))
4046         {
4047 #ifdef JP
4048                 if (percentage > 95)
4049                         msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4050                 else if (percentage > 75)
4051                         msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4052                 else if (percentage > 50)
4053                         msg_format("%^s¤Ï½Ì¤³¤Þ¤Ã¤¿¡£", m_name);
4054                 else if (percentage > 35)
4055                         msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4056                 else if (percentage > 20)
4057                         msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4058                 else if (percentage > 10)
4059                         msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4060                 else
4061                         msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4062 #else
4063                 if (percentage > 95)
4064                         msg_format("%^s barely notices.", m_name);
4065                 else if (percentage > 75)
4066                         msg_format("%^s flinches.", m_name);
4067                 else if (percentage > 50)
4068                         msg_format("%^s squelches.", m_name);
4069                 else if (percentage > 35)
4070                         msg_format("%^s quivers in pain.", m_name);
4071                 else if (percentage > 20)
4072                         msg_format("%^s writhes about.", m_name);
4073                 else if (percentage > 10)
4074                         msg_format("%^s writhes in agony.", m_name);
4075                 else
4076                         msg_format("%^s jerks limply.", m_name);
4077 #endif
4078
4079         }
4080
4081
4082         /* Fish */
4083         else if (strchr("l", r_ptr->d_char))
4084         {
4085                 if (percentage > 95)
4086 #ifdef JP
4087 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4088 #else
4089                         msg_format("%^s barely notices.", m_name);
4090 #endif
4091                 else if (percentage > 75)
4092 #ifdef JP
4093 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4094 #else
4095                         msg_format("%^s flinches.", m_name);
4096 #endif
4097                 else if (percentage > 50)
4098 #ifdef JP
4099 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4100 #else
4101                         msg_format("%^s hesitates.", m_name);
4102 #endif
4103                 else if (percentage > 35)
4104 #ifdef JP
4105 msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4106 #else
4107                         msg_format("%^s quivers in pain.", m_name);
4108 #endif
4109                 else if (percentage > 20)
4110 #ifdef JP
4111 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4112 #else
4113                         msg_format("%^s writhes about.", m_name);
4114 #endif
4115                 else if (percentage > 10)
4116 #ifdef JP
4117 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4118 #else
4119                         msg_format("%^s writhes in agony.", m_name);
4120 #endif
4121                 else
4122 #ifdef JP
4123 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4124 #else
4125                         msg_format("%^s jerks limply.", m_name);
4126 #endif
4127         }
4128
4129
4130         /* Golems, Walls, Doors, Stairs */
4131         else if (strchr("g#+<>", r_ptr->d_char))
4132         {
4133                 if (percentage > 95)
4134 #ifdef JP
4135 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4136 #else
4137                         msg_format("%^s ignores the attack.", m_name);
4138 #endif
4139                 else if (percentage > 75)
4140 #ifdef JP
4141 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4142 #else
4143                         msg_format("%^s shrugs off the attack.", m_name);
4144 #endif
4145                 else if (percentage > 50)
4146 #ifdef JP
4147 msg_format("%^s¤ÏÍëÌĤΤ褦¤ËËʤ¨¤¿¡£", m_name);
4148 #else
4149                         msg_format("%^s roars thunderously.", m_name);
4150 #endif
4151                 else if (percentage > 35)
4152 #ifdef JP
4153 msg_format("%^s¤Ï¶ì¤·¤²¤ËËʤ¨¤¿¡£", m_name);
4154 #else
4155                         msg_format("%^s rumbles.", m_name);
4156 #endif
4157                 else if (percentage > 20)
4158 #ifdef JP
4159 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4160 #else
4161                         msg_format("%^s grunts.", m_name);
4162 #endif
4163                 else if (percentage > 10)
4164 #ifdef JP
4165 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4166 #else
4167                         msg_format("%^s hesitates.", m_name);
4168 #endif
4169                 else
4170 #ifdef JP
4171 msg_format("%^s¤Ï¤¯¤·¤ã¤¯¤·¤ã¤Ë¤Ê¤Ã¤¿¡£", m_name);
4172 #else
4173                         msg_format("%^s crumples.", m_name);
4174 #endif
4175         }
4176
4177
4178         /* Snakes, Hydrae, Reptiles, Mimics */
4179         else if (strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char))
4180         {
4181                 if (percentage > 95)
4182 #ifdef JP
4183 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4184 #else
4185                         msg_format("%^s barely notices.", m_name);
4186 #endif
4187                 else if (percentage > 75)
4188 #ifdef JP
4189 msg_format("%^s¤Ï¥·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4190 #else
4191                         msg_format("%^s hisses.", m_name);
4192 #endif
4193                 else if (percentage > 50)
4194 #ifdef JP
4195 msg_format("%^s¤ÏÅܤäÆƬ¤ò¾å¤²¤¿¡£", m_name);
4196 #else
4197                         msg_format("%^s rears up in anger.", m_name);
4198 #endif
4199                 else if (percentage > 35)
4200 #ifdef JP
4201 msg_format("%^s¤ÏÌÔÁ³¤È°Ò³Å¤·¤¿¡£", m_name);
4202 #else
4203                         msg_format("%^s hisses furiously.", m_name);
4204 #endif
4205                 else if (percentage > 20)
4206 #ifdef JP
4207 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4208 #else
4209                         msg_format("%^s writhes about.", m_name);
4210 #endif
4211                 else if (percentage > 10)
4212 #ifdef JP
4213 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4214 #else
4215                         msg_format("%^s writhes in agony.", m_name);
4216 #endif
4217                 else
4218 #ifdef JP
4219 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4220 #else
4221                         msg_format("%^s jerks limply.", m_name);
4222 #endif
4223         }
4224
4225
4226         /* Felines */
4227         else if (strchr("f", r_ptr->d_char))
4228         {
4229                 if (percentage > 95)
4230 #ifdef JP
4231 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4232 #else
4233                         msg_format("%^s shrugs off the attack.", m_name);
4234 #endif
4235                 else if (percentage > 75)
4236 #ifdef JP
4237 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4238 #else
4239                         msg_format("%^s roars.", m_name);
4240 #endif
4241                 else if (percentage > 50)
4242 #ifdef JP
4243 msg_format("%^s¤ÏÅܤäÆËʤ¨¤¿¡£", m_name);
4244 #else
4245                         msg_format("%^s growls angrily.", m_name);
4246 #endif
4247                 else if (percentage > 35)
4248 #ifdef JP
4249 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4250 #else
4251                         msg_format("%^s hisses with pain.", m_name);
4252 #endif
4253                 else if (percentage > 20)
4254 #ifdef JP
4255 msg_format("%^s¤ÏÄˤߤǼ塹¤·¤¯ÌĤ¤¤¿¡£", m_name);
4256 #else
4257                         msg_format("%^s mewls in pain.", m_name);
4258 #endif
4259                 else if (percentage > 10)
4260 #ifdef JP
4261 msg_format("%^s¤Ï¶ìÄˤˤ¦¤á¤¤¤¿¡£", m_name);
4262 #else
4263                         msg_format("%^s hisses in agony.", m_name);
4264 #endif
4265                 else
4266 #ifdef JP
4267 msg_format("%s¤Ï°¥¤ì¤ÊÌĤ­À¼¤ò½Ð¤·¤¿¡£", m_name);
4268 #else
4269                         msg_format("%^s mewls pitifully.", m_name);
4270 #endif
4271         }
4272
4273
4274         /* Ants, Centipedes, Flies, Insects, Beetles, Spiders */
4275         else if (strchr("acFIKS", r_ptr->d_char))
4276         {
4277                 if (percentage > 95)
4278 #ifdef JP
4279 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4280 #else
4281                         msg_format("%^s ignores the attack.", m_name);
4282 #endif
4283                 else if (percentage > 75)
4284 #ifdef JP
4285 msg_format("%^s¤Ï¥­¡¼¥­¡¼ÌĤ¤¤¿¡£", m_name);
4286 #else
4287                         msg_format("%^s chitters.", m_name);
4288 #endif
4289
4290                 else if (percentage > 50)
4291 #ifdef JP
4292 msg_format("%^s¤Ï¥è¥í¥è¥íƨ¤²²ó¤Ã¤¿¡£", m_name);
4293 #else
4294                         msg_format("%^s scuttles about.", m_name);
4295 #endif
4296
4297                 else if (percentage > 35)
4298 #ifdef JP
4299 msg_format("%^s¤Ï¤¦¤ë¤µ¤¯ÌĤ¤¤¿¡£", m_name);
4300 #else
4301                         msg_format("%^s twitters.", m_name);
4302 #endif
4303
4304                 else if (percentage > 20)
4305 #ifdef JP
4306 msg_format("%^s¤ÏÄˤߤËáÛÚ»¤·¤¿¡£", m_name);
4307 #else
4308                         msg_format("%^s jerks in pain.", m_name);
4309 #endif
4310
4311                 else if (percentage > 10)
4312 #ifdef JP
4313 msg_format("%^s¤Ï¶ìÄˤÇáÛÚ»¤·¤¿¡£", m_name);
4314 #else
4315                         msg_format("%^s jerks in agony.", m_name);
4316 #endif
4317
4318                 else
4319 #ifdef JP
4320 msg_format("%^s¤Ï¥Ô¥¯¥Ô¥¯¤Ò¤­¤Ä¤Ã¤¿¡£", m_name);
4321 #else
4322                         msg_format("%^s twitches.", m_name);
4323 #endif
4324
4325         }
4326
4327
4328         /* Birds */
4329         else if (strchr("B", r_ptr->d_char))
4330         {
4331                 if (percentage > 95)
4332 #ifdef JP
4333 msg_format("%^s¤Ï¤µ¤¨¤º¤Ã¤¿¡£", m_name);
4334 #else
4335                         msg_format("%^s chirps.", m_name);
4336 #endif
4337
4338                 else if (percentage > 75)
4339 #ifdef JP
4340 msg_format("%^s¤Ï¥Ô¡¼¥Ô¡¼ÌĤ¤¤¿¡£", m_name);
4341 #else
4342                         msg_format("%^s twitters.", m_name);
4343 #endif
4344
4345                 else if (percentage > 50)
4346 #ifdef JP
4347 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ¤¤¿¡£", m_name);
4348 #else
4349                         msg_format("%^s squawks.", m_name);
4350 #endif
4351
4352                 else if (percentage > 35)
4353 #ifdef JP
4354 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ­¤ï¤á¤¤¤¿¡£", m_name);
4355 #else
4356                         msg_format("%^s chatters.", m_name);
4357 #endif
4358
4359                 else if (percentage > 20)
4360 #ifdef JP
4361 msg_format("%^s¤Ï¶ì¤·¤ó¤À¡£", m_name);
4362 #else
4363                         msg_format("%^s jeers.", m_name);
4364 #endif
4365
4366                 else if (percentage > 10)
4367 #ifdef JP
4368 msg_format("%^s¤Ï¤Î¤¿¤¦¤Á²ó¤Ã¤¿¡£", m_name);
4369 #else
4370                         msg_format("%^s flutters about.", m_name);
4371 #endif
4372
4373                 else
4374 #ifdef JP
4375 msg_format("%^s¤Ï¥­¡¼¥­¡¼¤ÈÌĤ­¶«¤ó¤À¡£", m_name);
4376 #else
4377                         msg_format("%^s squeaks.", m_name);
4378 #endif
4379
4380         }
4381
4382
4383         /* Dragons, Demons, High Undead */
4384         else if (strchr("duDLUW", r_ptr->d_char))
4385         {
4386                 if (percentage > 95)
4387 #ifdef JP
4388 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4389 #else
4390                         msg_format("%^s ignores the attack.", m_name);
4391 #endif
4392
4393                 else if (percentage > 75)
4394 #ifdef JP
4395 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4396 #else
4397                         msg_format("%^s flinches.", m_name);
4398 #endif
4399
4400                 else if (percentage > 50)
4401 #ifdef JP
4402 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4403 #else
4404                         msg_format("%^s hisses in pain.", m_name);
4405 #endif
4406
4407                 else if (percentage > 35)
4408 #ifdef JP
4409 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4410 #else
4411                         msg_format("%^s snarls with pain.", m_name);
4412 #endif
4413
4414                 else if (percentage > 20)
4415 #ifdef JP
4416 msg_format("%^s¤ÏÄˤߤËËʤ¨¤¿¡£", m_name);
4417 #else
4418                         msg_format("%^s roars with pain.", m_name);
4419 #endif
4420
4421                 else if (percentage > 10)
4422 #ifdef JP
4423 msg_format("%^s¤Ï¶ì¤·¤²¤Ë¶«¤ó¤À¡£", m_name);
4424 #else
4425                         msg_format("%^s gasps.", m_name);
4426 #endif
4427
4428                 else
4429 #ifdef JP
4430 msg_format("%^s¤Ï¼å¡¹¤·¤¯¤¦¤Ê¤Ã¤¿¡£", m_name);
4431 #else
4432                         msg_format("%^s snarls feebly.", m_name);
4433 #endif
4434
4435         }
4436
4437
4438         /* Skeletons */
4439         else if (strchr("s", r_ptr->d_char))
4440         {
4441                 if (percentage > 95)
4442 #ifdef JP
4443 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4444 #else
4445                         msg_format("%^s ignores the attack.", m_name);
4446 #endif
4447
4448                 else if (percentage > 75)
4449 #ifdef JP
4450 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4451 #else
4452                         msg_format("%^s shrugs off the attack.", m_name);
4453 #endif
4454
4455                 else if (percentage > 50)
4456 #ifdef JP
4457 msg_format("%^s¤Ï¥«¥¿¥«¥¿¤È¾Ð¤Ã¤¿¡£", m_name);
4458 #else
4459                         msg_format("%^s rattles.", m_name);
4460 #endif
4461
4462                 else if (percentage > 35)
4463 #ifdef JP
4464 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4465 #else
4466                         msg_format("%^s stumbles.", m_name);
4467 #endif
4468
4469                 else if (percentage > 20)
4470 #ifdef JP
4471 msg_format("%^s¤Ï¥«¥¿¥«¥¿¸À¤Ã¤¿¡£", m_name);
4472 #else
4473                         msg_format("%^s rattles.", m_name);
4474 #endif
4475
4476                 else if (percentage > 10)
4477 #ifdef JP
4478 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4479 #else
4480                         msg_format("%^s staggers.", m_name);
4481 #endif
4482
4483                 else
4484 #ifdef JP
4485 msg_format("%^s¤Ï¥¬¥¿¥¬¥¿¸À¤Ã¤¿¡£", m_name);
4486 #else
4487                         msg_format("%^s clatters.", m_name);
4488 #endif
4489
4490         }
4491
4492
4493         /* Zombies */
4494         else if (strchr("z", r_ptr->d_char))
4495         {
4496                 if (percentage > 95)
4497 #ifdef JP
4498 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4499 #else
4500                         msg_format("%^s ignores the attack.", m_name);
4501 #endif
4502
4503                 else if (percentage > 75)
4504 #ifdef JP
4505 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4506 #else
4507                         msg_format("%^s shrugs off the attack.", m_name);
4508 #endif
4509
4510                 else if (percentage > 50)
4511 #ifdef JP
4512 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4513 #else
4514                         msg_format("%^s groans.", m_name);
4515 #endif
4516
4517                 else if (percentage > 35)
4518 #ifdef JP
4519 msg_format("%s¤Ï¶ì¤·¤²¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4520 #else
4521                         msg_format("%^s moans.", m_name);
4522 #endif
4523
4524                 else if (percentage > 20)
4525 #ifdef JP
4526 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4527 #else
4528                         msg_format("%^s hesitates.", m_name);
4529 #endif
4530
4531                 else if (percentage > 10)
4532 #ifdef JP
4533 msg_format("%^s¤Ï¤¦¤Ê¤Ã¤¿¡£", m_name);
4534 #else
4535                         msg_format("%^s grunts.", m_name);
4536 #endif
4537
4538                 else
4539 #ifdef JP
4540 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4541 #else
4542                         msg_format("%^s staggers.", m_name);
4543 #endif
4544
4545         }
4546
4547
4548         /* Ghosts */
4549         else if (strchr("G", r_ptr->d_char))
4550
4551         {
4552                 if (percentage > 95)
4553 #ifdef JP
4554 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4555 #else
4556                         msg_format("%^s ignores the attack.", m_name);
4557 #endif
4558
4559                 else if (percentage > 75)
4560 #ifdef JP
4561 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4562 #else
4563                         msg_format("%^s shrugs off the attack.", m_name);
4564 #endif
4565
4566                 else if (percentage > 50)
4567 #ifdef JP
4568 msg_format("%s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4569 #else
4570                         msg_format("%^s moans.", m_name);
4571 #endif
4572
4573                 else if (percentage > 35)
4574 #ifdef JP
4575 msg_format("%^s¤Ïµã¤­¤ï¤á¤¤¤¿¡£", m_name);
4576 #else
4577                         msg_format("%^s wails.", m_name);
4578 #endif
4579
4580                 else if (percentage > 20)
4581 #ifdef JP
4582 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4583 #else
4584                         msg_format("%^s howls.", m_name);
4585 #endif
4586
4587                 else if (percentage > 10)
4588 #ifdef JP
4589 msg_format("%s¤Ï¼å¡¹¤·¤¯¤¦¤á¤¤¤¿¡£", m_name);
4590 #else
4591                         msg_format("%^s moans softly.", m_name);
4592 #endif
4593
4594                 else
4595 #ifdef JP
4596 msg_format("%^s¤Ï¤«¤¹¤«¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4597 #else
4598                         msg_format("%^s sighs.", m_name);
4599 #endif
4600
4601         }
4602
4603
4604         /* Dogs and Hounds */
4605         else if (strchr("CZ", r_ptr->d_char))
4606         {
4607 #ifdef JP
4608                 if (percentage > 95)
4609                         msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4610                 else if (percentage > 75)
4611                         msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4612                 else if (percentage > 50)
4613                         msg_format("%^s¤ÏÄˤߤǥ­¥ã¥ó¥­¥ã¥óËʤ¨¤¿¡£", m_name);
4614                 else if (percentage > 35)
4615                         msg_format("%^s¤ÏÄˤߤÇÌĤ­¤ï¤á¤¤¤¿¡£", m_name);
4616                 else if (percentage > 20)
4617                         msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÌĤ­¤ï¤á¤¤¤¿¡£", m_name);
4618                 else if (percentage > 10)
4619                         msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4620                 else
4621                         msg_format("%^s¤Ï¼å¡¹¤·¤¯Ëʤ¨¤¿¡£", m_name);
4622 #else
4623                 if (percentage > 95)
4624                         msg_format("%^s shrugs off the attack.", m_name);
4625                 else if (percentage > 75)
4626                         msg_format("%^s snarls with pain.", m_name);
4627                 else if (percentage > 50)
4628                         msg_format("%^s yelps in pain.", m_name);
4629                 else if (percentage > 35)
4630                         msg_format("%^s howls in pain.", m_name);
4631                 else if (percentage > 20)
4632                         msg_format("%^s howls in agony.", m_name);
4633                 else if (percentage > 10)
4634                         msg_format("%^s writhes in agony.", m_name);
4635                 else
4636                         msg_format("%^s yelps feebly.", m_name);
4637 #endif
4638
4639         }
4640
4641         /* One type of monsters (ignore,squeal,shriek) */
4642         else if (strchr("Xbilqrt", r_ptr->d_char))
4643         {
4644 #ifdef JP
4645                 if (percentage > 95)
4646                         msg_format("%^s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4647                 else if (percentage > 75)
4648                         msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4649                 else if (percentage > 50)
4650                         msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4651                 else if (percentage > 35)
4652                         msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4653                 else if (percentage > 20)
4654                         msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4655                 else if (percentage > 10)
4656                         msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4657                 else
4658                         msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4659 #else
4660                 if (percentage > 95)
4661                         msg_format("%^s ignores the attack.", m_name);
4662                 else if (percentage > 75)
4663                         msg_format("%^s grunts with pain.", m_name);
4664                 else if (percentage > 50)
4665                         msg_format("%^s squeals in pain.", m_name);
4666                 else if (percentage > 35)
4667                         msg_format("%^s shrieks in pain.", m_name);
4668                 else if (percentage > 20)
4669                         msg_format("%^s shrieks in agony.", m_name);
4670                 else if (percentage > 10)
4671                         msg_format("%^s writhes in agony.", m_name);
4672                 else
4673                         msg_format("%^s cries out feebly.", m_name);
4674 #endif
4675
4676         }
4677
4678         /* Another type of monsters (shrug,cry,scream) */
4679         else
4680         {
4681 #ifdef JP
4682                 if (percentage > 95)
4683                         msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4684                 else if (percentage > 75)
4685                         msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4686                 else if (percentage > 50)
4687                         msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4688                 else if (percentage > 35)
4689                         msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4690                 else if (percentage > 20)
4691                         msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4692                 else if (percentage > 10)
4693                         msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4694                 else
4695                         msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4696 #else
4697                 if (percentage > 95)
4698                         msg_format("%^s shrugs off the attack.", m_name);
4699                 else if (percentage > 75)
4700                         msg_format("%^s grunts with pain.", m_name);
4701                 else if (percentage > 50)
4702                         msg_format("%^s cries out in pain.", m_name);
4703                 else if (percentage > 35)
4704                         msg_format("%^s screams in pain.", m_name);
4705                 else if (percentage > 20)
4706                         msg_format("%^s screams in agony.", m_name);
4707                 else if (percentage > 10)
4708                         msg_format("%^s writhes in agony.", m_name);
4709                 else
4710                         msg_format("%^s cries out feebly.", m_name);
4711 #endif
4712
4713         }
4714 }
4715
4716
4717 /*
4718  * Learn about an "observed" resistance.
4719  */
4720 void update_smart_learn(int m_idx, int what)
4721 {
4722 #ifdef DRS_SMART_OPTIONS
4723
4724         monster_type *m_ptr = &m_list[m_idx];
4725
4726         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4727
4728
4729         /* Not allowed to learn */
4730         if (!smart_learn) return;
4731
4732         /* Too stupid to learn anything */
4733         if (r_ptr->flags2 & (RF2_STUPID)) return;
4734
4735         /* Not intelligent, only learn sometimes */
4736         if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
4737
4738
4739         /* XXX XXX XXX */
4740
4741         /* Analyze the knowledge */
4742         switch (what)
4743         {
4744         case DRS_ACID:
4745                 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
4746                 if (p_ptr->oppose_acid) m_ptr->smart |= (SM_OPP_ACID);
4747                 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
4748                 break;
4749
4750         case DRS_ELEC:
4751                 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
4752                 if (p_ptr->oppose_elec) m_ptr->smart |= (SM_OPP_ELEC);
4753                 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
4754                 break;
4755
4756         case DRS_FIRE:
4757                 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
4758                 if (p_ptr->oppose_fire) m_ptr->smart |= (SM_OPP_FIRE);
4759                 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
4760                 break;
4761
4762         case DRS_COLD:
4763                 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
4764                 if (p_ptr->oppose_cold) m_ptr->smart |= (SM_OPP_COLD);
4765                 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
4766                 break;
4767
4768         case DRS_POIS:
4769                 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
4770                 if (p_ptr->oppose_pois) m_ptr->smart |= (SM_OPP_POIS);
4771                 break;
4772
4773
4774         case DRS_NETH:
4775                 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
4776                 break;
4777
4778         case DRS_LITE:
4779                 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
4780                 break;
4781
4782         case DRS_DARK:
4783                 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
4784                 break;
4785
4786         case DRS_FEAR:
4787                 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
4788                 break;
4789
4790         case DRS_CONF:
4791                 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
4792                 break;
4793
4794         case DRS_CHAOS:
4795                 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
4796                 break;
4797
4798         case DRS_DISEN:
4799                 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
4800                 break;
4801
4802         case DRS_BLIND:
4803                 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
4804                 break;
4805
4806         case DRS_NEXUS:
4807                 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
4808                 break;
4809
4810         case DRS_SOUND:
4811                 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
4812                 break;
4813
4814         case DRS_SHARD:
4815                 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
4816                 break;
4817
4818         case DRS_FREE:
4819                 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
4820                 break;
4821
4822         case DRS_MANA:
4823                 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
4824                 break;
4825
4826         case DRS_REFLECT:
4827                 if (p_ptr->reflect) m_ptr-> smart |= (SM_IMM_REFLECT);
4828                 break;
4829         }
4830
4831 #endif /* DRS_SMART_OPTIONS */
4832
4833 }
4834
4835
4836 /*
4837  * Place the player in the dungeon XXX XXX
4838  */
4839 bool player_place(int y, int x)
4840 {
4841         /* Paranoia XXX XXX */
4842         if (cave[y][x].m_idx != 0) return FALSE;
4843
4844         /* Save player location */
4845         py = y;
4846         px = x;
4847
4848         /* Success */
4849         return TRUE;
4850 }
4851
4852
4853 /*
4854  * Drop all items carried by a monster
4855  */
4856 void monster_drop_carried_objects(monster_type *m_ptr)
4857 {
4858         s16b this_o_idx, next_o_idx = 0;
4859         object_type forge;
4860         object_type *o_ptr;
4861         object_type *q_ptr;
4862
4863
4864         /* Drop objects being carried */
4865         for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4866         {
4867                 /* Acquire object */
4868                 o_ptr = &o_list[this_o_idx];
4869
4870                 /* Acquire next object */
4871                 next_o_idx = o_ptr->next_o_idx;
4872
4873                 /* Paranoia */
4874                 o_ptr->held_m_idx = 0;
4875
4876                 /* Get local object */
4877                 q_ptr = &forge;
4878
4879                 /* Copy the object */
4880                 object_copy(q_ptr, o_ptr);
4881
4882                 /* Delete the object */
4883                 delete_object_idx(this_o_idx);
4884
4885                 /* Drop it */
4886                 (void)drop_near(q_ptr, -1, m_ptr->fy, m_ptr->fx);
4887         }
4888
4889         /* Forget objects */
4890         m_ptr->hold_o_idx = 0;
4891 }