OSDN Git Service

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