OSDN Git Service

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