OSDN Git Service

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