OSDN Git Service

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