OSDN Git Service

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