OSDN Git Service

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