OSDN Git Service

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