OSDN Git Service

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