OSDN Git Service

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