OSDN Git Service

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