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 || p_ptr->inside_quest < MIN_RANDOM_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  *
1528  * Useful Modes:
1529  *   0x00 --> Full nominative name ("the kobold") or "it"
1530  *   0x04 --> Full nominative name ("the kobold") or "something"
1531  *   0x80 --> Genocide resistance name ("the kobold")
1532  *   0x88 --> Killing name ("a kobold")
1533  *   0x22 --> Possessive, genderized if visable ("his") or "its"
1534  *   0x23 --> Reflexive, genderized if visable ("himself") or "itself"
1535  */
1536 void monster_desc(char *desc, monster_type *m_ptr, int mode)
1537 {
1538         cptr            res;
1539         monster_race    *r_ptr;
1540
1541         cptr            name;
1542         char            buf[128];
1543         char            silly_name[1024];
1544         bool            seen, pron;
1545         bool            named = FALSE;
1546
1547         r_ptr = &r_info[m_ptr->ap_r_idx];
1548
1549         /* Mode of 0x100 will reveal Chameleon's true name */
1550         if (mode & 0x100) name = (r_name + real_r_ptr(m_ptr)->name);
1551         else name = (r_name + r_ptr->name);
1552
1553         /* Are we hallucinating? (Idea from Nethack...) */
1554         if (p_ptr->image && !(mode & 0x200))
1555         {
1556                 if (one_in_(2))
1557                 {
1558 #ifdef JP
1559 if (!get_rnd_line("silly_j.txt", m_ptr->r_idx, silly_name))
1560 #else
1561                         if (!get_rnd_line("silly.txt", m_ptr->r_idx, silly_name))
1562 #endif
1563
1564                                 named = TRUE;
1565                 }
1566
1567                 if (!named)
1568                 {
1569                         monster_race *hallu_race;
1570
1571                         do
1572                         {
1573                                 hallu_race = &r_info[randint1(max_r_idx - 1)];
1574                         }
1575                         while (hallu_race->flags1 & RF1_UNIQUE);
1576
1577                         strcpy(silly_name, (r_name + hallu_race->name));
1578                 }
1579
1580                 /* Better not strcpy it, or we could corrupt r_info... */
1581                 name = silly_name;
1582         }
1583
1584         /* Can we "see" it (exists + forced, or visible + not unforced) */
1585         seen = (m_ptr && ((mode & 0x80) || (!(mode & 0x40) && m_ptr->ml)));
1586
1587         /* Sexed Pronouns (seen and allowed, or unseen and allowed) */
1588         pron = (m_ptr && ((seen && (mode & 0x20)) || (!seen && (mode & 0x10))));
1589
1590
1591         /* First, try using pronouns, or describing hidden monsters */
1592         if (!seen || pron)
1593         {
1594                 /* an encoding of the monster "sex" */
1595                 int kind = 0x00;
1596
1597                 /* Extract the gender (if applicable) */
1598                 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1599                 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1600
1601                 /* Ignore the gender (if desired) */
1602                 if (!m_ptr || !pron) kind = 0x00;
1603
1604
1605                 /* Assume simple result */
1606 #ifdef JP
1607                 res = "²¿¤«";
1608 #else
1609                 res = "it";
1610 #endif
1611
1612
1613                 /* Brute force: split on the possibilities */
1614                 switch (kind + (mode & 0x07))
1615                 {
1616                         /* Neuter, or unknown */
1617 #ifdef JP
1618                         case 0x00: res = "²¿¤«"; break;
1619                         case 0x01: res = "²¿¤«"; break;
1620                         case 0x02: res = "²¿¤«¤Î"; break;
1621                         case 0x03: res = "²¿¤«¼«¿È"; break;
1622                         case 0x04: res = "²¿¤«"; break;
1623                         case 0x05: res = "²¿¤«"; break;
1624                         case 0x06: res = "²¿¤«"; break;
1625                         case 0x07: res = "¤½¤ì¼«¿È"; break;
1626 #else
1627                         case 0x00: res = "it"; break;
1628                         case 0x01: res = "it"; break;
1629                         case 0x02: res = "its"; break;
1630                         case 0x03: res = "itself"; break;
1631                         case 0x04: res = "something"; break;
1632                         case 0x05: res = "something"; break;
1633                         case 0x06: res = "something's"; break;
1634                         case 0x07: res = "itself"; break;
1635 #endif
1636
1637
1638                         /* Male (assume human if vague) */
1639 #ifdef JP
1640                         case 0x10: res = "Èà"; break;
1641                         case 0x11: res = "Èà"; break;
1642                         case 0x12: res = "Èà¤Î"; break;
1643                         case 0x13: res = "È༫¿È"; break;
1644                         case 0x14: res = "狼"; break;
1645                         case 0x15: res = "狼"; break;
1646                         case 0x16: res = "狼¤Î"; break;
1647                         case 0x17: res = "È༫¿È"; break;
1648 #else
1649                         case 0x10: res = "he"; break;
1650                         case 0x11: res = "him"; break;
1651                         case 0x12: res = "his"; break;
1652                         case 0x13: res = "himself"; break;
1653                         case 0x14: res = "someone"; break;
1654                         case 0x15: res = "someone"; break;
1655                         case 0x16: res = "someone's"; break;
1656                         case 0x17: res = "himself"; break;
1657 #endif
1658
1659
1660                         /* Female (assume human if vague) */
1661 #ifdef JP
1662                         case 0x20: res = "Èà½÷"; break;
1663                         case 0x21: res = "Èà½÷"; break;
1664                         case 0x22: res = "Èà½÷¤Î"; break;
1665                         case 0x23: res = "Èà½÷¼«¿È"; break;
1666                         case 0x24: res = "狼"; break;
1667                         case 0x25: res = "狼"; break;
1668                         case 0x26: res = "狼¤Î"; break;
1669                         case 0x27: res = "Èà½÷¼«¿È"; break;
1670 #else
1671                         case 0x20: res = "she"; break;
1672                         case 0x21: res = "her"; break;
1673                         case 0x22: res = "her"; break;
1674                         case 0x23: res = "herself"; break;
1675                         case 0x24: res = "someone"; break;
1676                         case 0x25: res = "someone"; break;
1677                         case 0x26: res = "someone's"; break;
1678                         case 0x27: res = "herself"; break;
1679 #endif
1680
1681                 }
1682
1683                 /* Copy the result */
1684                 (void)strcpy(desc, res);
1685         }
1686
1687
1688         /* Handle visible monsters, "reflexive" request */
1689         else if ((mode & 0x02) && (mode & 0x01))
1690         {
1691                 /* The monster is visible, so use its gender */
1692 #ifdef JP
1693                 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, "Èà½÷¼«¿È");
1694                 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, "È༫¿È");
1695                 else strcpy(desc, "¤½¤ì¼«¿È");
1696 #else
1697                 if (r_ptr->flags1 & RF1_FEMALE) strcpy(desc, "herself");
1698                 else if (r_ptr->flags1 & RF1_MALE) strcpy(desc, "himself");
1699                 else strcpy(desc, "itself");
1700 #endif
1701
1702         }
1703
1704
1705         /* Handle all other visible monster requests */
1706         else
1707         {
1708                 /* Tanuki? */
1709                 if (is_pet(m_ptr) && m_ptr->ap_r_idx != m_ptr->r_idx)
1710                 {
1711 #ifdef JP
1712                                 char *t;
1713                                 strcpy(buf, name);
1714                                 t = buf;
1715                                 while(strncmp(t, "¡Ù", 2) && *t) t++;
1716                                 if (*t)
1717                                 {
1718                                         *t = '\0';
1719                                         (void)sprintf(desc, "%s¡©¡Ù", buf);
1720                                 }
1721                                 else
1722                                         (void)sprintf(desc, "%s¡©", name);
1723 #else
1724                                 (void)sprintf(desc, "%s?", name);
1725 #endif
1726                 }
1727                 else
1728
1729                 /* It could be a Unique */
1730                 if ((r_ptr->flags1 & RF1_UNIQUE) && !(p_ptr->image && !(mode & 0x200)))
1731                 {
1732                         /* Start with the name (thus nominative and objective) */
1733                         if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & 0x100))
1734                         {
1735 #ifdef JP
1736                                 char *t;
1737                                 strcpy(buf, name);
1738                                 t = buf;
1739                                 while(strncmp(t, "¡Ù", 2) && *t) t++;
1740                                 if (*t)
1741                                 {
1742                                         *t = '\0';
1743                                         (void)sprintf(desc, "%s¡©¡Ù", buf);
1744                                 }
1745                                 else
1746                                         (void)sprintf(desc, "%s¡©", name);
1747 #else
1748                                 (void)sprintf(desc, "%s?", name);
1749 #endif
1750                         }
1751                         else if ((cave[m_ptr->fy][m_ptr->fx].m_idx == p_ptr->riding) || !p_ptr->inside_battle)
1752                                 (void)strcpy(desc, name);
1753                         else
1754 #ifdef JP
1755                                 (void)sprintf(desc, "%s¤â¤É¤­", name);
1756 #else
1757                                 (void)sprintf(desc, "fake %s", name);
1758 #endif
1759                 }
1760
1761                 /* It could be an indefinite monster */
1762                 else if (mode & 0x08)
1763                 {
1764                         /* XXX Check plurality for "some" */
1765
1766                         /* Indefinite monsters need an indefinite article */
1767 #ifdef JP
1768                         (void)strcpy(desc, "");
1769 #else
1770                         (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1771 #endif
1772
1773                         (void)strcat(desc, name);
1774                 }
1775
1776                 /* It could be a normal, definite, monster */
1777                 else
1778                 {
1779                         /* Definite monsters need a definite article */
1780                         if (is_pet(m_ptr))
1781 #ifdef JP
1782                                 (void)strcpy(desc, "¤¢¤Ê¤¿¤Î");
1783 #else
1784                                 (void)strcpy(desc, "your ");
1785 #endif
1786
1787                         else
1788 #ifdef JP
1789                                 (void)strcpy(desc, "");
1790 #else
1791                                 (void)strcpy(desc, "the ");
1792 #endif
1793
1794                         (void)strcat(desc, name);
1795                 }
1796
1797                 if (m_ptr->nickname)
1798                 {
1799 #ifdef JP
1800                         sprintf(buf,"¡Ö%s¡×",quark_str(m_ptr->nickname));
1801 #else
1802                         sprintf(buf," called %s",quark_str(m_ptr->nickname));
1803 #endif
1804                         strcat(desc,buf);
1805                 }
1806
1807                 if ((m_ptr->fy == py) && (m_ptr->fx == px))
1808                 {
1809 #ifdef JP
1810                         strcat(desc,"(¾èÇÏÃæ)");
1811 #else
1812                         strcat(desc,"(riding)");
1813 #endif
1814                 }
1815
1816                 if ((mode & 0x200) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1817                 {
1818                         if (r_ptr->flags1 & RF1_UNIQUE)
1819                         {
1820 #ifdef JP
1821                                 strcat(desc,"(¥«¥á¥ì¥ª¥ó¤Î²¦)");
1822 #else
1823                                 strcat(desc,"(Chameleon Lord)");
1824 #endif
1825                         }
1826                         else
1827                         {
1828 #ifdef JP
1829                                 strcat(desc,"(¥«¥á¥ì¥ª¥ó)");
1830 #else
1831                                 strcat(desc,"(Chameleon)");
1832 #endif
1833                         }
1834                 }
1835
1836                 if ((mode & 0x200) && m_ptr->ap_r_idx != m_ptr->r_idx)
1837                 {
1838                         strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1839                 }
1840
1841                 /* Handle the Possessive as a special afterthought */
1842                 if (mode & 0x02)
1843                 {
1844                         /* XXX Check for trailing "s" */
1845                         
1846                         /* Simply append "apostrophe" and "s" */
1847 #ifdef JP
1848                         (void)strcat(desc, "¤Î");
1849 #else
1850                         (void)strcat(desc, "'s");
1851 #endif
1852
1853                 }
1854         }
1855 }
1856
1857
1858
1859
1860 /*
1861  * Learn about a monster (by "probing" it)
1862  *
1863  * Return the number of new flags learnt.  -Mogami-
1864  */
1865 int lore_do_probe(int r_idx)
1866 {
1867         monster_race *r_ptr = &r_info[r_idx];
1868         int i, n = 0;
1869         byte tmp_byte;
1870
1871         /* Maximal info about awareness */
1872         if (r_ptr->r_wake != MAX_UCHAR) n++;
1873         if (r_ptr->r_ignore != MAX_UCHAR) n++;
1874         r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1875                                 
1876         /* Observe "maximal" attacks */
1877         for (i = 0; i < 4; i++)
1878         {
1879                 /* Examine "actual" blows */
1880                 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1881                 {
1882                         /* Maximal observations */
1883                         if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1884                         r_ptr->r_blows[i] = MAX_UCHAR;
1885                 }
1886         }
1887                                 
1888         /* Maximal drops */
1889         tmp_byte = 
1890                 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1891                  ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1892                  ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1893                  ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1894                  ((r_ptr->flags1 & RF1_DROP_90)  ? 1 : 0) +
1895                  ((r_ptr->flags1 & RF1_DROP_60)  ? 1 : 0));
1896
1897         /* Only "valid" drops */
1898         if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1899         {
1900                 if (r_ptr->r_drop_item != tmp_byte) n++;
1901                 r_ptr->r_drop_item = tmp_byte;
1902         }
1903         if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1904         {
1905                 if (r_ptr->r_drop_gold != tmp_byte) n++;
1906                 r_ptr->r_drop_gold = tmp_byte;
1907         }
1908                                 
1909         /* Observe many spells */
1910         if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1911         r_ptr->r_cast_spell = MAX_UCHAR;
1912                                 
1913         /* Count unknown flags */
1914         for (i = 0; i < 32; i++)
1915         {
1916                 if (!(r_ptr->r_flags1 & (1L << i)) &&
1917                     (r_ptr->flags1 & (1L << i))) n++;
1918                 if (!(r_ptr->r_flags2 & (1L << i)) &&
1919                     (r_ptr->flags2 & (1L << i))) n++;
1920                 if (!(r_ptr->r_flags3 & (1L << i)) &&
1921                     (r_ptr->flags3 & (1L << i))) n++;
1922                 if (!(r_ptr->r_flags4 & (1L << i)) &&
1923                     (r_ptr->flags4 & (1L << i))) n++;
1924                 if (!(r_ptr->r_flags5 & (1L << i)) &&
1925                     (r_ptr->flags5 & (1L << i))) n++;
1926                 if (!(r_ptr->r_flags6 & (1L << i)) &&
1927                     (r_ptr->flags6 & (1L << i))) n++;
1928
1929                 /* r_flags7 is actually unused */
1930 #if 0
1931                 if (!(r_ptr->r_flags7 & (1L << i)) &&
1932                     (r_ptr->flags7 & (1L << i))) n++;
1933 #endif
1934         }
1935
1936         /* Know all the flags */
1937         r_ptr->r_flags1 = r_ptr->flags1;
1938         r_ptr->r_flags2 = r_ptr->flags2;
1939         r_ptr->r_flags3 = r_ptr->flags3;
1940         r_ptr->r_flags4 = r_ptr->flags4;
1941         r_ptr->r_flags5 = r_ptr->flags5;
1942         r_ptr->r_flags6 = r_ptr->flags6;
1943
1944         /* r_flags7 is actually unused */
1945         /* r_ptr->r_flags7 = r_ptr->flags7; */
1946
1947         /* Know about evolution */
1948         if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1949         r_ptr->r_xtra1 |= MR1_SINKA;
1950
1951         /* Update monster recall window */
1952         if (p_ptr->monster_race_idx == r_idx)
1953         {
1954                 /* Window stuff */
1955                 p_ptr->window |= (PW_MONSTER);
1956         }
1957
1958         /* Return the number of new flags learnt */
1959         return n;
1960 }
1961
1962
1963 /*
1964  * Take note that the given monster just dropped some treasure
1965  *
1966  * Note that learning the "GOOD"/"GREAT" flags gives information
1967  * about the treasure (even when the monster is killed for the first
1968  * time, such as uniques, and the treasure has not been examined yet).
1969  *
1970  * This "indirect" method is used to prevent the player from learning
1971  * exactly how much treasure a monster can drop from observing only
1972  * a single example of a drop.  This method actually observes how much
1973  * gold and items are dropped, and remembers that information to be
1974  * described later by the monster recall code.
1975  */
1976 void lore_treasure(int m_idx, int num_item, int num_gold)
1977 {
1978         monster_type *m_ptr = &m_list[m_idx];
1979
1980         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1981
1982         /* Note the number of things dropped */
1983         if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1984         if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1985
1986         /* Hack -- memorize the good/great flags */
1987         if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1988         if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1989
1990         /* Update monster recall window */
1991         if (p_ptr->monster_race_idx == m_ptr->r_idx)
1992         {
1993                 /* Window stuff */
1994                 p_ptr->window |= (PW_MONSTER);
1995         }
1996 }
1997
1998
1999
2000 void sanity_blast(monster_type *m_ptr, bool necro)
2001 {
2002         bool happened = FALSE;
2003         int power = 100;
2004
2005         if (p_ptr->inside_battle || !character_dungeon) return;
2006
2007         if (!necro)
2008         {
2009                 char            m_name[80];
2010                 monster_race    *r_ptr = &r_info[m_ptr->r_idx];
2011
2012                 power = r_ptr->level / 2;
2013
2014                 monster_desc(m_name, m_ptr, 0);
2015
2016                 if (!(r_ptr->flags1 & RF1_UNIQUE))
2017                 {
2018                         if (r_ptr->flags1 & RF1_FRIENDS)
2019                         power /= 2;
2020                 }
2021                 else power *= 2;
2022
2023                 if (!hack_mind)
2024                         return; /* No effect yet, just loaded... */
2025
2026                 if (!m_ptr->ml)
2027                         return; /* Cannot see it for some reason */
2028
2029                 if (!(r_ptr->flags2 & RF2_ELDRITCH_HORROR))
2030                         return; /* oops */
2031
2032
2033
2034                 if (is_pet(m_ptr))
2035                         return; /* Pet eldritch horrors are safe most of the time */
2036
2037                 if (randint1(100) > power) return;
2038
2039                 if (saving_throw(p_ptr->skill_sav - power))
2040                 {
2041                         return; /* Save, no adverse effects */
2042                 }
2043
2044                 if (p_ptr->image)
2045                 {
2046                         /* Something silly happens... */
2047 #ifdef JP
2048                         msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2049                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2050 #else
2051                         msg_format("You behold the %s visage of %s!",
2052                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2053 #endif
2054
2055
2056                         if (one_in_(3))
2057                         {
2058                                 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
2059                                 p_ptr->image = p_ptr->image + randint1(r_ptr->level);
2060                         }
2061
2062                         return; /* Never mind; we can't see it clearly enough */
2063                 }
2064
2065                 /* Something frightening happens... */
2066 #ifdef JP
2067                 msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2068                         horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2069 #else
2070                 msg_format("You behold the %s visage of %s!",
2071                         horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2072 #endif
2073
2074                 r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
2075
2076                 /* Demon characters are unaffected */
2077                 if (prace_is_(RACE_IMP) || prace_is_(RACE_DEMON) || (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) return;
2078                 if (p_ptr->wizard) return;
2079
2080                 /* Undead characters are 50% likely to be unaffected */
2081                 if (prace_is_(RACE_SKELETON) || prace_is_(RACE_ZOMBIE)
2082                         || prace_is_(RACE_VAMPIRE) || prace_is_(RACE_SPECTRE) ||
2083                     (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD))
2084                 {
2085                         if (saving_throw(25 + p_ptr->lev)) return;
2086                 }
2087         }
2088         else
2089         {
2090 #ifdef JP
2091 msg_print("¥Í¥¯¥í¥Î¥ß¥³¥ó¤òÆɤó¤ÇÀµµ¤¤ò¼º¤Ã¤¿¡ª");
2092 #else
2093                 msg_print("Your sanity is shaken by reading the Necronomicon!");
2094 #endif
2095
2096         }
2097
2098         if (!saving_throw(p_ptr->skill_sav - power)) /* Mind blast */
2099         {
2100                 if (!p_ptr->resist_conf)
2101                 {
2102                         (void)set_confused(p_ptr->confused + randint0(4) + 4);
2103                 }
2104                 if (!p_ptr->resist_chaos && one_in_(3))
2105                 {
2106                         (void)set_image(p_ptr->image + randint0(250) + 150);
2107                 }
2108                 return;
2109         }
2110
2111         if (!saving_throw(p_ptr->skill_sav - power)) /* Lose int & wis */
2112         {
2113                 do_dec_stat(A_INT);
2114                 do_dec_stat(A_WIS);
2115                 return;
2116         }
2117
2118         if (!saving_throw(p_ptr->skill_sav - power)) /* Brain smash */
2119         {
2120                 if (!p_ptr->resist_conf)
2121                 {
2122                         (void)set_confused(p_ptr->confused + randint0(4) + 4);
2123                 }
2124                 if (!p_ptr->free_act)
2125                 {
2126                         (void)set_paralyzed(p_ptr->paralyzed + randint0(4) + 4);
2127                 }
2128                 while (randint0(100) > p_ptr->skill_sav)
2129                         (void)do_dec_stat(A_INT);
2130                 while (randint0(100) > p_ptr->skill_sav)
2131                         (void)do_dec_stat(A_WIS);
2132                 if (!p_ptr->resist_chaos)
2133                 {
2134                         (void)set_image(p_ptr->image + randint0(250) + 150);
2135                 }
2136                 return;
2137         }
2138
2139         if (!saving_throw(p_ptr->skill_sav - power)) /* Amnesia */
2140         {
2141
2142                 if (lose_all_info())
2143 #ifdef JP
2144 msg_print("¤¢¤Þ¤ê¤Î¶²ÉݤËÁ´¤Æ¤Î¤³¤È¤ò˺¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª");
2145 #else
2146                         msg_print("You forget everything in your utmost terror!");
2147 #endif
2148
2149                 return;
2150         }
2151
2152         if (saving_throw(p_ptr->skill_sav - power))
2153         {
2154                 return;
2155         }
2156
2157         /* Else gain permanent insanity */
2158         if ((p_ptr->muta3 & MUT3_MORONIC) && /*(p_ptr->muta2 & MUT2_BERS_RAGE) &&*/
2159                 ((p_ptr->muta2 & MUT2_COWARDICE) || (p_ptr->resist_fear)) &&
2160                 ((p_ptr->muta2 & MUT2_HALLU) || (p_ptr->resist_chaos)))
2161         {
2162                 /* The poor bastard already has all possible insanities! */
2163                 return;
2164         }
2165
2166         while (!happened)
2167         {
2168                 switch (randint1(21))
2169                 {
2170                         case 1:
2171                                 if (!(p_ptr->muta3 & MUT3_MORONIC) && one_in_(5))
2172                                 {
2173                                         if ((p_ptr->stat_use[A_INT] < 4) && (p_ptr->stat_use[A_WIS] < 4))
2174                                         {
2175 #ifdef JP
2176 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¤è¤¦¤Êµ¤¤¬¤·¤¿¡£¤·¤«¤·¤½¤ì¤Ï¸µ¡¹¤À¤Ã¤¿¡£");
2177 #else
2178                                                 msg_print("You turn into an utter moron!");
2179 #endif
2180                                         }
2181                                         else
2182                                         {
2183 #ifdef JP
2184 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¡ª");
2185 #else
2186                                                 msg_print("You turn into an utter moron!");
2187 #endif
2188                                         }
2189
2190                                         if (p_ptr->muta3 & MUT3_HYPER_INT)
2191                                         {
2192 #ifdef JP
2193 msg_print("¤¢¤Ê¤¿¤ÎǾ¤ÏÀ¸ÂÎ¥³¥ó¥Ô¥å¡¼¥¿¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2194 #else
2195                                                 msg_print("Your brain is no longer a living computer.");
2196 #endif
2197
2198                                                 p_ptr->muta3 &= ~(MUT3_HYPER_INT);
2199                                         }
2200                                         p_ptr->muta3 |= MUT3_MORONIC;
2201                                         happened = TRUE;
2202                                 }
2203                                 break;
2204                         case 2:
2205                         case 3:
2206                         case 4:
2207                         case 5:
2208                         case 6:
2209                         case 7:
2210                         case 8:
2211                         case 9:
2212                         case 10:
2213                         case 11:
2214                                 if (!(p_ptr->muta2 & MUT2_COWARDICE) && !p_ptr->resist_fear)
2215                                 {
2216 #ifdef JP
2217 msg_print("¤¢¤Ê¤¿¤Ï¥Ñ¥é¥Î¥¤¥¢¤Ë¤Ê¤Ã¤¿¡ª");
2218 #else
2219                                         msg_print("You become paranoid!");
2220 #endif
2221
2222
2223                                         /* Duh, the following should never happen, but anyway... */
2224                                         if (p_ptr->muta3 & MUT3_FEARLESS)
2225                                         {
2226 #ifdef JP
2227 msg_print("¤¢¤Ê¤¿¤Ï¤â¤¦¶²¤ìÃΤ餺¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2228 #else
2229                                                 msg_print("You are no longer fearless.");
2230 #endif
2231
2232                                                 p_ptr->muta3 &= ~(MUT3_FEARLESS);
2233                                         }
2234
2235                                         p_ptr->muta2 |= MUT2_COWARDICE;
2236                                         happened = TRUE;
2237                                 }
2238                                 break;
2239                         case 12:
2240                         case 13:
2241                         case 14:
2242                         case 15:
2243                         case 16:
2244                         case 17:
2245                         case 18:
2246                         case 19:
2247                         case 20:
2248                         case 21:
2249                                 if (!(p_ptr->muta2 & MUT2_HALLU) && !p_ptr->resist_chaos)
2250                                 {
2251 #ifdef JP
2252 msg_print("¸¸³Ð¤ò¤Ò¤­µ¯¤³¤¹Àº¿ÀºøÍð¤Ë´Ù¤Ã¤¿¡ª");
2253 #else
2254                                         msg_print("You are afflicted by a hallucinatory insanity!");
2255 #endif
2256
2257                                         p_ptr->muta2 |= MUT2_HALLU;
2258                                         happened = TRUE;
2259                                 }
2260                                 break;
2261                         default:
2262                                 if (!(p_ptr->muta2 & MUT2_BERS_RAGE))
2263                                 {
2264 #ifdef JP
2265 msg_print("·ãÎõ¤Ê´¶¾ð¤Îȯºî¤Ë¤ª¤½¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡ª");
2266 #else
2267                                         msg_print("You become subject to fits of berserk rage!");
2268 #endif
2269
2270                                         p_ptr->muta2 |= MUT2_BERS_RAGE;
2271                                         happened = TRUE;
2272                                 }
2273                                 break;
2274                 }
2275         }
2276
2277         p_ptr->update |= PU_BONUS;
2278         handle_stuff();
2279 }
2280
2281
2282 /*
2283  * This function updates the monster record of the given monster
2284  *
2285  * This involves extracting the distance to the player (if requested),
2286  * and then checking for visibility (natural, infravision, see-invis,
2287  * telepathy), updating the monster visibility flag, redrawing (or
2288  * erasing) the monster when its visibility changes, and taking note
2289  * of any interesting monster flags (cold-blooded, invisible, etc).
2290  *
2291  * Note the new "mflag" field which encodes several monster state flags,
2292  * including "view" for when the monster is currently in line of sight,
2293  * and "mark" for when the monster is currently visible via detection.
2294  *
2295  * The only monster fields that are changed here are "cdis" (the
2296  * distance from the player), "ml" (visible to the player), and
2297  * "mflag" (to maintain the "MFLAG_VIEW" flag).
2298  *
2299  * Note the special "update_monsters()" function which can be used to
2300  * call this function once for every monster.
2301  *
2302  * Note the "full" flag which requests that the "cdis" field be updated,
2303  * this is only needed when the monster (or the player) has moved.
2304  *
2305  * Every time a monster moves, we must call this function for that
2306  * monster, and update the distance, and the visibility.  Every time
2307  * the player moves, we must call this function for every monster, and
2308  * update the distance, and the visibility.  Whenever the player "state"
2309  * changes in certain ways ("blindness", "infravision", "telepathy",
2310  * and "see invisible"), we must call this function for every monster,
2311  * and update the visibility.
2312  *
2313  * Routines that change the "illumination" of a grid must also call this
2314  * function for any monster in that grid, since the "visibility" of some
2315  * monsters may be based on the illumination of their grid.
2316  *
2317  * Note that this function is called once per monster every time the
2318  * player moves.  When the player is running, this function is one
2319  * of the primary bottlenecks, along with "update_view()" and the
2320  * "process_monsters()" code, so efficiency is important.
2321  *
2322  * Note the optimized "inline" version of the "distance()" function.
2323  *
2324  * A monster is "visible" to the player if (1) it has been detected
2325  * by the player, (2) it is close to the player and the player has
2326  * telepathy, or (3) it is close to the player, and in line of sight
2327  * of the player, and it is "illuminated" by some combination of
2328  * infravision, torch light, or permanent light (invisible monsters
2329  * are only affected by "light" if the player can see invisible).
2330  *
2331  * Monsters which are not on the current panel may be "visible" to
2332  * the player, and their descriptions will include an "offscreen"
2333  * reference.  Currently, offscreen monsters cannot be targetted
2334  * or viewed directly, but old targets will remain set.  XXX XXX
2335  *
2336  * The player can choose to be disturbed by several things, including
2337  * "disturb_move" (monster which is viewable moves in some way), and
2338  * "disturb_near" (monster which is "easily" viewable moves in some
2339  * way).  Note that "moves" includes "appears" and "disappears".
2340  */
2341 void update_mon(int m_idx, bool full)
2342 {
2343         monster_type *m_ptr = &m_list[m_idx];
2344
2345         monster_race *r_ptr = &r_info[m_ptr->r_idx];
2346
2347         bool do_disturb = disturb_move;
2348
2349         int d;
2350
2351         /* Current location */
2352         int fy = m_ptr->fy;
2353         int fx = m_ptr->fx;
2354
2355         /* Seen at all */
2356         bool flag = FALSE;
2357
2358         /* Seen by vision */
2359         bool easy = FALSE;
2360
2361         /* Do disturb? */
2362         if (disturb_high)
2363         {
2364                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2365
2366                 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
2367                         do_disturb = TRUE;
2368         }
2369
2370         /* Compute distance */
2371         if (full)
2372         {
2373                 /* Distance components */
2374                 int dy = (py > fy) ? (py - fy) : (fy - py);
2375                 int dx = (px > fx) ? (px - fx) : (fx - px);
2376
2377                 /* Approximate distance */
2378                 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2379
2380                 /* Restrict distance */
2381                 if (d > 255) d = 255;
2382
2383                 if (!d) d = 1;
2384
2385                 /* Save the distance */
2386                 m_ptr->cdis = d;
2387         }
2388
2389         /* Extract distance */
2390         else
2391         {
2392                 /* Extract the distance */
2393                 d = m_ptr->cdis;
2394         }
2395
2396
2397         /* Detected */
2398         if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
2399
2400
2401         /* Nearby */
2402         if (d <= ((d_info[dungeon_type].flags1 & DF1_DARKNESS) ? MAX_SIGHT / 2 : MAX_SIGHT))
2403         {
2404                 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS) || (d <= MAX_SIGHT / 4))
2405                 {
2406                         if (p_ptr->special_defense & KATA_MUSOU)
2407                         {
2408                                 /* Detectable */
2409                                 flag = TRUE;
2410
2411                                 /* Hack -- Memorize mental flags */
2412                                 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2413                                 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2414                         }
2415
2416                         /* Basic telepathy */
2417                         else if (p_ptr->telepathy)
2418                         {
2419                                 /* Empty mind, no telepathy */
2420                                 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
2421                                 {
2422                                         /* Memorize flags */
2423                                         r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
2424                                 }
2425
2426                                 /* Weird mind, occasional telepathy */
2427                                 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
2428                                 {
2429                                         /* One in ten individuals are detectable */
2430                                         if ((m_idx % 10) == 5)
2431                                         {
2432                                                 /* Detectable */
2433                                                 flag = TRUE;
2434
2435                                                 /* Memorize flags */
2436                                                 r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
2437
2438                                                 /* Hack -- Memorize mental flags */
2439                                                 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2440                                                 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2441                                         }
2442                                 }
2443
2444                                 /* Normal mind, allow telepathy */
2445                                 else
2446                                 {
2447                                         /* Detectable */
2448                                         flag = TRUE;
2449
2450                                         /* Hack -- Memorize mental flags */
2451                                         if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2452                                         if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2453                                 }
2454                         }
2455
2456                         /* Magical sensing */
2457                         if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
2458                         {
2459                                 flag = TRUE;
2460                                 r_ptr->r_flags3 |= (RF3_ANIMAL);
2461
2462                         }
2463
2464                         /* Magical sensing */
2465                         if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
2466                         {
2467                                 flag = TRUE;
2468                                 r_ptr->r_flags3 |= (RF3_UNDEAD);
2469
2470                         }
2471
2472                         /* Magical sensing */
2473                         if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
2474                         {
2475                                 flag = TRUE;
2476                                 r_ptr->r_flags3 |= (RF3_DEMON);
2477
2478                         }
2479
2480                         /* Magical sensing */
2481                         if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
2482                         {
2483                                 flag = TRUE;
2484                                 r_ptr->r_flags3 |= (RF3_ORC);
2485
2486                         }
2487
2488                         /* Magical sensing */
2489                         if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
2490                         {
2491                                 flag = TRUE;
2492                                 r_ptr->r_flags3 |= (RF3_TROLL);
2493
2494                         }
2495
2496                         /* Magical sensing */
2497                         if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
2498                         {
2499                                 flag = TRUE;
2500                                 r_ptr->r_flags3 |= (RF3_GIANT);
2501
2502                         }
2503
2504                         /* Magical sensing */
2505                         if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
2506                         {
2507                                 flag = TRUE;
2508                                 r_ptr->r_flags3 |= (RF3_DRAGON);
2509
2510                         }
2511
2512                         /* Magical sensing */
2513                         if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
2514                         {
2515                                 flag = TRUE;
2516                                 r_ptr->r_flags2 |= (RF2_HUMAN);
2517
2518                         }
2519
2520                         /* Magical sensing */
2521                         if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
2522                         {
2523                                 flag = TRUE;
2524                                 r_ptr->r_flags3 |= (RF3_EVIL);
2525
2526                         }
2527
2528                         /* Magical sensing */
2529                         if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
2530                         {
2531                                 flag = TRUE;
2532                                 r_ptr->r_flags3 |= (RF3_GOOD);
2533
2534                         }
2535
2536                         /* Magical sensing */
2537                         if ((p_ptr->esp_nonliving) && 
2538                             (r_ptr->flags3 & (RF3_NONLIVING)) &&
2539                             !(r_ptr->flags3 & (RF3_DEMON)) &&
2540                             !(r_ptr->flags3 & (RF3_UNDEAD)))
2541                         {
2542                                 flag = TRUE;
2543                                 r_ptr->r_flags3 |= (RF3_NONLIVING);
2544
2545                         }
2546
2547                         /* Magical sensing */
2548                         if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
2549                         {
2550                                 flag = TRUE;
2551                                 r_ptr->r_flags1 |= (RF1_UNIQUE);
2552
2553                         }
2554                 }
2555
2556                 /* Normal line of sight, and not blind */
2557                 if (player_has_los_bold(fy, fx) && !p_ptr->blind)
2558                 {
2559                         bool do_invisible = FALSE;
2560                         bool do_cold_blood = FALSE;
2561
2562                         /* Use "infravision" */
2563                         if (d <= p_ptr->see_infra)
2564                         {
2565                                 /* Handle "cold blooded" monsters */
2566                                 if (r_ptr->flags2 & (RF2_COLD_BLOOD))
2567                                 {
2568                                         /* Take note */
2569                                         do_cold_blood = TRUE;
2570                                 }
2571
2572                                 /* Handle "warm blooded" monsters */
2573                                 else
2574                                 {
2575                                         /* Easy to see */
2576                                         easy = flag = TRUE;
2577                                 }
2578                         }
2579
2580                         /* Use "illumination" */
2581                         if (player_can_see_bold(fy, fx))
2582                         {
2583                                 /* Handle "invisible" monsters */
2584                                 if (r_ptr->flags2 & (RF2_INVISIBLE))
2585                                 {
2586                                         /* Take note */
2587                                         do_invisible = TRUE;
2588
2589                                         /* See invisible */
2590                                         if (p_ptr->see_inv)
2591                                         {
2592                                                 /* Easy to see */
2593                                                 easy = flag = TRUE;
2594                                         }
2595                                 }
2596
2597                                 /* Handle "normal" monsters */
2598                                 else
2599                                 {
2600                                         /* Easy to see */
2601                                         easy = flag = TRUE;
2602                                 }
2603                         }
2604
2605                         /* Visible */
2606                         if (flag)
2607                         {
2608                                 /* Memorize flags */
2609                                 if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2610                                 if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2611                         }
2612                 }
2613         }
2614
2615
2616         /* The monster is now visible */
2617         if (flag)
2618         {
2619                 /* It was previously unseen */
2620                 if (!m_ptr->ml)
2621                 {
2622                         /* Mark as visible */
2623                         m_ptr->ml = TRUE;
2624
2625                         /* Draw the monster */
2626                         lite_spot(fy, fx);
2627
2628                         /* Update health bar as needed */
2629                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2630                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2631
2632                         /* Hack -- Count "fresh" sightings */
2633                         if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2634                                 r_info[MON_KAGE].r_sights++;
2635                         else if (m_ptr->ap_r_idx == m_ptr->r_idx && 
2636                                  r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
2637
2638                         /* Eldritch Horror */
2639                         if (r_ptr->flags2 & RF2_ELDRITCH_HORROR)
2640                         {
2641                                 sanity_blast(m_ptr, FALSE);
2642                         }
2643
2644                         /* Disturb on appearance */
2645                         if (disturb_near && (projectable(m_ptr->fy, m_ptr->fx, py, px) && projectable(py, px, m_ptr->fy, m_ptr->fx)))
2646                         {
2647                                 if (disturb_pets || is_hostile(m_ptr))
2648                                         disturb(1, 0);
2649                         }
2650                 }
2651         }
2652
2653         /* The monster is not visible */
2654         else
2655         {
2656                 /* It was previously seen */
2657                 if (m_ptr->ml)
2658                 {
2659                         /* Mark as not visible */
2660                         m_ptr->ml = FALSE;
2661
2662                         /* Erase the monster */
2663                         lite_spot(fy, fx);
2664
2665                         /* Update health bar as needed */
2666                         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2667                         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2668
2669                         /* Disturb on disappearance */
2670                         if (do_disturb)
2671                         {
2672                                 if (disturb_pets || is_hostile(m_ptr))
2673                                         disturb(1, 0);
2674                         }
2675                 }
2676         }
2677
2678
2679         /* The monster is now easily visible */
2680         if (easy)
2681         {
2682                 /* Change */
2683                 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2684                 {
2685                         /* Mark as easily visible */
2686                         m_ptr->mflag |= (MFLAG_VIEW);
2687
2688                         /* Disturb on appearance */
2689                         if (do_disturb)
2690                         {
2691                                 if (disturb_pets || is_hostile(m_ptr))
2692                                         disturb(1, 0);
2693                         }
2694                 }
2695         }
2696
2697         /* The monster is not easily visible */
2698         else
2699         {
2700                 /* Change */
2701                 if (m_ptr->mflag & (MFLAG_VIEW))
2702                 {
2703                         /* Mark as not easily visible */
2704                         m_ptr->mflag &= ~(MFLAG_VIEW);
2705
2706                         /* Disturb on disappearance */
2707                         if (do_disturb)
2708                         {
2709                                 if (disturb_pets || is_hostile(m_ptr))
2710                                         disturb(1, 0);
2711                         }
2712                 }
2713         }
2714 }
2715
2716
2717 /*
2718  * This function simply updates all the (non-dead) monsters (see above).
2719  */
2720 void update_monsters(bool full)
2721 {
2722         int i;
2723
2724         /* Update each (live) monster */
2725         for (i = 1; i < m_max; i++)
2726         {
2727                 monster_type *m_ptr = &m_list[i];
2728
2729                 /* Skip dead monsters */
2730                 if (!m_ptr->r_idx) continue;
2731
2732                 /* Update the monster */
2733                 update_mon(i, full);
2734         }
2735 }
2736
2737
2738 /*
2739  * Hack -- the index of the summoning monster
2740  */
2741 static bool monster_hook_chameleon_lord(int r_idx)
2742 {
2743         monster_race *r_ptr = &r_info[r_idx];
2744         monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2745         monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2746
2747         if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2748         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2749
2750         if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2751
2752         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))
2753                 return FALSE;
2754
2755         if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr)) return FALSE;
2756
2757         /* Not born */
2758         if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2759         {
2760                 if ((m_ptr->sub_align & SUB_ALIGN_EVIL) && (r_ptr->flags3 & RF3_GOOD)) return FALSE;
2761                 if ((m_ptr->sub_align & SUB_ALIGN_GOOD) && (r_ptr->flags3 & RF3_EVIL)) return FALSE;
2762         }
2763
2764         /* Born now */
2765         else if (summon_specific_who > 0)
2766         {
2767                 monster_type *sm_ptr = &m_list[summon_specific_who];
2768
2769                 if ((sm_ptr->sub_align & SUB_ALIGN_EVIL) && (r_ptr->flags3 & RF3_GOOD)) return FALSE;
2770                 if ((sm_ptr->sub_align & SUB_ALIGN_GOOD) && (r_ptr->flags3 & RF3_EVIL)) return FALSE;
2771         }
2772
2773         return TRUE;
2774 }
2775
2776 static bool monster_hook_chameleon(int r_idx)
2777 {
2778         monster_race *r_ptr = &r_info[r_idx];
2779         monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2780         monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2781
2782         if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2783         if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2784         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2785         
2786         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))
2787                 return FALSE;
2788
2789         if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr)) return FALSE;
2790
2791         /* Not born */
2792         if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2793         {
2794                 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2795                 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2796                 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2797         }
2798
2799         /* Born now */
2800         else if (summon_specific_who > 0)
2801         {
2802                 monster_type *sm_ptr = &m_list[summon_specific_who];
2803
2804                 if ((sm_ptr->sub_align & SUB_ALIGN_EVIL) && (r_ptr->flags3 & RF3_GOOD)) return FALSE;
2805                 if ((sm_ptr->sub_align & SUB_ALIGN_GOOD) && (r_ptr->flags3 & RF3_EVIL)) return FALSE;
2806         }
2807
2808         return (*(get_monster_hook()))(r_idx);
2809 }
2810
2811
2812 void choose_new_monster(int m_idx, bool born, int r_idx)
2813 {
2814         int oldmaxhp;
2815         monster_type *m_ptr = &m_list[m_idx];
2816         monster_race *r_ptr;
2817         char old_m_name[80];
2818         bool old_unique = FALSE;
2819
2820         if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2821                 old_unique = TRUE;
2822         if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2823         r_ptr = &r_info[r_idx];
2824
2825         monster_desc(old_m_name, m_ptr, 0);
2826
2827         if (!r_idx)
2828         {
2829                 int level;
2830
2831                 chameleon_change_m_idx = m_idx;
2832                 if (old_unique)
2833                         get_mon_num_prep(monster_hook_chameleon_lord, NULL);
2834                 else
2835                         get_mon_num_prep(monster_hook_chameleon, NULL);
2836
2837                 if (old_unique)
2838                         level = r_info[MON_CHAMELEON_K].level;
2839                 else if (!dun_level)
2840                         level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
2841                 else
2842                         level = dun_level;
2843
2844                 if (d_info[dungeon_type].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
2845
2846                 r_idx = get_mon_num(level);
2847                 r_ptr = &r_info[r_idx];
2848
2849                 chameleon_change_m_idx = 0;
2850
2851                 /* Paranoia */
2852                 if (!r_idx) return;
2853         }
2854
2855         m_ptr->r_idx = r_idx;
2856         m_ptr->ap_r_idx = r_idx;
2857         update_mon(m_idx, FALSE);
2858         lite_spot(m_ptr->fy, m_ptr->fx);
2859         if (born)
2860         {
2861                 /* Sub-alignment of a chameleon */
2862                 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2863                 {
2864                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2865                         if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2866                         if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2867                 }
2868                 return;
2869         }
2870
2871         if (m_idx == p_ptr->riding)
2872         {
2873                 char m_name[80];
2874                 monster_desc(m_name, m_ptr, 0);
2875 #ifdef JP
2876                 msg_format("ÆÍÁ³%s¤¬ÊѿȤ·¤¿¡£", old_m_name);
2877 #else
2878                 msg_format("Suddenly, %s transforms!", old_m_name);
2879 #endif
2880                 if (!(r_ptr->flags7 & RF7_RIDING))
2881 #ifdef JP
2882                         if (rakuba(0, TRUE)) msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2883 #else
2884                         if (rakuba(0, TRUE)) msg_format("You have fallen from %s.", m_name);
2885 #endif
2886         }
2887
2888         /* Extract the monster base speed */
2889         m_ptr->mspeed = get_mspeed(r_ptr);
2890
2891         oldmaxhp = m_ptr->max_maxhp;
2892         /* Assign maximal hitpoints */
2893         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2894         {
2895                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2896         }
2897         else
2898         {
2899                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2900         }
2901         m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2902         m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2903 }
2904
2905
2906 /*
2907  *  Hook for Tanuki
2908  */
2909 static bool monster_hook_tanuki(int r_idx)
2910 {
2911         monster_race *r_ptr = &r_info[r_idx];
2912
2913         if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2914         if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2915         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2916         if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2917         
2918         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))
2919                 return FALSE;
2920
2921         return (*(get_monster_hook()))(r_idx);
2922 }
2923
2924
2925 /*
2926  *  Set initial racial appearance of a monster
2927  */
2928 static int initial_r_appearance(int r_idx)
2929 {
2930         int attempts = 1000;
2931
2932         int ap_r_idx;
2933         int min = MIN(base_level-5, 50);
2934
2935         if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2936                 return r_idx;
2937
2938         get_mon_num_prep(monster_hook_tanuki, NULL);
2939
2940         while (--attempts)
2941         {
2942                 ap_r_idx = get_mon_num(base_level + 10);
2943                 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2944         }
2945
2946         return r_idx;
2947 }
2948
2949
2950 /*
2951  * Get initial monster speed
2952  */
2953 byte get_mspeed(monster_race *r_ptr)
2954 {
2955         /* Extract the monster base speed */
2956         int mspeed = r_ptr->speed;
2957
2958         /* Hack -- small racial variety */
2959         if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
2960         {
2961                 /* Allow some small variation per monster */
2962                 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2963                 if (i) mspeed += rand_spread(0, i);
2964         }
2965
2966         if (mspeed > 199) mspeed = 199;
2967
2968         return (byte)mspeed;
2969 }
2970
2971
2972 /*
2973  * Attempt to place a monster of the given race at the given location.
2974  *
2975  * To give the player a sporting chance, any monster that appears in
2976  * line-of-sight and is extremely dangerous can be marked as
2977  * "FORCE_SLEEP", which will cause them to be placed with low energy,
2978  * which often (but not always) lets the player move before they do.
2979  *
2980  * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2981  *
2982  * XXX XXX XXX Use special "here" and "dead" flags for unique monsters,
2983  * remove old "cur_num" and "max_num" fields.
2984  *
2985  * XXX XXX XXX Actually, do something similar for artifacts, to simplify
2986  * the "preserve" mode, and to make the "what artifacts" flag more useful.
2987  *
2988  * This is the only function which may place a monster in the dungeon,
2989  * except for the savefile loading code.
2990  */
2991 bool place_monster_one(int who, int y, int x, int r_idx, u32b mode)
2992 {
2993         cave_type               *c_ptr;
2994
2995         monster_type    *m_ptr;
2996
2997         monster_race    *r_ptr = &r_info[r_idx];
2998
2999         cptr            name = (r_name + r_ptr->name);
3000
3001         /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
3002         if(p_ptr->wild_mode) return FALSE;
3003
3004         /* Verify location */
3005         if (!in_bounds(y, x)) return (FALSE);
3006
3007         /* Require empty space (if not ghostly) */
3008         if (!(!dun_level && (cave[y][x].feat == FEAT_MOUNTAIN) && ((r_ptr->flags8 & RF8_WILD_MOUNTAIN) || (r_ptr->flags7 & RF7_CAN_FLY))) &&
3009             !(cave_empty_bold2(y, x) || (mode & PM_IGNORE_TERRAIN)) &&
3010             !((r_ptr->flags2 & RF2_PASS_WALL) &&
3011               !(cave_perma_bold(y, x) || cave[y][x].m_idx ||
3012                 ((y == py) && (x == px))))) return (FALSE);
3013
3014         /* Paranoia */
3015         if (!r_idx) return (FALSE);
3016
3017         /* Paranoia */
3018         if (!r_ptr->name) return (FALSE);
3019
3020         /* Nor on the Pattern */
3021         if ((cave[y][x].feat >= FEAT_PATTERN_START)
3022          && (cave[y][x].feat <= FEAT_PATTERN_XTRA2))
3023                 return (FALSE);
3024
3025         if (!(mode & PM_IGNORE_TERRAIN) &&
3026             !monster_can_cross_terrain(cave[y][x].feat, r_ptr))
3027         {
3028                 return FALSE;
3029         }
3030
3031         if (!p_ptr->inside_battle)
3032         {
3033                 /* Hack -- "unique" monsters must be "unique" */
3034                 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
3035                      (r_ptr->flags7 & (RF7_UNIQUE_7))) &&
3036                     (r_ptr->cur_num >= r_ptr->max_num))
3037                 {
3038                         /* Cannot create */
3039                         return (FALSE);
3040                 }
3041                 
3042                 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
3043                     (r_ptr->cur_num >= 1))
3044                 {
3045                         return (FALSE);
3046                 }
3047
3048                 if (r_idx == MON_BANORLUPART)
3049                 {
3050                         if (r_info[MON_BANOR].cur_num > 0) return FALSE;
3051                         if (r_info[MON_LUPART].cur_num > 0) return FALSE;
3052                 }
3053                 
3054                 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
3055                 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (dun_level < r_ptr->level) &&
3056                     (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
3057                 {
3058                         /* Cannot create */
3059                         return (FALSE);
3060                 }
3061         }
3062
3063         if(quest_number(dun_level))
3064         {
3065                 int hoge = quest_number(dun_level);
3066                 if((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
3067                 {
3068                         if(r_idx == quest[hoge].r_idx)
3069                         {
3070                                 int number_mon, i2, j2;
3071                                 number_mon = 0;
3072
3073                                 /* Count all quest monsters */
3074                                 for (i2 = 0; i2 < cur_wid; ++i2)
3075                                         for (j2 = 0; j2 < cur_hgt; j2++)
3076                                                 if (cave[j2][i2].m_idx > 0)
3077                                                         if (m_list[cave[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
3078                                                                 number_mon++;
3079                                 if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
3080                                         return FALSE;
3081                         }
3082                 }
3083         }
3084
3085         /* Access the location */
3086         c_ptr = &cave[y][x];
3087
3088         if (is_glyph_grid(c_ptr))
3089         {
3090                 if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
3091                 {
3092                         /* Describe observable breakage */
3093                         if (c_ptr->info & CAVE_MARK)
3094                         {
3095 #ifdef JP
3096 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3097 #else
3098                                 msg_print("The rune of protection is broken!");
3099 #endif
3100
3101                         }
3102
3103                         /* Forget the rune */
3104                         c_ptr->info &= ~(CAVE_MARK);
3105
3106                         /* Break the rune */
3107                         c_ptr->info &= ~(CAVE_OBJECT);
3108                         c_ptr->mimic = 0;
3109
3110                         /* Notice */
3111                         note_spot(y, x);
3112                 }
3113                 else return FALSE;
3114         }
3115
3116         /* Powerful monster */
3117         if (r_ptr->level > dun_level)
3118         {
3119                 /* Unique monsters */
3120                 if (r_ptr->flags1 & (RF1_UNIQUE))
3121                 {
3122                         /* Message for cheaters */
3123 #ifdef JP
3124                         if (cheat_hear) msg_format("¿¼ÁؤΥæ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3125 #else
3126                         if (cheat_hear) msg_format("Deep Unique (%s).", name);
3127 #endif
3128
3129
3130                         /* Boost rating by twice delta-depth */
3131                         rating += (r_ptr->level - dun_level) * 2;
3132                 }
3133
3134                 /* Normal monsters */
3135                 else
3136                 {
3137                         /* Message for cheaters */
3138 #ifdef JP
3139                         if (cheat_hear) msg_format("¿¼ÁؤΥâ¥ó¥¹¥¿¡¼ (%s)¡£", name);
3140 #else
3141                         if (cheat_hear) msg_format("Deep Monster (%s).", name);
3142 #endif
3143
3144
3145                         /* Boost rating by delta-depth */
3146                         rating += (r_ptr->level - dun_level);
3147                 }
3148         }
3149
3150         /* Note the monster */
3151         else if (r_ptr->flags1 & (RF1_UNIQUE))
3152         {
3153                 /* Unique monsters induce message */
3154 #ifdef JP
3155                 if (cheat_hear) msg_format("¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3156 #else
3157                 if (cheat_hear) msg_format("Unique (%s).", name);
3158 #endif
3159
3160         }
3161
3162         if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7) || (r_ptr->level < 10)) is_kage = FALSE;
3163
3164         /* Make a new monster */
3165         c_ptr->m_idx = m_pop();
3166         hack_m_idx_ii = c_ptr->m_idx;
3167
3168         /* Mega-Hack -- catch "failure" */
3169         if (!c_ptr->m_idx) return (FALSE);
3170
3171
3172         /* Get a new monster record */
3173         m_ptr = &m_list[c_ptr->m_idx];
3174
3175         /* Save the race */
3176         m_ptr->r_idx = r_idx;
3177         m_ptr->ap_r_idx = initial_r_appearance(r_idx);
3178
3179         /* Sub-alignment of a monster */
3180         if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
3181                 m_ptr->sub_align = m_list[who].sub_align;
3182         else
3183         {
3184                 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3185                 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
3186                 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
3187         }
3188
3189         /* Place the monster at the location */
3190         m_ptr->fy = y;
3191         m_ptr->fx = x;
3192
3193
3194         /* No "damage" yet */
3195         m_ptr->stunned = 0;
3196         m_ptr->confused = 0;
3197         m_ptr->monfear = 0;
3198
3199         /* Unknown distance */
3200         m_ptr->cdis = 0;
3201
3202         reset_target(m_ptr);
3203
3204         m_ptr->nickname = 0;
3205
3206         m_ptr->exp = 0;
3207
3208         /* No flags */
3209         m_ptr->mflag = 0;
3210         m_ptr->mflag2 = 0;
3211
3212         if (r_ptr->flags7 & RF7_CHAMELEON)
3213         {
3214                 choose_new_monster(c_ptr->m_idx, TRUE, 0);
3215                 r_ptr = &r_info[m_ptr->r_idx];
3216                 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
3217                 rating++;
3218
3219                 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
3220                 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
3221                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3222         }
3223         else if (is_kage)
3224         {
3225                 m_ptr->ap_r_idx = MON_KAGE;
3226                 m_ptr->mflag2 |= MFLAG2_KAGE;
3227         }
3228
3229         if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
3230
3231         /* Not visible */
3232         m_ptr->ml = FALSE;
3233
3234         /* Pet? */
3235         if (mode & PM_FORCE_PET)
3236         {
3237                 set_pet(m_ptr);
3238         }
3239         /* Friendly? */
3240         else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
3241                  (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
3242         {
3243                 if (!(p_ptr->align >= 0 && (r_ptr->flags3 & RF3_EVIL)) &&
3244                     !(p_ptr->align < 0 && (r_ptr->flags3 & RF3_GOOD)))
3245                 {
3246                         set_friendly(m_ptr);
3247                 }
3248         }
3249
3250         /* Assume no sleeping */
3251         m_ptr->csleep = 0;
3252
3253         /* Enforce sleeping if needed */
3254         if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
3255         {
3256                 int val = r_ptr->sleep;
3257                 m_ptr->csleep = ((val * 2) + randint1(val * 10));
3258         }
3259
3260         /* Assign maximal hitpoints */
3261         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
3262         {
3263                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
3264         }
3265         else
3266         {
3267                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
3268         }
3269
3270         /* Monsters have double hitpoints in Nightmare mode */
3271         if (ironman_nightmare)
3272         {
3273                 u32b hp = m_ptr->max_maxhp * 2L;
3274
3275                 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
3276         }
3277
3278         m_ptr->maxhp = m_ptr->max_maxhp;
3279
3280         /* And start out fully healthy */
3281         if (m_ptr->r_idx == MON_WOUNDED_BEAR)
3282                 m_ptr->hp = m_ptr->maxhp / 2;
3283         else m_ptr->hp = m_ptr->maxhp;
3284
3285
3286         /* Extract the monster base speed */
3287         m_ptr->mspeed = get_mspeed(r_ptr);
3288
3289         if (mode & PM_HASTE) m_ptr->fast = 100;
3290
3291         /* Give a random starting energy */
3292         if (!ironman_nightmare)
3293         {
3294                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
3295         }
3296         else
3297         {
3298                 /* Nightmare monsters are more prepared */
3299                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
3300         }
3301
3302         /* Force monster to wait for player, unless in Nightmare mode */
3303         if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
3304         {
3305                 /* Monster is still being nice */
3306                 m_ptr->mflag |= (MFLAG_NICE);
3307
3308                 /* Must repair monsters */
3309                 repair_monsters = TRUE;
3310         }
3311
3312         /* Hack -- see "process_monsters()" */
3313         if (c_ptr->m_idx < hack_m_idx)
3314         {
3315                 /* Monster is still being born */
3316                 m_ptr->mflag |= (MFLAG_BORN);
3317         }
3318
3319
3320         /* Update the monster */
3321         update_mon(c_ptr->m_idx, TRUE);
3322
3323
3324         /* Count the monsters on the level */
3325         real_r_ptr(m_ptr)->cur_num++;
3326
3327         /*
3328          * Memorize location of the unique monster in saved floors.
3329          * A unique monster move from old saved floor.
3330          */
3331         if (character_dungeon &&
3332             ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)))
3333                 real_r_ptr(m_ptr)->floor_id = p_ptr->floor_id;
3334
3335         /* Hack -- Count the number of "reproducers" */
3336         if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
3337
3338
3339         /* Hack -- Notice new multi-hued monsters */
3340         {
3341                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3342                 if ((ap_r_ptr->flags1 & RF1_ATTR_MULTI) || (ap_r_ptr->flags2 & RF2_SHAPECHANGER))
3343                         shimmer_monsters = TRUE;
3344         }
3345
3346         if (p_ptr->warning && character_dungeon)
3347         {
3348                 if (r_ptr->flags1 & RF1_UNIQUE)
3349                 {
3350                         cptr color;
3351                         object_type *o_ptr;
3352                         char o_name[MAX_NLEN];
3353
3354                         if (r_ptr->level > p_ptr->lev + 30)
3355 #ifdef JP
3356                                 color = "¹õ¤¯";
3357 #else
3358                                 color = "black";
3359 #endif
3360                         else if (r_ptr->level > p_ptr->lev + 15)
3361 #ifdef JP
3362                                 color = "»ç¿§¤Ë";
3363 #else
3364                                 color = "purple";
3365 #endif
3366                         else if (r_ptr->level > p_ptr->lev + 5)
3367 #ifdef JP
3368                                 color = "¥ë¥Ó¡¼¿§¤Ë";
3369 #else
3370                                 color = "deep red";
3371 #endif
3372                         else if (r_ptr->level > p_ptr->lev - 5)
3373 #ifdef JP
3374                                 color = "ÀÖ¤¯";
3375 #else
3376                                 color = "red";
3377 #endif
3378                         else if (r_ptr->level > p_ptr->lev - 15)
3379 #ifdef JP
3380                                 color = "¥Ô¥ó¥¯¿§¤Ë";
3381 #else
3382                                 color = "pink";
3383 #endif
3384                         else
3385 #ifdef JP
3386                                 color = "Çò¤¯";
3387 #else
3388                                 color = "white";
3389 #endif
3390
3391                         o_ptr = choose_warning_item();
3392                         object_desc(o_name, o_ptr, FALSE, 0);
3393 #ifdef JP
3394                         msg_format("%s¤Ï%s¸÷¤Ã¤¿¡£",o_name, color);
3395 #else
3396                         msg_format("%s glows %s.",o_name, color);
3397 #endif
3398                 }
3399         }
3400
3401         if (is_explosive_rune_grid(c_ptr))
3402         {
3403                 /* Break the ward */
3404                 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3405                 {
3406                         /* Describe observable breakage */
3407                         if (c_ptr->info & CAVE_MARK)
3408                         {
3409 #ifdef JP
3410 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3411 #else
3412                                 msg_print("The rune explodes!");
3413 #endif
3414
3415                                 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);
3416                         }
3417                 }
3418                 else
3419                 {
3420 #ifdef JP
3421 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3422 #else
3423                         msg_print("An explosive rune was disarmed.");
3424 #endif
3425                 }
3426
3427                 /* Forget the rune */
3428                 c_ptr->info &= ~(CAVE_MARK);
3429
3430                 /* Break the rune */
3431                 c_ptr->info &= ~(CAVE_OBJECT);
3432                 c_ptr->mimic = 0;
3433
3434                 note_spot(y, x);
3435                 lite_spot(y, x);
3436         }
3437
3438         /* Success */
3439         return (TRUE);
3440 }
3441
3442
3443 /*
3444  *  improved version of scatter() for place monster
3445  */
3446
3447 #define MON_SCAT_MAXD 10
3448
3449 static bool mon_scatter(int *yp, int *xp, int y, int x, int max_dist)
3450 {
3451         int place_x[MON_SCAT_MAXD];
3452         int place_y[MON_SCAT_MAXD];
3453         int num[MON_SCAT_MAXD];
3454         int i;
3455         int nx, ny;
3456
3457         if (max_dist >= MON_SCAT_MAXD)
3458                 return FALSE;
3459
3460         for (i = 0; i < MON_SCAT_MAXD; i++)
3461                 num[i] = 0;
3462
3463         for (nx = x - max_dist; nx <= x + max_dist; nx++)
3464                 for (ny = y - max_dist; ny <= y + max_dist; ny++)
3465                 {
3466                         /* Ignore annoying locations */
3467                         if (!in_bounds(ny, nx)) continue;
3468                         
3469                         /* Require "line of sight" */
3470                         if (!los(y, x, ny, nx)) continue;
3471                         
3472                         /* Walls and Monsters block flow */
3473                         if (!cave_empty_bold2(ny, nx)) continue;
3474                         if (cave[ny][nx].m_idx) continue;
3475                         if ((ny == py) && (nx == px)) continue;
3476                                                 
3477                         /* ... nor on the Pattern */
3478                         if ((cave[ny][nx].feat >= FEAT_PATTERN_START) &&
3479                             (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2))
3480                                 continue;
3481                         
3482                         i = distance(y, x, ny, nx);
3483
3484                         if (i > max_dist)
3485                                 continue;
3486                         
3487                         num[i]++;
3488
3489                         /* random swap */
3490                         if(one_in_(num[i]))
3491                         {
3492                                 place_x[i] = nx;
3493                                 place_y[i] = ny;
3494                         }
3495                         
3496                 }
3497
3498         i = 0;
3499         while (i < MON_SCAT_MAXD && 0 == num[i])
3500                 i++;
3501         if (i >= MON_SCAT_MAXD)
3502                 return FALSE;
3503
3504         *xp = place_x[i];
3505         *yp = place_y[i];
3506
3507         return TRUE;
3508 }
3509
3510
3511 /*
3512  * Maximum size of a group of monsters
3513  */
3514 #define GROUP_MAX       32
3515
3516
3517 /*
3518  * Attempt to place a "group" of monsters around the given location
3519  */
3520 static bool place_monster_group(int who, int y, int x, int r_idx, u32b mode)
3521 {
3522         monster_race *r_ptr = &r_info[r_idx];
3523
3524         int old, n, i;
3525         int total = 0, extra = 0;
3526
3527         int hack_n = 0;
3528
3529         byte hack_y[GROUP_MAX];
3530         byte hack_x[GROUP_MAX];
3531
3532
3533         /* Pick a group size */
3534         total = randint1(10);
3535
3536         /* Hard monsters, small groups */
3537         if (r_ptr->level > dun_level)
3538         {
3539                 extra = r_ptr->level - dun_level;
3540                 extra = 0 - randint1(extra);
3541         }
3542
3543         /* Easy monsters, large groups */
3544         else if (r_ptr->level < dun_level)
3545         {
3546                 extra = dun_level - r_ptr->level;
3547                 extra = randint1(extra);
3548         }
3549
3550         /* Hack -- limit group reduction */
3551         if (extra > 9) extra = 9;
3552
3553         /* Modify the group size */
3554         total += extra;
3555
3556         /* Minimum size */
3557         if (total < 1) total = 1;
3558
3559         /* Maximum size */
3560         if (total > GROUP_MAX) total = GROUP_MAX;
3561
3562
3563         /* Save the rating */
3564         old = rating;
3565
3566         /* Start on the monster */
3567         hack_n = 1;
3568         hack_x[0] = x;
3569         hack_y[0] = y;
3570
3571         /* Puddle monsters, breadth first, up to total */
3572         for (n = 0; (n < hack_n) && (hack_n < total); n++)
3573         {
3574                 /* Grab the location */
3575                 int hx = hack_x[n];
3576                 int hy = hack_y[n];
3577
3578                 /* Check each direction, up to total */
3579                 for (i = 0; (i < 8) && (hack_n < total); i++)
3580                 {
3581                         int mx, my;
3582
3583                         scatter(&my, &mx, hy, hx, 4, 0);
3584
3585                         /* Walls and Monsters block flow */
3586                         if (!cave_empty_bold2(my, mx)) continue;
3587
3588                         /* Attempt to place another monster */
3589                         if (place_monster_one(who, my, mx, r_idx, mode))
3590                         {
3591                                 /* Add it to the "hack" set */
3592                                 hack_y[hack_n] = my;
3593                                 hack_x[hack_n] = mx;
3594                                 hack_n++;
3595                         }
3596                 }
3597         }
3598
3599         /* Hack -- restore the rating */
3600         rating = old;
3601
3602
3603         /* Success */
3604         return (TRUE);
3605 }
3606
3607
3608 /*
3609  * Hack -- help pick an escort type
3610  */
3611 static int place_monster_idx = 0;
3612 static int place_monster_m_idx = 0;
3613
3614 /*
3615  * Hack -- help pick an escort type
3616  */
3617 static bool place_monster_okay(int r_idx)
3618 {
3619         monster_race *r_ptr = &r_info[place_monster_idx];
3620         monster_type *m_ptr = &m_list[place_monster_m_idx];
3621
3622         monster_race *z_ptr = &r_info[r_idx];
3623
3624         /* Hack - Escorts have to have the same dungeon flag */
3625         if (monster_dungeon(place_monster_idx) != monster_dungeon(r_idx)) return (FALSE);
3626
3627         /* Require similar "race" */
3628         if (z_ptr->d_char != r_ptr->d_char) return (FALSE);
3629
3630         /* Skip more advanced monsters */
3631         if (z_ptr->level > r_ptr->level) return (FALSE);
3632
3633         /* Skip unique monsters */
3634         if (z_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3635
3636         /* Paranoia -- Skip identical monsters */
3637         if (place_monster_idx == r_idx) return (FALSE);
3638
3639         /* Skip different alignment */
3640         if (((m_ptr->sub_align & SUB_ALIGN_EVIL) && (z_ptr->flags3 & RF3_GOOD)) ||
3641             ((m_ptr->sub_align & SUB_ALIGN_GOOD) && (z_ptr->flags3 & RF3_EVIL)))
3642                 return FALSE;
3643
3644         if (r_ptr->flags7 & RF7_FRIENDLY)
3645         {
3646                 if (((p_ptr->align < 0) && (z_ptr->flags3 & RF3_GOOD)) ||
3647                     ((p_ptr->align > 0) && (z_ptr->flags3 & RF3_EVIL)))
3648                         return FALSE;
3649         }
3650
3651         if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3652                 return FALSE;
3653
3654         /* Okay */
3655         return (TRUE);
3656 }
3657
3658
3659 /*
3660  * Attempt to place a monster of the given race at the given location
3661  *
3662  * Note that certain monsters are now marked as requiring "friends".
3663  * These monsters, if successfully placed, and if the "grp" parameter
3664  * is TRUE, will be surrounded by a "group" of identical monsters.
3665  *
3666  * Note that certain monsters are now marked as requiring an "escort",
3667  * which is a collection of monsters with similar "race" but lower level.
3668  *
3669  * Some monsters induce a fake "group" flag on their escorts.
3670  *
3671  * Note the "bizarre" use of non-recursion to prevent annoying output
3672  * when running a code profiler.
3673  *
3674  * Note the use of the new "monster allocation table" code to restrict
3675  * the "get_mon_num()" function to "legal" escort types.
3676  */
3677 bool place_monster_aux(int who, int y, int x, int r_idx, u32b mode)
3678 {
3679         int             i;
3680         monster_race    *r_ptr = &r_info[r_idx];
3681
3682         if (one_in_(333) && !(mode & PM_NO_KAGE) && !(mode & PM_FORCE_PET))
3683                 is_kage = TRUE;
3684         else
3685                 is_kage = FALSE;
3686
3687         /* Place one monster, or fail */
3688         if (!place_monster_one(who, y, x, r_idx, mode)) return (FALSE);
3689
3690
3691         /* Require the "group" flag */
3692         if (!(mode & PM_ALLOW_GROUP)) return (TRUE);
3693
3694         place_monster_m_idx = hack_m_idx_ii;
3695
3696         /* Friends for certain monsters */
3697         if (r_ptr->flags1 & (RF1_FRIENDS))
3698         {
3699                 /* Attempt to place a group */
3700                 (void)place_monster_group(who, y, x, r_idx, mode);
3701         }
3702
3703
3704         /* Escorts for certain monsters */
3705         if (r_ptr->flags1 & (RF1_ESCORT))
3706         {
3707                 /* Set the escort index */
3708                 place_monster_idx = r_idx;
3709
3710                 /* Try to place several "escorts" */
3711                 for (i = 0; i < 32; i++)
3712                 {
3713                         int nx, ny, z, d = 3;
3714
3715                         /* Pick a location */
3716                         scatter(&ny, &nx, y, x, d, 0);
3717
3718                         /* Require empty grids */
3719                         if (!cave_empty_bold2(ny, nx)) continue;
3720
3721                         /* Prepare allocation table */
3722                         get_mon_num_prep(place_monster_okay, get_monster_hook2(ny, nx));
3723
3724                         /* Pick a random race */
3725                         z = get_mon_num(r_ptr->level);
3726
3727                         /* Handle failure */
3728                         if (!z) break;
3729
3730                         /* Place a single escort */
3731                         (void)place_monster_one(place_monster_m_idx, ny, nx, z, mode);
3732
3733                         /* Place a "group" of escorts if needed */
3734                         if ((r_info[z].flags1 & RF1_FRIENDS) ||
3735                             (r_ptr->flags1 & RF1_ESCORTS))
3736                         {
3737                                 /* Place a group of monsters */
3738                                 (void)place_monster_group(place_monster_m_idx, ny, nx, z, mode);
3739                         }
3740                 }
3741         }
3742
3743         /* Success */
3744         return (TRUE);
3745 }
3746
3747
3748 /*
3749  * Hack -- attempt to place a monster at the given location
3750  *
3751  * Attempt to find a monster appropriate to the "monster_level"
3752  */
3753 bool place_monster(int y, int x, u32b mode)
3754 {
3755         int r_idx;
3756
3757         /* Prepare allocation table */
3758         get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3759
3760         /* Pick a monster */
3761         r_idx = get_mon_num(monster_level);
3762
3763         /* Handle failure */
3764         if (!r_idx) return (FALSE);
3765
3766         /* Attempt to place the monster */
3767         if (place_monster_aux(0, y, x, r_idx, mode)) return (TRUE);
3768
3769         /* Oops */
3770         return (FALSE);
3771 }
3772
3773
3774 #ifdef MONSTER_HORDES
3775
3776 bool alloc_horde(int y, int x)
3777 {
3778         monster_race *r_ptr = NULL;
3779         int r_idx = 0;
3780         int m_idx;
3781         int attempts = 1000;
3782         int cy = y;
3783         int cx = x;
3784
3785         /* Prepare allocation table */
3786         get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3787
3788         while (--attempts)
3789         {
3790                 /* Pick a monster */
3791                 r_idx = get_mon_num(monster_level);
3792
3793                 /* Handle failure */
3794                 if (!r_idx) return (FALSE);
3795
3796                 r_ptr = &r_info[r_idx];
3797
3798                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3799
3800                 if (r_idx == MON_HAGURE) continue;
3801                 break;
3802         }
3803         if (attempts < 1) return FALSE;
3804
3805         attempts = 1000;
3806
3807         while (--attempts)
3808         {
3809                 /* Attempt to place the monster */
3810                 if (place_monster_aux(0, y, x, r_idx, 0L)) break;
3811         }
3812
3813         if (attempts < 1) return FALSE;
3814
3815         m_idx = cave[y][x].m_idx;
3816
3817         if (m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[m_list[m_idx].r_idx];
3818         summon_kin_type = r_ptr->d_char;
3819
3820         for (attempts = randint1(10) + 5; attempts; attempts--)
3821         {
3822                 scatter(&cy, &cx, y, x, 5, 0);
3823
3824                 (void)summon_specific(m_idx, cy, cx, dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
3825
3826                 y = cy;
3827                 x = cx;
3828         }
3829
3830         return TRUE;
3831 }
3832
3833 #endif /* MONSTER_HORDES */
3834
3835
3836
3837 /*
3838  * Attempt to allocate a random monster in the dungeon.
3839  *
3840  * Place the monster at least "dis" distance from the player.
3841  *
3842  * Use "slp" to choose the initial "sleep" status
3843  *
3844  * Use "monster_level" for the monster level
3845  */
3846 bool alloc_monster(int dis, u32b mode)
3847 {
3848         int                     y = 0, x = 0;
3849         int         attempts_left = 10000;
3850         int guardian = d_info[dungeon_type].final_guardian;
3851
3852         /* Put an Guardian */
3853         if(guardian && d_info[dungeon_type].maxdepth == dun_level && r_info[guardian].cur_num < r_info[guardian].max_num )
3854         {
3855                 int oy;
3856                 int ox;
3857                 int try = 4000;
3858
3859                 /* Find a good position */
3860                 while(try)
3861                 {
3862                         /* Get a random spot */
3863                         oy = randint1(cur_hgt - 4) + 2;
3864                         ox = randint1(cur_wid - 4) + 2;
3865
3866                         /* Is it a good spot ? */
3867                         if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(cave[oy][ox].feat, &r_info[guardian]))
3868                         {
3869                                 /* Place the guardian */
3870                                 if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) break;
3871                         }
3872                         /* One less try */
3873                         try--;
3874                 }
3875         }
3876
3877
3878         /* Find a legal, distant, unoccupied, space */
3879         while (attempts_left--)
3880         {
3881                 /* Pick a location */
3882                 y = randint0(cur_hgt);
3883                 x = randint0(cur_wid);
3884
3885                 /* Require empty floor grid (was "naked") */
3886                 if (dun_level || (wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].terrain != TERRAIN_MOUNTAIN))
3887                 {
3888                         if (!cave_empty_bold2(y, x)) continue;
3889                 }
3890                 else
3891                 {
3892                         if (!cave_empty_bold2(y, x) && (cave[y][x].feat != FEAT_MOUNTAIN)) continue;
3893                 }
3894
3895                 /* Accept far away grids */
3896                 if (distance(y, x, py, px) > dis) break;
3897         }
3898
3899         if (!attempts_left)
3900         {
3901                 if (cheat_xtra || cheat_hear)
3902                 {
3903 #ifdef JP
3904 msg_print("·Ù¹ð¡ª¿·¤¿¤Ê¥â¥ó¥¹¥¿¡¼¤òÇÛÃ֤Ǥ­¤Þ¤»¤ó¡£¾®¤µ¤¤³¬¤Ç¤¹¤«¡©");
3905 #else
3906                         msg_print("Warning! Could not allocate a new monster. Small level?");
3907 #endif
3908
3909                 }
3910
3911                 return (FALSE);
3912         }
3913
3914
3915 #ifdef MONSTER_HORDES
3916         if (randint1(5000) <= dun_level)
3917         {
3918                 if (alloc_horde(y, x))
3919                 {
3920 #ifdef JP
3921 if (cheat_hear) msg_print("¥â¥ó¥¹¥¿¡¼¤ÎÂç·²");
3922 #else
3923                         if (cheat_hear) msg_print("Monster horde.");
3924 #endif
3925
3926                         return (TRUE);
3927                 }
3928         }
3929         else
3930         {
3931 #endif /* MONSTER_HORDES */
3932
3933                 /* Attempt to place the monster, allow groups */
3934                 if (place_monster(y, x, (mode | PM_ALLOW_GROUP))) return (TRUE);
3935
3936 #ifdef MONSTER_HORDES
3937         }
3938 #endif /* MONSTER_HORDES */
3939
3940         /* Nope */
3941         return (FALSE);
3942 }
3943
3944
3945
3946
3947 /*
3948  * Hack -- help decide if a monster race is "okay" to summon
3949  */
3950 static bool summon_specific_okay(int r_idx)
3951 {
3952         monster_race *r_ptr = &r_info[r_idx];
3953
3954         /* Hack - Only summon dungeon monsters */
3955         if (!monster_dungeon(r_idx)) return (FALSE);
3956
3957         /* Hack -- identify the summoning monster */
3958         if (summon_specific_who > 0)
3959         {
3960                 monster_type *m_ptr = &m_list[summon_specific_who];
3961
3962                 /* Do not summon enemies */
3963
3964                 /* Friendly vs. opposite aligned normal or pet */
3965                 if (((r_ptr->flags3 & RF3_EVIL) &&
3966                           (m_ptr->sub_align & SUB_ALIGN_GOOD)) ||
3967                          ((r_ptr->flags3 & RF3_GOOD) &&
3968                           (m_ptr->sub_align & SUB_ALIGN_EVIL)))
3969                 {
3970                         return FALSE;
3971                 }
3972
3973                 /* Hostile vs. non-hostile */
3974                 if (is_hostile(m_ptr) != summon_specific_hostile)
3975                 {
3976                         return FALSE;
3977                 }
3978         }
3979         /* Use the player's alignment */
3980         else if (summon_specific_who < 0)
3981         {
3982                 /* Do not summon enemies of the pets */
3983                 if ((p_ptr->align < -9) && (r_ptr->flags3 & RF3_GOOD))
3984                 {
3985                         if (!one_in_((0-p_ptr->align)/2+1)) return FALSE;
3986                 }
3987                 else if ((p_ptr->align > 9) && (r_ptr->flags3 & RF3_EVIL))
3988                 {
3989                         if (!one_in_(p_ptr->align/2+1)) return FALSE;
3990                 }
3991         }
3992
3993         /* Hack -- no specific type specified */
3994         if (!summon_specific_type) return (TRUE);
3995
3996         if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7))) return FALSE;
3997
3998         if ((summon_specific_who < 0) &&
3999             ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) &&
4000             (((p_ptr->align > 9) && (r_ptr->flags3 & RF3_EVIL)) ||
4001              ((p_ptr->align < -9) && (r_ptr->flags3 & RF3_GOOD))))
4002                 return FALSE;
4003
4004         if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[dungeon_type].flags1 & DF1_CHAMELEON)) return TRUE;
4005
4006         return (summon_specific_aux(r_idx));
4007 }
4008
4009
4010 /*
4011  * Place a monster (of the specified "type") near the given
4012  * location.  Return TRUE if a monster was actually summoned.
4013  *
4014  * We will attempt to place the monster up to 10 times before giving up.
4015  *
4016  * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
4017  * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
4018  * Note: None of the other summon codes will ever summon Unique's.
4019  *
4020  * This function has been changed.  We now take the "monster level"
4021  * of the summoning monster as a parameter, and use that, along with
4022  * the current dungeon level, to help determine the level of the
4023  * desired monster.  Note that this is an upper bound, and also
4024  * tends to "prefer" monsters of that level.  Currently, we use
4025  * the average of the dungeon and monster levels, and then add
4026  * five to allow slight increases in monster power.
4027  *
4028  * Note that we use the new "monster allocation table" creation code
4029  * to restrict the "get_mon_num()" function to the set of "legal"
4030  * monsters, making this function much faster and more reliable.
4031  *
4032  * Note that this function may not succeed, though this is very rare.
4033  */
4034 bool summon_specific(int who, int y1, int x1, int lev, int type, u32b mode)
4035 {
4036         int x, y, r_idx;
4037
4038         if (p_ptr->inside_arena) return (FALSE);
4039
4040         if (!mon_scatter(&y, &x, y1, x1, 2)) return FALSE;
4041
4042         /* Save the summoner */
4043         summon_specific_who = who;
4044
4045         /* Save the "summon" type */
4046         summon_specific_type = type;
4047
4048         summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
4049
4050         /* Save the hostility */
4051         summon_specific_hostile = (!(mode & PM_FORCE_FRIENDLY) && !(is_friendly_idx(who)) && !(mode & PM_FORCE_PET));
4052
4053         /* Prepare allocation table */
4054         get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
4055
4056         /* Pick a monster, using the level calculation */
4057         r_idx = get_mon_num((dun_level + lev) / 2 + 5);
4058
4059         /* Handle failure */
4060         if (!r_idx)
4061         {
4062                 summon_specific_type = 0;
4063                 return (FALSE);
4064         }
4065
4066         if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
4067
4068         /* Attempt to place the monster (awake, allow groups) */
4069         if (!place_monster_aux(who, y, x, r_idx, mode))
4070         {
4071                 summon_specific_type = 0;
4072                 return (FALSE);
4073         }
4074
4075         summon_specific_type = 0;
4076         /* Success */
4077         return (TRUE);
4078 }
4079
4080 /* A "dangerous" function, creates a pet of the specified type */
4081 bool summon_named_creature (int who, int oy, int ox, int r_idx, u32b mode)
4082 {
4083         int x, y;
4084
4085         /* Paranoia */
4086         /* if (!r_idx) return; */
4087
4088         /* Prevent illegal monsters */
4089         if (r_idx >= max_r_idx) return FALSE;
4090
4091         if (p_ptr->inside_arena) return FALSE;
4092
4093         if (!mon_scatter(&y, &x, oy, ox, 2)) return FALSE;
4094
4095         /* Place it (allow groups) */
4096         return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
4097 }
4098
4099
4100 /*
4101  * Let the given monster attempt to reproduce.
4102  *
4103  * Note that "reproduction" REQUIRES empty space.
4104  */
4105 bool multiply_monster(int m_idx, bool clone, u32b mode)
4106 {
4107         monster_type    *m_ptr = &m_list[m_idx];
4108
4109         int y, x;
4110
4111         if (!mon_scatter(&y, &x, m_ptr->fy, m_ptr->fx, 1))
4112                 return FALSE;
4113
4114         if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
4115
4116         /* Create a new monster (awake, no groups) */
4117         if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE)))
4118                 return FALSE;
4119
4120         if (clone)
4121         {
4122                 m_list[hack_m_idx_ii].smart |= SM_CLONED;
4123                 m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
4124         }
4125
4126         return TRUE;
4127 }
4128
4129
4130
4131
4132
4133 /*
4134  * Dump a message describing a monster's reaction to damage
4135  *
4136  * Technically should attempt to treat "Beholder"'s as jelly's
4137  */
4138 void message_pain(int m_idx, int dam)
4139 {
4140         long oldhp, newhp, tmp;
4141         int percentage;
4142
4143         monster_type *m_ptr = &m_list[m_idx];
4144         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4145
4146         char m_name[80];
4147
4148
4149         /* Get the monster name */
4150         monster_desc(m_name, m_ptr, 0);
4151
4152         /* Notice non-damage */
4153         if (dam == 0)
4154         {
4155 #ifdef JP
4156                 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Æ¤¤¤Ê¤¤¡£", m_name);
4157 #else
4158                 msg_format("%^s is unharmed.", m_name);
4159 #endif
4160
4161                 return;
4162         }
4163
4164         /* Note -- subtle fix -CFT */
4165         newhp = (long)(m_ptr->hp);
4166         oldhp = newhp + (long)(dam);
4167         tmp = (newhp * 100L) / oldhp;
4168         percentage = (int)(tmp);
4169
4170
4171         /* Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs */
4172         if (strchr(",ejmvwQ", r_ptr->d_char))
4173         {
4174 #ifdef JP
4175                 if (percentage > 95)
4176                         msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4177                 else if (percentage > 75)
4178                         msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4179                 else if (percentage > 50)
4180                         msg_format("%^s¤Ï½Ì¤³¤Þ¤Ã¤¿¡£", m_name);
4181                 else if (percentage > 35)
4182                         msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4183                 else if (percentage > 20)
4184                         msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4185                 else if (percentage > 10)
4186                         msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4187                 else
4188                         msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4189 #else
4190                 if (percentage > 95)
4191                         msg_format("%^s barely notices.", m_name);
4192                 else if (percentage > 75)
4193                         msg_format("%^s flinches.", m_name);
4194                 else if (percentage > 50)
4195                         msg_format("%^s squelches.", m_name);
4196                 else if (percentage > 35)
4197                         msg_format("%^s quivers in pain.", m_name);
4198                 else if (percentage > 20)
4199                         msg_format("%^s writhes about.", m_name);
4200                 else if (percentage > 10)
4201                         msg_format("%^s writhes in agony.", m_name);
4202                 else
4203                         msg_format("%^s jerks limply.", m_name);
4204 #endif
4205
4206         }
4207
4208
4209         /* Fish */
4210         else if (strchr("l", r_ptr->d_char))
4211         {
4212                 if (percentage > 95)
4213 #ifdef JP
4214 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4215 #else
4216                         msg_format("%^s barely notices.", m_name);
4217 #endif
4218                 else if (percentage > 75)
4219 #ifdef JP
4220 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4221 #else
4222                         msg_format("%^s flinches.", m_name);
4223 #endif
4224                 else if (percentage > 50)
4225 #ifdef JP
4226 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4227 #else
4228                         msg_format("%^s hesitates.", m_name);
4229 #endif
4230                 else if (percentage > 35)
4231 #ifdef JP
4232 msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4233 #else
4234                         msg_format("%^s quivers in pain.", m_name);
4235 #endif
4236                 else if (percentage > 20)
4237 #ifdef JP
4238 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4239 #else
4240                         msg_format("%^s writhes about.", m_name);
4241 #endif
4242                 else if (percentage > 10)
4243 #ifdef JP
4244 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4245 #else
4246                         msg_format("%^s writhes in agony.", m_name);
4247 #endif
4248                 else
4249 #ifdef JP
4250 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4251 #else
4252                         msg_format("%^s jerks limply.", m_name);
4253 #endif
4254         }
4255
4256
4257         /* Golems, Walls, Doors, Stairs */
4258         else if (strchr("g#+<>", r_ptr->d_char))
4259         {
4260                 if (percentage > 95)
4261 #ifdef JP
4262 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4263 #else
4264                         msg_format("%^s ignores the attack.", m_name);
4265 #endif
4266                 else if (percentage > 75)
4267 #ifdef JP
4268 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4269 #else
4270                         msg_format("%^s shrugs off the attack.", m_name);
4271 #endif
4272                 else if (percentage > 50)
4273 #ifdef JP
4274 msg_format("%^s¤ÏÍëÌĤΤ褦¤ËËʤ¨¤¿¡£", m_name);
4275 #else
4276                         msg_format("%^s roars thunderously.", m_name);
4277 #endif
4278                 else if (percentage > 35)
4279 #ifdef JP
4280 msg_format("%^s¤Ï¶ì¤·¤²¤ËËʤ¨¤¿¡£", m_name);
4281 #else
4282                         msg_format("%^s rumbles.", m_name);
4283 #endif
4284                 else if (percentage > 20)
4285 #ifdef JP
4286 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4287 #else
4288                         msg_format("%^s grunts.", m_name);
4289 #endif
4290                 else if (percentage > 10)
4291 #ifdef JP
4292 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4293 #else
4294                         msg_format("%^s hesitates.", m_name);
4295 #endif
4296                 else
4297 #ifdef JP
4298 msg_format("%^s¤Ï¤¯¤·¤ã¤¯¤·¤ã¤Ë¤Ê¤Ã¤¿¡£", m_name);
4299 #else
4300                         msg_format("%^s crumples.", m_name);
4301 #endif
4302         }
4303
4304
4305         /* Snakes, Hydrae, Reptiles, Mimics */
4306         else if (strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char))
4307         {
4308                 if (percentage > 95)
4309 #ifdef JP
4310 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4311 #else
4312                         msg_format("%^s barely notices.", m_name);
4313 #endif
4314                 else if (percentage > 75)
4315 #ifdef JP
4316 msg_format("%^s¤Ï¥·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4317 #else
4318                         msg_format("%^s hisses.", m_name);
4319 #endif
4320                 else if (percentage > 50)
4321 #ifdef JP
4322 msg_format("%^s¤ÏÅܤäÆƬ¤ò¾å¤²¤¿¡£", m_name);
4323 #else
4324                         msg_format("%^s rears up in anger.", m_name);
4325 #endif
4326                 else if (percentage > 35)
4327 #ifdef JP
4328 msg_format("%^s¤ÏÌÔÁ³¤È°Ò³Å¤·¤¿¡£", m_name);
4329 #else
4330                         msg_format("%^s hisses furiously.", m_name);
4331 #endif
4332                 else if (percentage > 20)
4333 #ifdef JP
4334 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4335 #else
4336                         msg_format("%^s writhes about.", m_name);
4337 #endif
4338                 else if (percentage > 10)
4339 #ifdef JP
4340 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4341 #else
4342                         msg_format("%^s writhes in agony.", m_name);
4343 #endif
4344                 else
4345 #ifdef JP
4346 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4347 #else
4348                         msg_format("%^s jerks limply.", m_name);
4349 #endif
4350         }
4351
4352
4353         /* Felines */
4354         else if (strchr("f", r_ptr->d_char))
4355         {
4356                 if (percentage > 95)
4357 #ifdef JP
4358 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4359 #else
4360                         msg_format("%^s shrugs off the attack.", m_name);
4361 #endif
4362                 else if (percentage > 75)
4363 #ifdef JP
4364 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4365 #else
4366                         msg_format("%^s roars.", m_name);
4367 #endif
4368                 else if (percentage > 50)
4369 #ifdef JP
4370 msg_format("%^s¤ÏÅܤäÆËʤ¨¤¿¡£", m_name);
4371 #else
4372                         msg_format("%^s growls angrily.", m_name);
4373 #endif
4374                 else if (percentage > 35)
4375 #ifdef JP
4376 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4377 #else
4378                         msg_format("%^s hisses with pain.", m_name);
4379 #endif
4380                 else if (percentage > 20)
4381 #ifdef JP
4382 msg_format("%^s¤ÏÄˤߤǼ塹¤·¤¯ÌĤ¤¤¿¡£", m_name);
4383 #else
4384                         msg_format("%^s mewls in pain.", m_name);
4385 #endif
4386                 else if (percentage > 10)
4387 #ifdef JP
4388 msg_format("%^s¤Ï¶ìÄˤˤ¦¤á¤¤¤¿¡£", m_name);
4389 #else
4390                         msg_format("%^s hisses in agony.", m_name);
4391 #endif
4392                 else
4393 #ifdef JP
4394 msg_format("%s¤Ï°¥¤ì¤ÊÌĤ­À¼¤ò½Ð¤·¤¿¡£", m_name);
4395 #else
4396                         msg_format("%^s mewls pitifully.", m_name);
4397 #endif
4398         }
4399
4400
4401         /* Ants, Centipedes, Flies, Insects, Beetles, Spiders */
4402         else if (strchr("acFIKS", r_ptr->d_char))
4403         {
4404                 if (percentage > 95)
4405 #ifdef JP
4406 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4407 #else
4408                         msg_format("%^s ignores the attack.", m_name);
4409 #endif
4410                 else if (percentage > 75)
4411 #ifdef JP
4412 msg_format("%^s¤Ï¥­¡¼¥­¡¼ÌĤ¤¤¿¡£", m_name);
4413 #else
4414                         msg_format("%^s chitters.", m_name);
4415 #endif
4416
4417                 else if (percentage > 50)
4418 #ifdef JP
4419 msg_format("%^s¤Ï¥è¥í¥è¥íƨ¤²²ó¤Ã¤¿¡£", m_name);
4420 #else
4421                         msg_format("%^s scuttles about.", m_name);
4422 #endif
4423
4424                 else if (percentage > 35)
4425 #ifdef JP
4426 msg_format("%^s¤Ï¤¦¤ë¤µ¤¯ÌĤ¤¤¿¡£", m_name);
4427 #else
4428                         msg_format("%^s twitters.", m_name);
4429 #endif
4430
4431                 else if (percentage > 20)
4432 #ifdef JP
4433 msg_format("%^s¤ÏÄˤߤËáÛÚ»¤·¤¿¡£", m_name);
4434 #else
4435                         msg_format("%^s jerks in pain.", m_name);
4436 #endif
4437
4438                 else if (percentage > 10)
4439 #ifdef JP
4440 msg_format("%^s¤Ï¶ìÄˤÇáÛÚ»¤·¤¿¡£", m_name);
4441 #else
4442                         msg_format("%^s jerks in agony.", m_name);
4443 #endif
4444
4445                 else
4446 #ifdef JP
4447 msg_format("%^s¤Ï¥Ô¥¯¥Ô¥¯¤Ò¤­¤Ä¤Ã¤¿¡£", m_name);
4448 #else
4449                         msg_format("%^s twitches.", m_name);
4450 #endif
4451
4452         }
4453
4454
4455         /* Birds */
4456         else if (strchr("B", r_ptr->d_char))
4457         {
4458                 if (percentage > 95)
4459 #ifdef JP
4460 msg_format("%^s¤Ï¤µ¤¨¤º¤Ã¤¿¡£", m_name);
4461 #else
4462                         msg_format("%^s chirps.", m_name);
4463 #endif
4464
4465                 else if (percentage > 75)
4466 #ifdef JP
4467 msg_format("%^s¤Ï¥Ô¡¼¥Ô¡¼ÌĤ¤¤¿¡£", m_name);
4468 #else
4469                         msg_format("%^s twitters.", m_name);
4470 #endif
4471
4472                 else if (percentage > 50)
4473 #ifdef JP
4474 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ¤¤¿¡£", m_name);
4475 #else
4476                         msg_format("%^s squawks.", m_name);
4477 #endif
4478
4479                 else if (percentage > 35)
4480 #ifdef JP
4481 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ­¤ï¤á¤¤¤¿¡£", m_name);
4482 #else
4483                         msg_format("%^s chatters.", m_name);
4484 #endif
4485
4486                 else if (percentage > 20)
4487 #ifdef JP
4488 msg_format("%^s¤Ï¶ì¤·¤ó¤À¡£", m_name);
4489 #else
4490                         msg_format("%^s jeers.", m_name);
4491 #endif
4492
4493                 else if (percentage > 10)
4494 #ifdef JP
4495 msg_format("%^s¤Ï¤Î¤¿¤¦¤Á²ó¤Ã¤¿¡£", m_name);
4496 #else
4497                         msg_format("%^s flutters about.", m_name);
4498 #endif
4499
4500                 else
4501 #ifdef JP
4502 msg_format("%^s¤Ï¥­¡¼¥­¡¼¤ÈÌĤ­¶«¤ó¤À¡£", m_name);
4503 #else
4504                         msg_format("%^s squeaks.", m_name);
4505 #endif
4506
4507         }
4508
4509
4510         /* Dragons, Demons, High Undead */
4511         else if (strchr("duDLUW", r_ptr->d_char))
4512         {
4513                 if (percentage > 95)
4514 #ifdef JP
4515 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4516 #else
4517                         msg_format("%^s ignores the attack.", m_name);
4518 #endif
4519
4520                 else if (percentage > 75)
4521 #ifdef JP
4522 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4523 #else
4524                         msg_format("%^s flinches.", m_name);
4525 #endif
4526
4527                 else if (percentage > 50)
4528 #ifdef JP
4529 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4530 #else
4531                         msg_format("%^s hisses in pain.", m_name);
4532 #endif
4533
4534                 else if (percentage > 35)
4535 #ifdef JP
4536 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4537 #else
4538                         msg_format("%^s snarls with pain.", m_name);
4539 #endif
4540
4541                 else if (percentage > 20)
4542 #ifdef JP
4543 msg_format("%^s¤ÏÄˤߤËËʤ¨¤¿¡£", m_name);
4544 #else
4545                         msg_format("%^s roars with pain.", m_name);
4546 #endif
4547
4548                 else if (percentage > 10)
4549 #ifdef JP
4550 msg_format("%^s¤Ï¶ì¤·¤²¤Ë¶«¤ó¤À¡£", m_name);
4551 #else
4552                         msg_format("%^s gasps.", m_name);
4553 #endif
4554
4555                 else
4556 #ifdef JP
4557 msg_format("%^s¤Ï¼å¡¹¤·¤¯¤¦¤Ê¤Ã¤¿¡£", m_name);
4558 #else
4559                         msg_format("%^s snarls feebly.", m_name);
4560 #endif
4561
4562         }
4563
4564
4565         /* Skeletons */
4566         else if (strchr("s", r_ptr->d_char))
4567         {
4568                 if (percentage > 95)
4569 #ifdef JP
4570 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4571 #else
4572                         msg_format("%^s ignores the attack.", m_name);
4573 #endif
4574
4575                 else if (percentage > 75)
4576 #ifdef JP
4577 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4578 #else
4579                         msg_format("%^s shrugs off the attack.", m_name);
4580 #endif
4581
4582                 else if (percentage > 50)
4583 #ifdef JP
4584 msg_format("%^s¤Ï¥«¥¿¥«¥¿¤È¾Ð¤Ã¤¿¡£", m_name);
4585 #else
4586                         msg_format("%^s rattles.", m_name);
4587 #endif
4588
4589                 else if (percentage > 35)
4590 #ifdef JP
4591 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4592 #else
4593                         msg_format("%^s stumbles.", m_name);
4594 #endif
4595
4596                 else if (percentage > 20)
4597 #ifdef JP
4598 msg_format("%^s¤Ï¥«¥¿¥«¥¿¸À¤Ã¤¿¡£", m_name);
4599 #else
4600                         msg_format("%^s rattles.", m_name);
4601 #endif
4602
4603                 else if (percentage > 10)
4604 #ifdef JP
4605 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4606 #else
4607                         msg_format("%^s staggers.", m_name);
4608 #endif
4609
4610                 else
4611 #ifdef JP
4612 msg_format("%^s¤Ï¥¬¥¿¥¬¥¿¸À¤Ã¤¿¡£", m_name);
4613 #else
4614                         msg_format("%^s clatters.", m_name);
4615 #endif
4616
4617         }
4618
4619
4620         /* Zombies */
4621         else if (strchr("z", r_ptr->d_char))
4622         {
4623                 if (percentage > 95)
4624 #ifdef JP
4625 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4626 #else
4627                         msg_format("%^s ignores the attack.", m_name);
4628 #endif
4629
4630                 else if (percentage > 75)
4631 #ifdef JP
4632 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4633 #else
4634                         msg_format("%^s shrugs off the attack.", m_name);
4635 #endif
4636
4637                 else if (percentage > 50)
4638 #ifdef JP
4639 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4640 #else
4641                         msg_format("%^s groans.", m_name);
4642 #endif
4643
4644                 else if (percentage > 35)
4645 #ifdef JP
4646 msg_format("%s¤Ï¶ì¤·¤²¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4647 #else
4648                         msg_format("%^s moans.", m_name);
4649 #endif
4650
4651                 else if (percentage > 20)
4652 #ifdef JP
4653 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4654 #else
4655                         msg_format("%^s hesitates.", m_name);
4656 #endif
4657
4658                 else if (percentage > 10)
4659 #ifdef JP
4660 msg_format("%^s¤Ï¤¦¤Ê¤Ã¤¿¡£", m_name);
4661 #else
4662                         msg_format("%^s grunts.", m_name);
4663 #endif
4664
4665                 else
4666 #ifdef JP
4667 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4668 #else
4669                         msg_format("%^s staggers.", m_name);
4670 #endif
4671
4672         }
4673
4674
4675         /* Ghosts */
4676         else if (strchr("G", r_ptr->d_char))
4677
4678         {
4679                 if (percentage > 95)
4680 #ifdef JP
4681 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4682 #else
4683                         msg_format("%^s ignores the attack.", m_name);
4684 #endif
4685
4686                 else if (percentage > 75)
4687 #ifdef JP
4688 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4689 #else
4690                         msg_format("%^s shrugs off the attack.", m_name);
4691 #endif
4692
4693                 else if (percentage > 50)
4694 #ifdef JP
4695 msg_format("%s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4696 #else
4697                         msg_format("%^s moans.", m_name);
4698 #endif
4699
4700                 else if (percentage > 35)
4701 #ifdef JP
4702 msg_format("%^s¤Ïµã¤­¤ï¤á¤¤¤¿¡£", m_name);
4703 #else
4704                         msg_format("%^s wails.", m_name);
4705 #endif
4706
4707                 else if (percentage > 20)
4708 #ifdef JP
4709 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4710 #else
4711                         msg_format("%^s howls.", m_name);
4712 #endif
4713
4714                 else if (percentage > 10)
4715 #ifdef JP
4716 msg_format("%s¤Ï¼å¡¹¤·¤¯¤¦¤á¤¤¤¿¡£", m_name);
4717 #else
4718                         msg_format("%^s moans softly.", m_name);
4719 #endif
4720
4721                 else
4722 #ifdef JP
4723 msg_format("%^s¤Ï¤«¤¹¤«¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4724 #else
4725                         msg_format("%^s sighs.", m_name);
4726 #endif
4727
4728         }
4729
4730
4731         /* Dogs and Hounds */
4732         else if (strchr("CZ", r_ptr->d_char))
4733         {
4734 #ifdef JP
4735                 if (percentage > 95)
4736                         msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4737                 else if (percentage > 75)
4738                         msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4739                 else if (percentage > 50)
4740                         msg_format("%^s¤ÏÄˤߤǥ­¥ã¥ó¥­¥ã¥óËʤ¨¤¿¡£", m_name);
4741                 else if (percentage > 35)
4742                         msg_format("%^s¤ÏÄˤߤÇÌĤ­¤ï¤á¤¤¤¿¡£", m_name);
4743                 else if (percentage > 20)
4744                         msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÌĤ­¤ï¤á¤¤¤¿¡£", m_name);
4745                 else if (percentage > 10)
4746                         msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4747                 else
4748                         msg_format("%^s¤Ï¼å¡¹¤·¤¯Ëʤ¨¤¿¡£", m_name);
4749 #else
4750                 if (percentage > 95)
4751                         msg_format("%^s shrugs off the attack.", m_name);
4752                 else if (percentage > 75)
4753                         msg_format("%^s snarls with pain.", m_name);
4754                 else if (percentage > 50)
4755                         msg_format("%^s yelps in pain.", m_name);
4756                 else if (percentage > 35)
4757                         msg_format("%^s howls in pain.", m_name);
4758                 else if (percentage > 20)
4759                         msg_format("%^s howls in agony.", m_name);
4760                 else if (percentage > 10)
4761                         msg_format("%^s writhes in agony.", m_name);
4762                 else
4763                         msg_format("%^s yelps feebly.", m_name);
4764 #endif
4765
4766         }
4767
4768         /* One type of monsters (ignore,squeal,shriek) */
4769         else if (strchr("Xbilqrt", r_ptr->d_char))
4770         {
4771 #ifdef JP
4772                 if (percentage > 95)
4773                         msg_format("%^s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4774                 else if (percentage > 75)
4775                         msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4776                 else if (percentage > 50)
4777                         msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4778                 else if (percentage > 35)
4779                         msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4780                 else if (percentage > 20)
4781                         msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4782                 else if (percentage > 10)
4783                         msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4784                 else
4785                         msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4786 #else
4787                 if (percentage > 95)
4788                         msg_format("%^s ignores the attack.", m_name);
4789                 else if (percentage > 75)
4790                         msg_format("%^s grunts with pain.", m_name);
4791                 else if (percentage > 50)
4792                         msg_format("%^s squeals in pain.", m_name);
4793                 else if (percentage > 35)
4794                         msg_format("%^s shrieks in pain.", m_name);
4795                 else if (percentage > 20)
4796                         msg_format("%^s shrieks in agony.", m_name);
4797                 else if (percentage > 10)
4798                         msg_format("%^s writhes in agony.", m_name);
4799                 else
4800                         msg_format("%^s cries out feebly.", m_name);
4801 #endif
4802
4803         }
4804
4805         /* Another type of monsters (shrug,cry,scream) */
4806         else
4807         {
4808 #ifdef JP
4809                 if (percentage > 95)
4810                         msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4811                 else if (percentage > 75)
4812                         msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4813                 else if (percentage > 50)
4814                         msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4815                 else if (percentage > 35)
4816                         msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4817                 else if (percentage > 20)
4818                         msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4819                 else if (percentage > 10)
4820                         msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4821                 else
4822                         msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4823 #else
4824                 if (percentage > 95)
4825                         msg_format("%^s shrugs off the attack.", m_name);
4826                 else if (percentage > 75)
4827                         msg_format("%^s grunts with pain.", m_name);
4828                 else if (percentage > 50)
4829                         msg_format("%^s cries out in pain.", m_name);
4830                 else if (percentage > 35)
4831                         msg_format("%^s screams in pain.", m_name);
4832                 else if (percentage > 20)
4833                         msg_format("%^s screams in agony.", m_name);
4834                 else if (percentage > 10)
4835                         msg_format("%^s writhes in agony.", m_name);
4836                 else
4837                         msg_format("%^s cries out feebly.", m_name);
4838 #endif
4839
4840         }
4841 }
4842
4843
4844 /*
4845  * Learn about an "observed" resistance.
4846  */
4847 void update_smart_learn(int m_idx, int what)
4848 {
4849 #ifdef DRS_SMART_OPTIONS
4850
4851         monster_type *m_ptr = &m_list[m_idx];
4852
4853         monster_race *r_ptr = &r_info[m_ptr->r_idx];
4854
4855
4856         /* Not allowed to learn */
4857         if (!smart_learn) return;
4858
4859         /* Too stupid to learn anything */
4860         if (r_ptr->flags2 & (RF2_STUPID)) return;
4861
4862         /* Not intelligent, only learn sometimes */
4863         if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
4864
4865
4866         /* XXX XXX XXX */
4867
4868         /* Analyze the knowledge */
4869         switch (what)
4870         {
4871         case DRS_ACID:
4872                 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
4873                 if (IS_OPPOSE_ACID()) m_ptr->smart |= (SM_OPP_ACID);
4874                 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
4875                 break;
4876
4877         case DRS_ELEC:
4878                 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
4879                 if (IS_OPPOSE_ELEC()) m_ptr->smart |= (SM_OPP_ELEC);
4880                 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
4881                 break;
4882
4883         case DRS_FIRE:
4884                 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
4885                 if (IS_OPPOSE_FIRE()) m_ptr->smart |= (SM_OPP_FIRE);
4886                 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
4887                 break;
4888
4889         case DRS_COLD:
4890                 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
4891                 if (IS_OPPOSE_COLD()) m_ptr->smart |= (SM_OPP_COLD);
4892                 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
4893                 break;
4894
4895         case DRS_POIS:
4896                 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
4897                 if (IS_OPPOSE_POIS()) m_ptr->smart |= (SM_OPP_POIS);
4898                 break;
4899
4900
4901         case DRS_NETH:
4902                 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
4903                 break;
4904
4905         case DRS_LITE:
4906                 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
4907                 break;
4908
4909         case DRS_DARK:
4910                 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
4911                 break;
4912
4913         case DRS_FEAR:
4914                 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
4915                 break;
4916
4917         case DRS_CONF:
4918                 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
4919                 break;
4920
4921         case DRS_CHAOS:
4922                 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
4923                 break;
4924
4925         case DRS_DISEN:
4926                 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
4927                 break;
4928
4929         case DRS_BLIND:
4930                 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
4931                 break;
4932
4933         case DRS_NEXUS:
4934                 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
4935                 break;
4936
4937         case DRS_SOUND:
4938                 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
4939                 break;
4940
4941         case DRS_SHARD:
4942                 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
4943                 break;
4944
4945         case DRS_FREE:
4946                 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
4947                 break;
4948
4949         case DRS_MANA:
4950                 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
4951                 break;
4952
4953         case DRS_REFLECT:
4954                 if (p_ptr->reflect) m_ptr-> smart |= (SM_IMM_REFLECT);
4955                 break;
4956         }
4957
4958 #endif /* DRS_SMART_OPTIONS */
4959
4960 }
4961
4962
4963 /*
4964  * Place the player in the dungeon XXX XXX
4965  */
4966 bool player_place(int y, int x)
4967 {
4968         /* Paranoia XXX XXX */
4969         if (cave[y][x].m_idx != 0) return FALSE;
4970
4971         /* Save player location */
4972         py = y;
4973         px = x;
4974
4975         /* Success */
4976         return TRUE;
4977 }
4978
4979
4980 /*
4981  * Drop all items carried by a monster
4982  */
4983 void monster_drop_carried_objects(monster_type *m_ptr)
4984 {
4985         s16b this_o_idx, next_o_idx = 0;
4986         object_type forge;
4987         object_type *o_ptr;
4988         object_type *q_ptr;
4989
4990
4991         /* Drop objects being carried */
4992         for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4993         {
4994                 /* Acquire object */
4995                 o_ptr = &o_list[this_o_idx];
4996
4997                 /* Acquire next object */
4998                 next_o_idx = o_ptr->next_o_idx;
4999
5000                 /* Paranoia */
5001                 o_ptr->held_m_idx = 0;
5002
5003                 /* Get local object */
5004                 q_ptr = &forge;
5005
5006                 /* Copy the object */
5007                 object_copy(q_ptr, o_ptr);
5008
5009                 /* Delete the object */
5010                 delete_object_idx(this_o_idx);
5011
5012                 /* Drop it */
5013                 (void)drop_near(q_ptr, -1, m_ptr->fy, m_ptr->fx);
5014         }
5015
5016         /* Forget objects */
5017         m_ptr->hold_o_idx = 0;
5018 }