OSDN Git Service

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