OSDN Git Service

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