OSDN Git Service

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