OSDN Git Service

[Refactor] #37353 ウィザードモードフラグ を player_type 構造体から world_type 構造体へ移動.
[hengband/hengband.git] / src / monster-status.c
1 #include "angband.h"
2 #include "core.h"
3 #include "util.h"
4
5 #include "creature.h"
6 #include "cmd-dump.h"
7 #include "dungeon.h"
8 #include "floor.h"
9 #include "grid.h"
10 #include "monster.h"
11 #include "monster-status.h"
12 #include "monster-spell.h"
13 #include "monster-process.h"
14 #include "spells.h"
15 #include "spells-summon.h"
16 #include "monsterrace-hook.h"
17 #include "object-curse.h"
18 #include "artifact.h"
19 #include "avatar.h"
20 #include "files.h"
21 #include "player-effects.h"
22 #include "player-personality.h"
23 #include "view-mainwindow.h"
24 #include "world.h"
25 #include "report.h"
26 #include "melee.h"
27
28
29 /*!
30 * @brief モンスターIDからPOWERFULフラグの有無を取得する /
31 * @param m_idx モンスターID
32 * @return POWERFULフラグがあればTRUE、なければFALSEを返す。
33 */
34 bool monster_is_powerful(MONSTER_IDX m_idx)
35 {
36         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
37         monster_race *r_ptr = &r_info[m_ptr->r_idx];
38         bool powerful = r_ptr->flags2 & RF2_POWERFUL ? TRUE : FALSE;
39         return powerful;
40 }
41
42 /*!
43 * @brief モンスターIDからモンスターのレベルを取得する(ただし最低1を保証する) /
44 * @param m_idx モンスターID
45 * @return モンスターのレベル
46 */
47 DEPTH monster_level_idx(MONSTER_IDX m_idx)
48 {
49         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
50         monster_race *r_ptr = &r_info[m_ptr->r_idx];
51         DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
52         return rlev;
53 }
54
55 /*!
56  * @brief モンスターに与えたダメージの修正処理 /
57  * Modify the physical damage done to the monster.
58  * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
59  * @param dam ダメージ基本値
60  * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
61  * @return 修正を行った結果のダメージ量
62  * @details
63  * <pre>
64  * (for example when it's invulnerable or shielded)
65  * ToDo: Accept a damage-type to calculate the modified damage from
66  * things like fire, frost, lightning, poison, ... attacks.
67  * "type" is not yet used and should be 0.
68  * </pre>
69  */
70 HIT_POINT mon_damage_mod(monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
71 {
72         monster_race *r_ptr = &r_info[m_ptr->r_idx];
73
74         if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
75         {
76                 dam /= 100;
77                 if ((dam == 0) && one_in_(3)) dam = 1;
78         }
79
80         if (MON_INVULNER(m_ptr))
81         {
82                 if (is_psy_spear)
83                 {
84                         if (!p_ptr->blind && is_seen(m_ptr))
85                         {
86                                 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
87                         }
88                 }
89                 else if (!one_in_(PENETRATE_INVULNERABILITY))
90                 {
91                         return (0);
92                 }
93         }
94         return (dam);
95 }
96
97
98
99 /*!
100  * @brief モンスターに与えたダメージを元に経験値を加算する /
101  * Calculate experience point to be get
102  * @param dam 与えたダメージ量
103  * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
104  * @return なし
105  * @details
106  * <pre>
107  * Even the 64 bit operation is not big enough to avoid overflaw
108  * unless we carefully choose orders of multiplication and division.
109  * Get the coefficient first, and multiply (potentially huge) base
110  * experience point of a monster later.
111  * </pre>
112  */
113 static void get_exp_from_mon(HIT_POINT dam, monster_type *m_ptr)
114 {
115         monster_race *r_ptr = &r_info[m_ptr->r_idx];
116
117         s32b new_exp;
118         u32b new_exp_frac;
119         s32b div_h;
120         u32b div_l;
121
122         if (!monster_is_valid(m_ptr)) return;
123         if (is_pet(m_ptr) || p_ptr->phase_out) return;
124
125         /*
126          * - Ratio of monster's level to player's level effects
127          * - Varying speed effects
128          * - Get a fraction in proportion of damage point
129          */
130         new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
131         new_exp_frac = 0;
132         div_h = 0L;
133         div_l = (p_ptr->max_plv + 2) * SPEED_TO_ENERGY(r_ptr->speed);
134
135         /* Use (average maxhp * 2) as a denominator */
136         if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
137                 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
138         else
139                 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
140
141         /* Special penalty in the wilderness */
142         if (!current_floor_ptr->dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
143                 s64b_mul(&div_h, &div_l, 0, 5);
144
145         /* Do division first to prevent overflaw */
146         s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
147
148         /* Special penalty for mutiply-monster */
149         if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
150         {
151                 int monnum_penarty = r_ptr->r_akills / 400;
152                 if (monnum_penarty > 8) monnum_penarty = 8;
153
154                 while (monnum_penarty--)
155                 {
156                         /* Divide by 4 */
157                         s64b_RSHIFT(new_exp, new_exp_frac, 2);
158                 }
159         }
160
161         /* Special penalty for rest_and_shoot exp scum */
162         if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
163         {
164                 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
165                 if (over_damage > 32) over_damage = 32;
166
167                 while (over_damage--)
168                 {
169                         /* 9/10 for once */
170                         s64b_mul(&new_exp, &new_exp_frac, 0, 9);
171                         s64b_div(&new_exp, &new_exp_frac, 0, 10);
172                 }
173         }
174
175         /* Finally multiply base experience point of the monster */
176         s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
177
178         gain_exp_64(p_ptr, new_exp, new_exp_frac);
179 }
180
181
182
183 /*!
184 * @brief モンスターの時限ステータスを取得する
185 * @return m_idx モンスターの参照ID
186 * @return mproc_type モンスターの時限ステータスID
187 * @return 残りターン値
188 */
189 int get_mproc_idx(MONSTER_IDX m_idx, int mproc_type)
190 {
191         s16b *cur_mproc_list = current_floor_ptr->mproc_list[mproc_type];
192         int i;
193
194         for (i = current_floor_ptr->mproc_max[mproc_type] - 1; i >= 0; i--)
195         {
196                 if (cur_mproc_list[i] == m_idx) return i;
197         }
198
199         return -1;
200 }
201
202 /*!
203 * @brief モンスターの時限ステータスリストを追加する
204 * @return m_idx モンスターの参照ID
205 * @return mproc_type 追加したいモンスターの時限ステータスID
206 * @return なし
207 */
208 static void mproc_add(MONSTER_IDX m_idx, int mproc_type)
209 {
210         if (current_floor_ptr->mproc_max[mproc_type] < current_floor_ptr->max_m_idx) current_floor_ptr->mproc_list[mproc_type][current_floor_ptr->mproc_max[mproc_type]++] = (s16b)m_idx;
211 }
212
213
214 /*!
215 * @brief モンスターの時限ステータスリストを削除
216 * @return m_idx モンスターの参照ID
217 * @return mproc_type 削除したいモンスターの時限ステータスID
218 * @return なし
219 */
220 static void mproc_remove(MONSTER_IDX m_idx, int mproc_type)
221 {
222         int mproc_idx = get_mproc_idx(m_idx, mproc_type);
223         if (mproc_idx >= 0) current_floor_ptr->mproc_list[mproc_type][mproc_idx] = current_floor_ptr->mproc_list[mproc_type][--current_floor_ptr->mproc_max[mproc_type]];
224 }
225
226
227 /*!
228 * @brief モンスターの時限ステータスリストを初期化する / Initialize monster process
229 * @return なし
230 */
231 void mproc_init(void)
232 {
233         monster_type *m_ptr;
234         MONSTER_IDX i;
235         int cmi;
236
237         /* Reset "current_floor_ptr->mproc_max[]" */
238         for (cmi = 0; cmi < MAX_MTIMED; cmi++) current_floor_ptr->mproc_max[cmi] = 0;
239
240         /* Process the monsters (backwards) */
241         for (i = current_floor_ptr->m_max - 1; i >= 1; i--)
242         {
243                 m_ptr = &current_floor_ptr->m_list[i];
244
245                 /* Ignore "dead" monsters */
246                 if (!monster_is_valid(m_ptr)) continue;
247
248                 for (cmi = 0; cmi < MAX_MTIMED; cmi++)
249                 {
250                         if (m_ptr->mtimed[cmi]) mproc_add(i, cmi);
251                 }
252         }
253 }
254
255
256 /*!
257 * @brief モンスターの睡眠状態値をセットする。0で起きる。 /
258 * Set "m_ptr->mtimed[MTIMED_CSLEEP]", notice observable changes
259 * @param m_idx モンスター参照ID
260 * @param v セットする値
261 * @return 別途更新処理が必要な場合TRUEを返す
262 */
263 bool set_monster_csleep(MONSTER_IDX m_idx, int v)
264 {
265         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
266         bool notice = FALSE;
267         v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
268
269         if (v)
270         {
271                 if (!MON_CSLEEP(m_ptr))
272                 {
273                         mproc_add(m_idx, MTIMED_CSLEEP);
274                         notice = TRUE;
275                 }
276         }
277
278         else
279         {
280                 if (MON_CSLEEP(m_ptr))
281                 {
282                         mproc_remove(m_idx, MTIMED_CSLEEP);
283                         notice = TRUE;
284                 }
285         }
286
287         /* Use the value */
288         m_ptr->mtimed[MTIMED_CSLEEP] = (s16b)v;
289
290         if (!notice) return FALSE;
291
292         if (m_ptr->ml)
293         {
294                 /* Update health bar as needed */
295                 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
296                 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
297         }
298
299         if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
300
301         return TRUE;
302 }
303
304
305 /*!
306 * @brief モンスターの加速状態値をセット /
307 * Set "m_ptr->mtimed[MTIMED_FAST]", notice observable changes
308 * @param m_idx モンスター参照ID
309 * @param v セットする値
310 * @return 別途更新処理が必要な場合TRUEを返す
311 */
312 bool set_monster_fast(MONSTER_IDX m_idx, int v)
313 {
314         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
315         bool notice = FALSE;
316         v = (v > 200) ? 200 : (v < 0) ? 0 : v;
317
318         if (v)
319         {
320                 if (!MON_FAST(m_ptr))
321                 {
322                         mproc_add(m_idx, MTIMED_FAST);
323                         notice = TRUE;
324                 }
325         }
326
327         else
328         {
329                 if (MON_FAST(m_ptr))
330                 {
331                         mproc_remove(m_idx, MTIMED_FAST);
332                         notice = TRUE;
333                 }
334         }
335
336         /* Use the value */
337         m_ptr->mtimed[MTIMED_FAST] = (s16b)v;
338
339         if (!notice) return FALSE;
340
341         if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
342
343         return TRUE;
344 }
345
346
347 /*
348 * Set "m_ptr->mtimed[MTIMED_SLOW]", notice observable changes
349 */
350 bool set_monster_slow(MONSTER_IDX m_idx, int v)
351 {
352         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
353         bool notice = FALSE;
354         v = (v > 200) ? 200 : (v < 0) ? 0 : v;
355
356         if (v)
357         {
358                 if (!MON_SLOW(m_ptr))
359                 {
360                         mproc_add(m_idx, MTIMED_SLOW);
361                         notice = TRUE;
362                 }
363         }
364
365         else
366         {
367                 if (MON_SLOW(m_ptr))
368                 {
369                         mproc_remove(m_idx, MTIMED_SLOW);
370                         notice = TRUE;
371                 }
372         }
373
374         /* Use the value */
375         m_ptr->mtimed[MTIMED_SLOW] = (s16b)v;
376
377         if (!notice) return FALSE;
378
379         if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
380
381         return TRUE;
382 }
383
384
385 /*!
386 * @brief モンスターの朦朧状態値をセット /
387 * Set "m_ptr->mtimed[MTIMED_STUNNED]", notice observable changes
388 * @param m_idx モンスター参照ID
389 * @param v セットする値
390 * @return 別途更新処理が必要な場合TRUEを返す
391 */
392 bool set_monster_stunned(MONSTER_IDX m_idx, int v)
393 {
394         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
395         bool notice = FALSE;
396         v = (v > 200) ? 200 : (v < 0) ? 0 : v;
397
398         if (v)
399         {
400                 if (!MON_STUNNED(m_ptr))
401                 {
402                         mproc_add(m_idx, MTIMED_STUNNED);
403                         notice = TRUE;
404                 }
405         }
406
407         else
408         {
409                 if (MON_STUNNED(m_ptr))
410                 {
411                         mproc_remove(m_idx, MTIMED_STUNNED);
412                         notice = TRUE;
413                 }
414         }
415
416         /* Use the value */
417         m_ptr->mtimed[MTIMED_STUNNED] = (s16b)v;
418
419         return notice;
420 }
421
422
423 /*!
424 * @brief モンスターの混乱状態値をセット /
425 * Set "m_ptr->mtimed[MTIMED_CONFUSED]", notice observable changes
426 * @param m_idx モンスター参照ID
427 * @param v セットする値
428 * @return 別途更新処理が必要な場合TRUEを返す
429 */
430 bool set_monster_confused(MONSTER_IDX m_idx, int v)
431 {
432         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
433         bool notice = FALSE;
434         v = (v > 200) ? 200 : (v < 0) ? 0 : v;
435
436         if (v)
437         {
438                 if (!MON_CONFUSED(m_ptr))
439                 {
440                         mproc_add(m_idx, MTIMED_CONFUSED);
441                         notice = TRUE;
442                 }
443         }
444
445         else
446         {
447                 if (MON_CONFUSED(m_ptr))
448                 {
449                         mproc_remove(m_idx, MTIMED_CONFUSED);
450                         notice = TRUE;
451                 }
452         }
453
454         /* Use the value */
455         m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)v;
456
457         return notice;
458 }
459
460
461 /*!
462 * @brief モンスターの恐慌状態値をセット /
463 * Set "m_ptr->mtimed[MTIMED_MONFEAR]", notice observable changes
464 * @param m_idx モンスター参照ID
465 * @param v セットする値
466 * @return 別途更新処理が必要な場合TRUEを返す
467 */
468 bool set_monster_monfear(MONSTER_IDX m_idx, int v)
469 {
470         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
471         bool notice = FALSE;
472         v = (v > 200) ? 200 : (v < 0) ? 0 : v;
473
474         if (v)
475         {
476                 if (!MON_MONFEAR(m_ptr))
477                 {
478                         mproc_add(m_idx, MTIMED_MONFEAR);
479                         notice = TRUE;
480                 }
481         }
482
483         else
484         {
485                 if (MON_MONFEAR(m_ptr))
486                 {
487                         mproc_remove(m_idx, MTIMED_MONFEAR);
488                         notice = TRUE;
489                 }
490         }
491
492         /* Use the value */
493         m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)v;
494
495         if (!notice) return FALSE;
496
497         if (m_ptr->ml)
498         {
499                 /* Update health bar as needed */
500                 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
501                 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
502         }
503
504         return TRUE;
505 }
506
507
508 /*!
509 * @brief モンスターの無敵状態値をセット /
510 * Set "m_ptr->mtimed[MTIMED_INVULNER]", notice observable changes
511 * @param m_idx モンスター参照ID
512 * @param v セットする値
513 * @param energy_need TRUEならば無敵解除時に行動ターン消費を行う
514 * @return 別途更新処理が必要な場合TRUEを返す
515 */
516 bool set_monster_invulner(MONSTER_IDX m_idx, int v, bool energy_need)
517 {
518         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
519         bool notice = FALSE;
520         v = (v > 200) ? 200 : (v < 0) ? 0 : v;
521
522         if (v)
523         {
524                 if (!MON_INVULNER(m_ptr))
525                 {
526                         mproc_add(m_idx, MTIMED_INVULNER);
527                         notice = TRUE;
528                 }
529         }
530
531         else
532         {
533                 if (MON_INVULNER(m_ptr))
534                 {
535                         mproc_remove(m_idx, MTIMED_INVULNER);
536                         if (energy_need && !p_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
537                         notice = TRUE;
538                 }
539         }
540
541         /* Use the value */
542         m_ptr->mtimed[MTIMED_INVULNER] = (s16b)v;
543
544         if (!notice) return FALSE;
545
546         if (m_ptr->ml)
547         {
548                 /* Update health bar as needed */
549                 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
550                 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
551         }
552
553         return TRUE;
554 }
555
556
557 static u32b csleep_noise;
558
559 /*!
560 * @brief モンスターの各種状態値を時間経過により更新するサブルーチン
561 * @param m_idx モンスター参照ID
562 * @param mtimed_idx 更新するモンスターの時限ステータスID
563 * @return なし
564 */
565 static void process_monsters_mtimed_aux(MONSTER_IDX m_idx, int mtimed_idx)
566 {
567         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
568
569         switch (mtimed_idx)
570         {
571         case MTIMED_CSLEEP:
572         {
573                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
574
575                 /* Assume does not wake up */
576                 bool test = FALSE;
577
578                 /* Hack -- Require proximity */
579                 if (m_ptr->cdis < AAF_LIMIT)
580                 {
581                         /* Handle "sensing radius" */
582                         if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
583                         {
584                                 /* We may wake up */
585                                 test = TRUE;
586                         }
587
588                         /* Handle "sight" and "aggravation" */
589                         else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(m_ptr->fy, m_ptr->fx)))
590                         {
591                                 /* We may wake up */
592                                 test = TRUE;
593                         }
594                 }
595
596                 if (test)
597                 {
598                         u32b notice = randint0(1024);
599
600                         /* Nightmare monsters are more alert */
601                         if (ironman_nightmare) notice /= 2;
602
603                         /* Hack -- See if monster "notices" player */
604                         if ((notice * notice * notice) <= csleep_noise)
605                         {
606                                 /* Hack -- amount of "waking" */
607                                 /* Wake up faster near the player */
608                                 int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
609
610                                 /* Hack -- amount of "waking" is affected by speed of player */
611                                 d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
612                                 if (d < 0) d = 1;
613
614                                 /* Monster wakes up "a little bit" */
615
616                                 /* Still asleep */
617                                 if (!set_monster_csleep(m_idx, MON_CSLEEP(m_ptr) - d))
618                                 {
619                                         /* Notice the "not waking up" */
620                                         if (is_original_ap_and_seen(m_ptr))
621                                         {
622                                                 /* Hack -- Count the ignores */
623                                                 if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++;
624                                         }
625                                 }
626
627                                 /* Just woke up */
628                                 else
629                                 {
630                                         /* Notice the "waking up" */
631                                         if (m_ptr->ml)
632                                         {
633                                                 GAME_TEXT m_name[MAX_NLEN];
634                                                 monster_desc(m_name, m_ptr, 0);
635                                                 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
636                                         }
637
638                                         if (is_original_ap_and_seen(m_ptr))
639                                         {
640                                                 /* Hack -- Count the wakings */
641                                                 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
642                                         }
643                                 }
644                         }
645                 }
646                 break;
647         }
648
649         case MTIMED_FAST:
650                 /* Reduce by one, note if expires */
651                 if (set_monster_fast(m_idx, MON_FAST(m_ptr) - 1))
652                 {
653                         if (is_seen(m_ptr))
654                         {
655                                 GAME_TEXT m_name[MAX_NLEN];
656                                 monster_desc(m_name, m_ptr, 0);
657                                 msg_format(_("%^sはもう加速されていない。", "%^s is no longer fast."), m_name);
658                         }
659                 }
660                 break;
661
662         case MTIMED_SLOW:
663                 /* Reduce by one, note if expires */
664                 if (set_monster_slow(m_idx, MON_SLOW(m_ptr) - 1))
665                 {
666                         if (is_seen(m_ptr))
667                         {
668                                 GAME_TEXT m_name[MAX_NLEN];
669                                 monster_desc(m_name, m_ptr, 0);
670                                 msg_format(_("%^sはもう減速されていない。", "%^s is no longer slow."), m_name);
671                         }
672                 }
673                 break;
674
675         case MTIMED_STUNNED:
676         {
677                 int rlev = r_info[m_ptr->r_idx].level;
678
679                 /* Recover from stun */
680                 if (set_monster_stunned(m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
681                 {
682                         /* Message if visible */
683                         if (is_seen(m_ptr))
684                         {
685                                 GAME_TEXT m_name[MAX_NLEN];
686                                 monster_desc(m_name, m_ptr, 0);
687                                 msg_format(_("%^sは朦朧状態から立ち直った。", "%^s is no longer stunned."), m_name);
688                         }
689                 }
690                 break;
691         }
692
693         case MTIMED_CONFUSED:
694                 /* Reduce the confusion */
695                 if (set_monster_confused(m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
696                 {
697                         /* Message if visible */
698                         if (is_seen(m_ptr))
699                         {
700                                 GAME_TEXT m_name[MAX_NLEN];
701                                 monster_desc(m_name, m_ptr, 0);
702                                 msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name);
703                         }
704                 }
705                 break;
706
707         case MTIMED_MONFEAR:
708                 /* Reduce the fear */
709                 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
710                 {
711                         /* Visual note */
712                         if (is_seen(m_ptr))
713                         {
714                                 GAME_TEXT m_name[MAX_NLEN];
715 #ifndef JP
716                                 char m_poss[80];
717
718                                 /* Acquire the monster possessive */
719                                 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
720 #endif
721                                 monster_desc(m_name, m_ptr, 0);
722 #ifdef JP
723                                 msg_format("%^sは勇気を取り戻した。", m_name);
724 #else
725                                 msg_format("%^s recovers %s courage.", m_name, m_poss);
726 #endif
727                         }
728                 }
729                 break;
730
731         case MTIMED_INVULNER:
732                 /* Reduce by one, note if expires */
733                 if (set_monster_invulner(m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
734                 {
735                         if (is_seen(m_ptr))
736                         {
737                                 GAME_TEXT m_name[MAX_NLEN];
738                                 monster_desc(m_name, m_ptr, 0);
739                                 msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name);
740                         }
741                 }
742                 break;
743         }
744 }
745
746
747 /*!
748 * @brief 全モンスターの各種状態値を時間経過により更新するメインルーチン
749 * @param mtimed_idx 更新するモンスターの時限ステータスID
750 * @return なし
751 * @details
752 * Process the counters of monsters (once per 10 game turns)\n
753 * These functions are to process monsters' counters same as player's.
754 */
755 void process_monsters_mtimed(int mtimed_idx)
756 {
757         int  i;
758         s16b *cur_mproc_list = current_floor_ptr->mproc_list[mtimed_idx];
759
760         /* Hack -- calculate the "player noise" */
761         if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - p_ptr->skill_stl));
762
763         /* Process the monsters (backwards) */
764         for (i = current_floor_ptr->mproc_max[mtimed_idx] - 1; i >= 0; i--)
765         {
766                 process_monsters_mtimed_aux(cur_mproc_list[i], mtimed_idx);
767         }
768 }
769
770 /*!
771 * @brief モンスターへの魔力消去処理
772 * @param m_idx 魔力消去を受けるモンスターの参照ID
773 * @return なし
774 */
775 void dispel_monster_status(MONSTER_IDX m_idx)
776 {
777         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
778         GAME_TEXT m_name[MAX_NLEN];
779
780         monster_desc(m_name, m_ptr, 0);
781         if (set_monster_invulner(m_idx, 0, TRUE))
782         {
783                 if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name);
784         }
785         if (set_monster_fast(m_idx, 0))
786         {
787                 if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name);
788         }
789         if (set_monster_slow(m_idx, 0))
790         {
791                 if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name);
792         }
793 }
794
795 /*!
796 * @brief モンスターの時間停止処理
797 * @param num 時間停止を行った敵が行動できる回数
798 * @param who 時間停止処理の主体ID
799 * @param vs_player TRUEならば時間停止開始処理を行う
800 * @return 時間停止が行われている状態ならばTRUEを返す
801 */
802 bool set_monster_timewalk(int num, MONSTER_IDX who, bool vs_player)
803 {
804         monster_type *m_ptr = &current_floor_ptr->m_list[hack_m_idx];  /* the world monster */
805
806         if (current_world_ptr->timewalk_m_idx) return (FALSE);
807
808         if (vs_player)
809         {
810                 GAME_TEXT m_name[MAX_NLEN];
811                 monster_desc(m_name, m_ptr, 0);
812
813                 if (who == 1)
814                         msg_format(_("「『ザ・ワールド』!時は止まった!」", "%s yells 'The World! Time has stopped!'"), m_name);
815                 else if (who == 3)
816                         msg_format(_("「時よ!」", "%s yells 'Time!'"), m_name);
817                 else msg_print("hek!");
818
819                 msg_print(NULL);
820         }
821
822         /* This monster cast spells */
823         current_world_ptr->timewalk_m_idx = hack_m_idx;
824
825         if (vs_player) do_cmd_redraw(p_ptr);
826
827         while (num--)
828         {
829                 if (!monster_is_valid(m_ptr)) break;
830                 process_monster(current_world_ptr->timewalk_m_idx);
831                 reset_target(m_ptr);
832                 handle_stuff();
833
834                 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
835         }
836
837         p_ptr->redraw |= (PR_MAP);
838         p_ptr->update |= (PU_MONSTERS);
839         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
840
841         current_world_ptr->timewalk_m_idx = 0;
842         if (vs_player || (player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)))
843         {
844                 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
845                 msg_print(NULL);
846         }
847
848         handle_stuff();
849         return (TRUE);
850 }
851
852 /*!
853 * @brief モンスターの経験値取得処理
854 * @param m_idx 経験値を得るモンスターの参照ID
855 * @param s_idx 撃破されたモンスター種族の参照ID
856 * @return なし
857 */
858 void monster_gain_exp(MONSTER_IDX m_idx, MONRACE_IDX s_idx)
859 {
860         monster_type *m_ptr;
861         monster_race *r_ptr;
862         monster_race *s_ptr;
863         int new_exp;
864         if (m_idx <= 0 || s_idx <= 0) return;
865
866         m_ptr = &current_floor_ptr->m_list[m_idx];
867
868         if (!monster_is_valid(m_ptr)) return;
869
870         r_ptr = &r_info[m_ptr->r_idx];
871         s_ptr = &r_info[s_idx];
872
873         if (p_ptr->phase_out) return;
874
875         if (!r_ptr->next_exp) return;
876
877         new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
878         if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
879         if (!current_floor_ptr->dun_level) new_exp /= 5;
880         m_ptr->exp += new_exp;
881         if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
882
883         if (m_ptr->exp >= r_ptr->next_exp)
884         {
885                 GAME_TEXT m_name[MAX_NLEN];
886                 int old_hp = m_ptr->hp;
887                 int old_maxhp = m_ptr->max_maxhp;
888                 int old_r_idx = m_ptr->r_idx;
889                 byte old_sub_align = m_ptr->sub_align;
890
891                 /* Hack -- Reduce the racial counter of previous monster */
892                 real_r_ptr(m_ptr)->cur_num--;
893
894                 monster_desc(m_name, m_ptr, 0);
895                 m_ptr->r_idx = r_ptr->next_r_idx;
896
897                 /* Count the monsters on the level */
898                 real_r_ptr(m_ptr)->cur_num++;
899
900                 m_ptr->ap_r_idx = m_ptr->r_idx;
901                 r_ptr = &r_info[m_ptr->r_idx];
902
903                 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
904                 {
905                         m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
906                 }
907                 else
908                 {
909                         m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
910                 }
911                 if (ironman_nightmare)
912                 {
913                         HIT_POINT hp = m_ptr->max_maxhp * 2L;
914                         m_ptr->max_maxhp = MIN(30000, hp);
915                 }
916                 m_ptr->maxhp = m_ptr->max_maxhp;
917                 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
918
919                 /* dealt damage is 0 at initial*/
920                 m_ptr->dealt_damage = 0;
921
922                 /* Extract the monster base speed */
923                 m_ptr->mspeed = get_mspeed(r_ptr);
924
925                 /* Sub-alignment of a monster */
926                 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
927                         m_ptr->sub_align = old_sub_align;
928                 else
929                 {
930                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
931                         if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
932                         if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
933                 }
934
935                 m_ptr->exp = 0;
936
937                 if (is_pet(m_ptr) || m_ptr->ml)
938                 {
939                         if (!ignore_unview || player_can_see_bold(m_ptr->fy, m_ptr->fx))
940                         {
941                                 if (p_ptr->image)
942                                 {
943                                         monster_race *hallu_race;
944
945                                         do
946                                         {
947                                                 hallu_race = &r_info[randint1(max_r_idx - 1)];
948                                         } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
949                                         msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name);
950                                 }
951                                 else
952                                 {
953                                         msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name);
954                                 }
955                         }
956
957                         if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
958
959                         /* Now you feel very close to this pet. */
960                         m_ptr->parent_m_idx = 0;
961                 }
962                 update_monster(m_idx, FALSE);
963                 lite_spot(m_ptr->fy, m_ptr->fx);
964         }
965         if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;
966 }
967
968 /*!
969  * @brief モンスターのHPをダメージに応じて減算する /
970  * Decreases monsters hit points, handling monster death.
971  * @param dam 与えたダメージ量
972  * @param m_idx ダメージを与えたモンスターのID
973  * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
974  * @param note モンスターが倒された際の特別なメッセージ述語
975  * @return なし
976  * @details
977  * <pre>
978  * We return TRUE if the monster has been killed (and deleted).
979  * We announce monster death (using an optional "death message"
980  * if given, and a otherwise a generic killed/destroyed message).
981  * Only "physical attacks" can induce the "You have slain" message.
982  * Missile and Spell attacks will induce the "dies" message, or
983  * various "specialized" messages.  Note that "You have destroyed"
984  * and "is destroyed" are synonyms for "You have slain" and "dies".
985  * Hack -- unseen monsters yield "You have killed it." message.
986  * Added fear (DGK) and check whether to print fear messages -CWS
987  * Made name, sex, and capitalization generic -BEN-
988  * As always, the "ghost" processing is a total hack.
989  * Hack -- we "delay" fear messages by passing around a "fear" flag.
990  * Consider decreasing monster experience over time, say,
991  * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
992  * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
993  * monster worth more than subsequent monsters.  This would also need
994  * to induce changes in the monster recall code.
995  * </pre>
996  */
997 bool mon_take_hit(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
998 {
999         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
1000         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1001         monster_type exp_mon;
1002
1003         /* Innocent until proven otherwise */
1004         bool innocent = TRUE, thief = FALSE;
1005         int i;
1006         HIT_POINT expdam;
1007
1008         (void)COPY(&exp_mon, m_ptr, monster_type);
1009
1010         expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
1011
1012         get_exp_from_mon(expdam, &exp_mon);
1013
1014         /* Genocided by chaos patron */
1015         if (!monster_is_valid(m_ptr)) m_idx = 0;
1016
1017         /* Redraw (later) if needed */
1018         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1019         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1020
1021         (void)set_monster_csleep(m_idx, 0);
1022
1023         /* Hack - Cancel any special player stealth magics. -LM- */
1024         if (p_ptr->special_defense & NINJA_S_STEALTH)
1025         {
1026                 set_superstealth(p_ptr, FALSE);
1027         }
1028
1029         /* Genocided by chaos patron */
1030         if (!m_idx) return TRUE;
1031
1032         m_ptr->hp -= dam;
1033         m_ptr->dealt_damage += dam;
1034
1035         if (m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
1036
1037         if (current_world_ptr->wizard)
1038         {
1039                 msg_format(_("合計%d/%dのダメージを与えた。", "You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
1040         }
1041
1042         /* It is dead now */
1043         if (m_ptr->hp < 0)
1044         {
1045                 GAME_TEXT m_name[MAX_NLEN];
1046
1047                 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1048                 {
1049                         /* You might have unmasked Tanuki first time */
1050                         r_ptr = &r_info[m_ptr->r_idx];
1051                         m_ptr->ap_r_idx = m_ptr->r_idx;
1052                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1053                 }
1054
1055                 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1056                 {
1057                         /* You might have unmasked Chameleon first time */
1058                         r_ptr = real_r_ptr(m_ptr);
1059                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1060                 }
1061
1062                 if (!(m_ptr->smart & SM_CLONED))
1063                 {
1064                         /* When the player kills a Unique, it stays dead */
1065                         if (r_ptr->flags1 & RF1_UNIQUE)
1066                         {
1067                                 r_ptr->max_num = 0;
1068
1069                                 /* Mega-Hack -- Banor & Lupart */
1070                                 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1071                                 {
1072                                         r_info[MON_BANORLUPART].max_num = 0;
1073                                         r_info[MON_BANORLUPART].r_pkills++;
1074                                         r_info[MON_BANORLUPART].r_akills++;
1075                                         if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1076                                 }
1077                                 else if (m_ptr->r_idx == MON_BANORLUPART)
1078                                 {
1079                                         r_info[MON_BANOR].max_num = 0;
1080                                         r_info[MON_BANOR].r_pkills++;
1081                                         r_info[MON_BANOR].r_akills++;
1082                                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1083                                         r_info[MON_LUPART].max_num = 0;
1084                                         r_info[MON_LUPART].r_pkills++;
1085                                         r_info[MON_LUPART].r_akills++;
1086                                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1087                                 }
1088                         }
1089
1090                         /* When the player kills a Nazgul, it stays dead */
1091                         else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1092                 }
1093
1094                 /* Count all monsters killed */
1095                 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1096
1097                 /* Recall even invisible uniques or winners */
1098                 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1099                 {
1100                         /* Count kills this life */
1101                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1102                         else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1103
1104                         /* Count kills in all lives */
1105                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1106                         else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1107
1108                         /* Hack -- Auto-recall */
1109                         monster_race_track(m_ptr->ap_r_idx);
1110                 }
1111
1112                 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1113
1114                 /* Don't kill Amberites */
1115                 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1116                 {
1117                         int curses = 1 + randint1(3);
1118                         bool stop_ty = FALSE;
1119                         int count = 0;
1120
1121                         msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
1122                         curse_equipment(100, 50);
1123
1124                         do
1125                         {
1126                                 stop_ty = activate_ty_curse(stop_ty, &count);
1127                         } while (--curses);
1128                 }
1129
1130                 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1131                 {
1132                         char line_got[1024];
1133                         if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
1134                         {
1135                                 msg_format("%^s %s", m_name, line_got);
1136                         }
1137
1138 #ifdef WORLD_SCORE
1139                         if (m_ptr->r_idx == MON_SERPENT)
1140                         {
1141                                 screen_dump = make_screen_dump();
1142                         }
1143 #endif
1144                 }
1145
1146                 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1147                 {
1148                         if (!current_floor_ptr->dun_level && !p_ptr->ambush_flag && !p_ptr->inside_arena)
1149                         {
1150                                 chg_virtue(p_ptr, V_VALOUR, -1);
1151                         }
1152                         else if (r_ptr->level > current_floor_ptr->dun_level)
1153                         {
1154                                 if (randint1(10) <= (r_ptr->level - current_floor_ptr->dun_level))
1155                                         chg_virtue(p_ptr, V_VALOUR, 1);
1156                         }
1157                         if (r_ptr->level > 60)
1158                         {
1159                                 chg_virtue(p_ptr, V_VALOUR, 1);
1160                         }
1161                         if (r_ptr->level >= 2 * (p_ptr->lev + 1))
1162                                 chg_virtue(p_ptr, V_VALOUR, 2);
1163                 }
1164
1165                 if (r_ptr->flags1 & RF1_UNIQUE)
1166                 {
1167                         if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(p_ptr, V_HARMONY, 2);
1168
1169                         if (r_ptr->flags3 & RF3_GOOD)
1170                         {
1171                                 chg_virtue(p_ptr, V_UNLIFE, 2);
1172                                 chg_virtue(p_ptr, V_VITALITY, -2);
1173                         }
1174
1175                         if (one_in_(3)) chg_virtue(p_ptr, V_INDIVIDUALISM, -1);
1176                 }
1177
1178                 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1179                 {
1180                         chg_virtue(p_ptr, V_COMPASSION, -1);
1181                 }
1182
1183                 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100)))
1184                         chg_virtue(p_ptr, V_UNLIFE, 1);
1185
1186                 if (r_ptr->d_char == 'A')
1187                 {
1188                         if (r_ptr->flags1 & RF1_UNIQUE)
1189                                 chg_virtue(p_ptr, V_FAITH, -2);
1190                         else if ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100))
1191                         {
1192                                 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(p_ptr, V_FAITH, -1);
1193                                 else chg_virtue(p_ptr, V_FAITH, 1);
1194                         }
1195                 }
1196                 else if (r_ptr->flags3 & RF3_DEMON)
1197                 {
1198                         if (r_ptr->flags1 & RF1_UNIQUE)
1199                                 chg_virtue(p_ptr, V_FAITH, 2);
1200                         else if ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100))
1201                                 chg_virtue(p_ptr, V_FAITH, 1);
1202                 }
1203
1204                 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1205                         chg_virtue(p_ptr, V_VITALITY, 2);
1206
1207                 if (r_ptr->r_deaths)
1208                 {
1209                         if (r_ptr->flags1 & RF1_UNIQUE)
1210                         {
1211                                 chg_virtue(p_ptr, V_HONOUR, 10);
1212                         }
1213                         else if ((r_ptr->level) / 10 + (2 * current_floor_ptr->dun_level) >= randint1(100))
1214                         {
1215                                 chg_virtue(p_ptr, V_HONOUR, 1);
1216                         }
1217                 }
1218                 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1219                 {
1220                         chg_virtue(p_ptr, V_VALOUR, -1);
1221                 }
1222
1223                 for (i = 0; i < 4; i++)
1224                 {
1225                         if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1226
1227                         if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1228                                 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1229
1230                                 thief = TRUE; /* Thief! */
1231                 }
1232
1233                 /* The new law says it is illegal to live in the dungeon */
1234                 if (r_ptr->level != 0) innocent = FALSE;
1235
1236                 if (thief)
1237                 {
1238                         if (r_ptr->flags1 & RF1_UNIQUE)
1239                                 chg_virtue(p_ptr, V_JUSTICE, 3);
1240                         else if (1 + ((r_ptr->level) / 10 + (2 * current_floor_ptr->dun_level)) >= randint1(100))
1241                                 chg_virtue(p_ptr, V_JUSTICE, 1);
1242                 }
1243                 else if (innocent)
1244                 {
1245                         chg_virtue(p_ptr, V_JUSTICE, -1);
1246                 }
1247
1248                 if ((r_ptr->flags3 & RF3_ANIMAL) && !(r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags4 & ~(RF4_NOMAGIC_MASK)) && !(r_ptr->a_ability_flags1 & ~(RF5_NOMAGIC_MASK)) && !(r_ptr->a_ability_flags2 & ~(RF6_NOMAGIC_MASK)))
1249                 {
1250                         if (one_in_(4)) chg_virtue(p_ptr, V_NATURE, -1);
1251                 }
1252
1253                 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1254                 {
1255                         char note_buf[160];
1256                         sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
1257                         exe_write_diary(p_ptr, NIKKI_UNIQUE, 0, note_buf);
1258                 }
1259
1260                 /* Make a sound */
1261                 sound(SOUND_KILL);
1262
1263                 /* Death by Missile/Spell attack */
1264                 if (note)
1265                 {
1266                         msg_format("%^s%s", m_name, note);
1267                 }
1268
1269                 /* Death by physical attack -- invisible monster */
1270                 else if (!m_ptr->ml)
1271                 {
1272 #ifdef JP
1273                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (p_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1274                                 msg_format("せっかくだから%sを殺した。", m_name);
1275                         else
1276                                 msg_format("%sを殺した。", m_name);
1277 #else
1278                         msg_format("You have killed %s.", m_name);
1279 #endif
1280
1281                 }
1282
1283                 /* Death by Physical attack -- non-living monster */
1284                 else if (!monster_living(m_ptr->r_idx))
1285                 {
1286                         bool explode = FALSE;
1287
1288                         for (i = 0; i < 4; i++)
1289                         {
1290                                 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1291                         }
1292
1293                         /* Special note at death */
1294                         if (explode)
1295                                 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
1296                         else
1297                         {
1298 #ifdef JP
1299                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (p_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1300                                         msg_format("せっかくだから%sを倒した。", m_name);
1301                                 else
1302                                         msg_format("%sを倒した。", m_name);
1303 #else
1304                                 msg_format("You have destroyed %s.", m_name);
1305 #endif
1306                         }
1307                 }
1308
1309                 /* Death by Physical attack -- living monster */
1310                 else
1311                 {
1312 #ifdef JP
1313                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (p_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1314                                 msg_format("せっかくだから%sを葬り去った。", m_name);
1315                         else
1316                                 msg_format("%sを葬り去った。", m_name);
1317 #else
1318                         msg_format("You have slain %s.", m_name);
1319 #endif
1320
1321                 }
1322                 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
1323                 {
1324                         for (i = 0; i < MAX_KUBI; i++)
1325                         {
1326                                 if ((current_world_ptr->bounty_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
1327                                 {
1328                                         msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1329                                         break;
1330                                 }
1331                         }
1332                 }
1333
1334                 /* Generate treasure */
1335                 monster_death(m_idx, TRUE);
1336
1337                 /* Mega hack : replace IKETA to BIKETAL */
1338                 if ((m_ptr->r_idx == MON_IKETA) && !(p_ptr->inside_arena || p_ptr->phase_out))
1339                 {
1340                         POSITION dummy_y = m_ptr->fy;
1341                         POSITION dummy_x = m_ptr->fx;
1342                         BIT_FLAGS mode = 0L;
1343                         if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1344                         delete_monster_idx(m_idx);
1345                         if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1346                         {
1347                                 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha!  *I* am Biketal!"));
1348                         }
1349                 }
1350                 else
1351                 {
1352                         delete_monster_idx(m_idx);
1353                 }
1354
1355                 get_exp_from_mon((long)exp_mon.max_maxhp * 2, &exp_mon);
1356
1357                 /* Not afraid */
1358                 (*fear) = FALSE;
1359
1360                 /* Monster is dead */
1361                 return (TRUE);
1362         }
1363
1364
1365 #ifdef ALLOW_FEAR
1366
1367         /* Mega-Hack -- Pain cancels fear */
1368         if (MON_MONFEAR(m_ptr) && (dam > 0))
1369         {
1370                 /* Cure fear */
1371                 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1372                 {
1373                         /* No more fear */
1374                         (*fear) = FALSE;
1375                 }
1376         }
1377
1378         /* Sometimes a monster gets scared by damage */
1379         if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1380         {
1381                 /* Percentage of fully healthy */
1382                 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1383
1384                 /*
1385                  * Run (sometimes) if at 10% or less of max hit points,
1386                  * or (usually) when hit for half its current hit points
1387                  */
1388                 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1389                 {
1390                         /* Hack -- note fear */
1391                         (*fear) = TRUE;
1392
1393                         /* Hack -- Add some timed fear */
1394                         (void)set_monster_monfear(m_idx, (randint1(10) +
1395                                 (((dam >= m_ptr->hp) && (percentage > 7)) ?
1396                                         20 : ((11 - percentage) * 5))));
1397                 }
1398         }
1399
1400 #endif
1401
1402         /* Not dead yet */
1403         return (FALSE);
1404 }
1405
1406 bool monster_is_valid(monster_type *m_ptr)
1407 {
1408         return (m_ptr->r_idx != 0);
1409 }