OSDN Git Service

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