OSDN Git Service

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