OSDN Git Service

[Fix] #38997 前回マージ後の英語版ビルドエラーを修正. / Fixed English build error after previous merge.
[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(target_ptr, 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(target_ptr, m_name, m_ptr, 0);
662                         msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
663                 }
664
665                 if (is_original_ap_and_seen(target_ptr, 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(target_ptr, 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(target_ptr, 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(target_ptr, 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(target_ptr, 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 #ifndef JP
748                         char m_poss[80];
749
750                         /* Acquire the monster possessive */
751                         monster_desc(target_ptr, m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
752 #endif
753                         monster_desc(target_ptr, m_name, m_ptr, 0);
754 #ifdef JP
755                         msg_format("%^sは勇気を取り戻した。", m_name);
756 #else
757                         msg_format("%^s recovers %s courage.", m_name, m_poss);
758 #endif
759                 }
760
761                 break;
762         }
763
764         case MTIMED_INVULNER:
765         {
766                 /* Reduce by one, note if expires */
767                 if (!set_monster_invulner(target_ptr, m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
768                         break;
769
770                 if (is_seen(m_ptr))
771                 {
772                         GAME_TEXT m_name[MAX_NLEN];
773                         monster_desc(target_ptr, m_name, m_ptr, 0);
774                         msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name);
775                 }
776
777                 break;
778         }
779         }
780 }
781
782
783 /*!
784 * @brief 全モンスターの各種状態値を時間経過により更新するメインルーチン
785 * @param mtimed_idx 更新するモンスターの時限ステータスID
786 * @param target_ptr プレーヤーへの参照ポインタ
787 * @return なし
788 * @details
789 * Process the counters of monsters (once per 10 game turns)\n
790 * These functions are to process monsters' counters same as player's.
791 */
792 void process_monsters_mtimed(player_type *target_ptr, int mtimed_idx)
793 {
794         floor_type *floor_ptr = target_ptr->current_floor_ptr;
795         s16b *cur_mproc_list = floor_ptr->mproc_list[mtimed_idx];
796
797         /* Hack -- calculate the "player noise" */
798         if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - target_ptr->skill_stl));
799
800         /* Process the monsters (backwards) */
801         for (int i = floor_ptr->mproc_max[mtimed_idx] - 1; i >= 0; i--)
802         {
803                 process_monsters_mtimed_aux(target_ptr, cur_mproc_list[i], mtimed_idx);
804         }
805 }
806
807
808 /*!
809 * @brief モンスターへの魔力消去処理
810 * @param target_ptr プレーヤーへの参照ポインタ
811 * @param m_idx 魔力消去を受けるモンスターの参照ID
812 * @return なし
813 */
814 void dispel_monster_status(player_type *target_ptr, MONSTER_IDX m_idx)
815 {
816         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
817         GAME_TEXT m_name[MAX_NLEN];
818
819         monster_desc(target_ptr, m_name, m_ptr, 0);
820         if (set_monster_invulner(target_ptr, m_idx, 0, TRUE))
821         {
822                 if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name);
823         }
824
825         if (set_monster_fast(target_ptr, m_idx, 0))
826         {
827                 if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name);
828         }
829
830         if (set_monster_slow(target_ptr, m_idx, 0))
831         {
832                 if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name);
833         }
834 }
835
836
837 /*!
838 * @brief モンスターの時間停止処理
839 * @param target_ptr プレーヤーへの参照ポインタ
840 * @param num 時間停止を行った敵が行動できる回数
841 * @param who 時間停止処理の主体ID
842 * @param vs_player TRUEならば時間停止開始処理を行う
843 * @return 時間停止が行われている状態ならばTRUEを返す
844 */
845 bool set_monster_timewalk(player_type *target_ptr, int num, MONSTER_IDX who, bool vs_player)
846 {
847         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[hack_m_idx];  /* the world monster */
848
849         if (current_world_ptr->timewalk_m_idx) return FALSE;
850
851         if (vs_player)
852         {
853                 GAME_TEXT m_name[MAX_NLEN];
854                 monster_desc(target_ptr, m_name, m_ptr, 0);
855
856                 if (who == 1)
857                         msg_format(_("「『ザ・ワールド』!時は止まった!」", "%s yells 'The World! Time has stopped!'"), m_name);
858                 else if (who == 3)
859                         msg_format(_("「時よ!」", "%s yells 'Time!'"), m_name);
860                 else msg_print("hek!");
861
862                 msg_print(NULL);
863         }
864
865         /* This monster cast spells */
866         current_world_ptr->timewalk_m_idx = hack_m_idx;
867
868         if (vs_player) do_cmd_redraw(target_ptr);
869
870         while (num--)
871         {
872                 if (!monster_is_valid(m_ptr)) break;
873                 process_monster(target_ptr, current_world_ptr->timewalk_m_idx);
874                 reset_target(m_ptr);
875                 handle_stuff(target_ptr);
876
877                 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
878         }
879
880         target_ptr->redraw |= (PR_MAP);
881         target_ptr->update |= (PU_MONSTERS);
882         target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
883
884         current_world_ptr->timewalk_m_idx = 0;
885         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)))
886         {
887                 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
888                 msg_print(NULL);
889         }
890
891         handle_stuff(target_ptr);
892         return TRUE;
893 }
894
895 /*!
896 * @brief モンスターの経験値取得処理
897 * @param target_ptr プレーヤーへの参照ポインタ
898 * @param m_idx 経験値を得るモンスターの参照ID
899 * @param s_idx 撃破されたモンスター種族の参照ID
900 * @return なし
901 */
902 void monster_gain_exp(player_type *target_ptr, MONSTER_IDX m_idx, MONRACE_IDX s_idx)
903 {
904         monster_type *m_ptr;
905         monster_race *r_ptr;
906         monster_race *s_ptr;
907         if (m_idx <= 0 || s_idx <= 0) return;
908
909         floor_type *floor_ptr = target_ptr->current_floor_ptr;
910         m_ptr = &floor_ptr->m_list[m_idx];
911
912         if (!monster_is_valid(m_ptr)) return;
913
914         r_ptr = &r_info[m_ptr->r_idx];
915         s_ptr = &r_info[s_idx];
916
917         if (target_ptr->phase_out) return;
918
919         if (!r_ptr->next_exp) return;
920
921         int new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
922         if (m_idx == target_ptr->riding) new_exp = (new_exp + 1) / 2;
923         if (!floor_ptr->dun_level) new_exp /= 5;
924         m_ptr->exp += new_exp;
925         if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
926
927         if (m_ptr->exp < r_ptr->next_exp)
928         {
929                 if (m_idx == target_ptr->riding) target_ptr->update |= PU_BONUS;
930                 return;
931         }
932
933         GAME_TEXT m_name[MAX_NLEN];
934         int old_hp = m_ptr->hp;
935         int old_maxhp = m_ptr->max_maxhp;
936         int old_r_idx = m_ptr->r_idx;
937         byte old_sub_align = m_ptr->sub_align;
938
939         /* Hack -- Reduce the racial counter of previous monster */
940         real_r_ptr(m_ptr)->cur_num--;
941
942         monster_desc(target_ptr, m_name, m_ptr, 0);
943         m_ptr->r_idx = r_ptr->next_r_idx;
944
945         /* Count the monsters on the level */
946         real_r_ptr(m_ptr)->cur_num++;
947
948         m_ptr->ap_r_idx = m_ptr->r_idx;
949         r_ptr = &r_info[m_ptr->r_idx];
950
951         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
952         {
953                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
954         }
955         else
956         {
957                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
958         }
959         if (ironman_nightmare)
960         {
961                 HIT_POINT hp = m_ptr->max_maxhp * 2L;
962                 m_ptr->max_maxhp = MIN(30000, hp);
963         }
964
965         m_ptr->maxhp = m_ptr->max_maxhp;
966         m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
967
968         /* dealt damage is 0 at initial*/
969         m_ptr->dealt_damage = 0;
970
971         /* Extract the monster base speed */
972         m_ptr->mspeed = get_mspeed(target_ptr, r_ptr);
973
974         /* Sub-alignment of a monster */
975         if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
976                 m_ptr->sub_align = old_sub_align;
977         else
978         {
979                 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
980                 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
981                 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
982         }
983
984         m_ptr->exp = 0;
985
986         if (is_pet(m_ptr) || m_ptr->ml)
987         {
988                 if (!ignore_unview || player_can_see_bold(target_ptr, m_ptr->fy, m_ptr->fx))
989                 {
990                         if (target_ptr->image)
991                         {
992                                 monster_race *hallu_race;
993
994                                 do
995                                 {
996                                         hallu_race = &r_info[randint1(max_r_idx - 1)];
997                                 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
998                                 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name);
999                         }
1000                         else
1001                         {
1002                                 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name);
1003                         }
1004                 }
1005
1006                 if (!target_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
1007
1008                 /* Now you feel very close to this pet. */
1009                 m_ptr->parent_m_idx = 0;
1010         }
1011
1012         update_monster(target_ptr, m_idx, FALSE);
1013         lite_spot(target_ptr, m_ptr->fy, m_ptr->fx);
1014
1015         if (m_idx == target_ptr->riding) target_ptr->update |= PU_BONUS;
1016 }
1017
1018 /*!
1019  * @brief モンスターのHPをダメージに応じて減算する /
1020  * Decreases monsters hit points, handling monster death.
1021  * @param dam 与えたダメージ量
1022  * @param m_idx ダメージを与えたモンスターのID
1023  * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
1024  * @param note モンスターが倒された際の特別なメッセージ述語
1025  * @return なし
1026  * @details
1027  * <pre>
1028  * We return TRUE if the monster has been killed (and deleted).
1029  * We announce monster death (using an optional "death message"
1030  * if given, and a otherwise a generic killed/destroyed message).
1031  * Only "physical attacks" can induce the "You have slain" message.
1032  * Missile and Spell attacks will induce the "dies" message, or
1033  * various "specialized" messages.  Note that "You have destroyed"
1034  * and "is destroyed" are synonyms for "You have slain" and "dies".
1035  * Hack -- unseen monsters yield "You have killed it." message.
1036  * Added fear (DGK) and check whether to print fear messages -CWS
1037  * Made name, sex, and capitalization generic -BEN-
1038  * As always, the "ghost" processing is a total hack.
1039  * Hack -- we "delay" fear messages by passing around a "fear" flag.
1040  * Consider decreasing monster experience over time, say,
1041  * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
1042  * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
1043  * monster worth more than subsequent monsters.  This would also need
1044  * to induce changes in the monster recall code.
1045  * </pre>
1046  */
1047 bool mon_take_hit(player_type *target_ptr, MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
1048 {
1049         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1050         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1051         monster_type exp_mon;
1052
1053         /* Innocent until proven otherwise */
1054         bool innocent = TRUE, thief = FALSE;
1055         int i;
1056         HIT_POINT expdam;
1057
1058         (void)COPY(&exp_mon, m_ptr, monster_type);
1059
1060         expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
1061
1062         get_exp_from_mon(target_ptr, expdam, &exp_mon);
1063
1064         /* Genocided by chaos patron */
1065         if (!monster_is_valid(m_ptr)) m_idx = 0;
1066
1067         /* Redraw (later) if needed */
1068         if (target_ptr->health_who == m_idx) target_ptr->redraw |= (PR_HEALTH);
1069         if (target_ptr->riding == m_idx) target_ptr->redraw |= (PR_UHEALTH);
1070
1071         (void)set_monster_csleep(target_ptr, m_idx, 0);
1072
1073         /* Hack - Cancel any special player stealth magics. -LM- */
1074         if (target_ptr->special_defense & NINJA_S_STEALTH)
1075         {
1076                 set_superstealth(target_ptr, FALSE);
1077         }
1078
1079         /* Genocided by chaos patron */
1080         if (!m_idx) return TRUE;
1081
1082         m_ptr->hp -= dam;
1083         m_ptr->dealt_damage += dam;
1084
1085         if (m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
1086
1087         if (current_world_ptr->wizard)
1088         {
1089                 msg_format(_("合計%d/%dのダメージを与えた。", "You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
1090         }
1091
1092         /* It is dead now */
1093         if (m_ptr->hp < 0)
1094         {
1095                 GAME_TEXT m_name[MAX_NLEN];
1096
1097                 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1098                 {
1099                         /* You might have unmasked Tanuki first time */
1100                         r_ptr = &r_info[m_ptr->r_idx];
1101                         m_ptr->ap_r_idx = m_ptr->r_idx;
1102                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1103                 }
1104
1105                 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1106                 {
1107                         /* You might have unmasked Chameleon first time */
1108                         r_ptr = real_r_ptr(m_ptr);
1109                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1110                 }
1111
1112                 if (!(m_ptr->smart & SM_CLONED))
1113                 {
1114                         /* When the player kills a Unique, it stays dead */
1115                         if (r_ptr->flags1 & RF1_UNIQUE)
1116                         {
1117                                 r_ptr->max_num = 0;
1118
1119                                 /* Mega-Hack -- Banor & Lupart */
1120                                 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1121                                 {
1122                                         r_info[MON_BANORLUPART].max_num = 0;
1123                                         r_info[MON_BANORLUPART].r_pkills++;
1124                                         r_info[MON_BANORLUPART].r_akills++;
1125                                         if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1126                                 }
1127                                 else if (m_ptr->r_idx == MON_BANORLUPART)
1128                                 {
1129                                         r_info[MON_BANOR].max_num = 0;
1130                                         r_info[MON_BANOR].r_pkills++;
1131                                         r_info[MON_BANOR].r_akills++;
1132                                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1133                                         r_info[MON_LUPART].max_num = 0;
1134                                         r_info[MON_LUPART].r_pkills++;
1135                                         r_info[MON_LUPART].r_akills++;
1136                                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1137                                 }
1138                         }
1139
1140                         /* When the player kills a Nazgul, it stays dead */
1141                         else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1142                 }
1143
1144                 /* Count all monsters killed */
1145                 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1146
1147                 /* Recall even invisible uniques or winners */
1148                 if ((m_ptr->ml && !target_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1149                 {
1150                         /* Count kills this life */
1151                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1152                         else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1153
1154                         /* Count kills in all lives */
1155                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1156                         else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1157
1158                         /* Hack -- Auto-recall */
1159                         monster_race_track(target_ptr, m_ptr->ap_r_idx);
1160                 }
1161
1162                 monster_desc(target_ptr, m_name, m_ptr, MD_TRUE_NAME);
1163
1164                 /* Don't kill Amberites */
1165                 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1166                 {
1167                         int curses = 1 + randint1(3);
1168                         bool stop_ty = FALSE;
1169                         int count = 0;
1170
1171                         msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
1172                         curse_equipment(target_ptr, 100, 50);
1173
1174                         do
1175                         {
1176                                 stop_ty = activate_ty_curse(target_ptr, stop_ty, &count);
1177                         } while (--curses);
1178                 }
1179
1180                 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1181                 {
1182                         char line_got[1024];
1183                         if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
1184                         {
1185                                 msg_format("%^s %s", m_name, line_got);
1186                         }
1187
1188 #ifdef WORLD_SCORE
1189                         if (m_ptr->r_idx == MON_SERPENT)
1190                         {
1191                                 screen_dump = make_screen_dump(target_ptr);
1192                         }
1193 #endif
1194                 }
1195
1196                 if (!(d_info[target_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1197                 {
1198                         if (!target_ptr->current_floor_ptr->dun_level && !target_ptr->ambush_flag && !target_ptr->current_floor_ptr->inside_arena)
1199                         {
1200                                 chg_virtue(target_ptr, V_VALOUR, -1);
1201                         }
1202                         else if (r_ptr->level > target_ptr->current_floor_ptr->dun_level)
1203                         {
1204                                 if (randint1(10) <= (r_ptr->level - target_ptr->current_floor_ptr->dun_level))
1205                                         chg_virtue(target_ptr, V_VALOUR, 1);
1206                         }
1207                         if (r_ptr->level > 60)
1208                         {
1209                                 chg_virtue(target_ptr, V_VALOUR, 1);
1210                         }
1211                         if (r_ptr->level >= 2 * (target_ptr->lev + 1))
1212                                 chg_virtue(target_ptr, V_VALOUR, 2);
1213                 }
1214
1215                 if (r_ptr->flags1 & RF1_UNIQUE)
1216                 {
1217                         if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(target_ptr, V_HARMONY, 2);
1218
1219                         if (r_ptr->flags3 & RF3_GOOD)
1220                         {
1221                                 chg_virtue(target_ptr, V_UNLIFE, 2);
1222                                 chg_virtue(target_ptr, V_VITALITY, -2);
1223                         }
1224
1225                         if (one_in_(3)) chg_virtue(target_ptr, V_INDIVIDUALISM, -1);
1226                 }
1227
1228                 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1229                 {
1230                         chg_virtue(target_ptr, V_COMPASSION, -1);
1231                 }
1232
1233                 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * target_ptr->current_floor_ptr->dun_level) >= randint1(100)))
1234                         chg_virtue(target_ptr, V_UNLIFE, 1);
1235
1236                 if (r_ptr->d_char == 'A')
1237                 {
1238                         if (r_ptr->flags1 & RF1_UNIQUE)
1239                                 chg_virtue(target_ptr, V_FAITH, -2);
1240                         else if ((r_ptr->level) / 10 + (3 * target_ptr->current_floor_ptr->dun_level) >= randint1(100))
1241                         {
1242                                 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(target_ptr, V_FAITH, -1);
1243                                 else chg_virtue(target_ptr, V_FAITH, 1);
1244                         }
1245                 }
1246                 else if (r_ptr->flags3 & RF3_DEMON)
1247                 {
1248                         if (r_ptr->flags1 & RF1_UNIQUE)
1249                                 chg_virtue(target_ptr, V_FAITH, 2);
1250                         else if ((r_ptr->level) / 10 + (3 * target_ptr->current_floor_ptr->dun_level) >= randint1(100))
1251                                 chg_virtue(target_ptr, V_FAITH, 1);
1252                 }
1253
1254                 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1255                         chg_virtue(target_ptr, V_VITALITY, 2);
1256
1257                 if (r_ptr->r_deaths)
1258                 {
1259                         if (r_ptr->flags1 & RF1_UNIQUE)
1260                         {
1261                                 chg_virtue(target_ptr, V_HONOUR, 10);
1262                         }
1263                         else if ((r_ptr->level) / 10 + (2 * target_ptr->current_floor_ptr->dun_level) >= randint1(100))
1264                         {
1265                                 chg_virtue(target_ptr, V_HONOUR, 1);
1266                         }
1267                 }
1268                 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1269                 {
1270                         chg_virtue(target_ptr, V_VALOUR, -1);
1271                 }
1272
1273                 for (i = 0; i < 4; i++)
1274                 {
1275                         if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1276
1277                         if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1278                                 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1279
1280                                 thief = TRUE; /* Thief! */
1281                 }
1282
1283                 /* The new law says it is illegal to live in the dungeon */
1284                 if (r_ptr->level != 0) innocent = FALSE;
1285
1286                 if (thief)
1287                 {
1288                         if (r_ptr->flags1 & RF1_UNIQUE)
1289                                 chg_virtue(target_ptr, V_JUSTICE, 3);
1290                         else if (1 + ((r_ptr->level) / 10 + (2 * target_ptr->current_floor_ptr->dun_level)) >= randint1(100))
1291                                 chg_virtue(target_ptr, V_JUSTICE, 1);
1292                 }
1293                 else if (innocent)
1294                 {
1295                         chg_virtue(target_ptr, V_JUSTICE, -1);
1296                 }
1297
1298                 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)))
1299                 {
1300                         if (one_in_(4)) chg_virtue(target_ptr, V_NATURE, -1);
1301                 }
1302
1303                 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1304                 {
1305                         char note_buf[160];
1306                         sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
1307                         exe_write_diary(target_ptr, DIARY_UNIQUE, 0, note_buf);
1308                 }
1309
1310                 /* Make a sound */
1311                 sound(SOUND_KILL);
1312
1313                 /* Death by Missile/Spell attack */
1314                 if (note)
1315                 {
1316                         msg_format("%^s%s", m_name, note);
1317                 }
1318
1319                 /* Death by physical attack -- invisible monster */
1320                 else if (!m_ptr->ml)
1321                 {
1322 #ifdef JP
1323                         if ((target_ptr->pseikaku == SEIKAKU_COMBAT) || (target_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1324                                 msg_format("せっかくだから%sを殺した。", m_name);
1325                         else
1326                                 msg_format("%sを殺した。", m_name);
1327 #else
1328                         msg_format("You have killed %s.", m_name);
1329 #endif
1330
1331                 }
1332
1333                 /* Death by Physical attack -- non-living monster */
1334                 else if (!monster_living(m_ptr->r_idx))
1335                 {
1336                         bool explode = FALSE;
1337
1338                         for (i = 0; i < 4; i++)
1339                         {
1340                                 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1341                         }
1342
1343                         /* Special note at death */
1344                         if (explode)
1345                                 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
1346                         else
1347                         {
1348 #ifdef JP
1349                                 if ((target_ptr->pseikaku == SEIKAKU_COMBAT) || (target_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1350                                         msg_format("せっかくだから%sを倒した。", m_name);
1351                                 else
1352                                         msg_format("%sを倒した。", m_name);
1353 #else
1354                                 msg_format("You have destroyed %s.", m_name);
1355 #endif
1356                         }
1357                 }
1358
1359                 /* Death by Physical attack -- living monster */
1360                 else
1361                 {
1362 #ifdef JP
1363                         if ((target_ptr->pseikaku == SEIKAKU_COMBAT) || (target_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1364                                 msg_format("せっかくだから%sを葬り去った。", m_name);
1365                         else
1366                                 msg_format("%sを葬り去った。", m_name);
1367 #else
1368                         msg_format("You have slain %s.", m_name);
1369 #endif
1370
1371                 }
1372                 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
1373                 {
1374                         for (i = 0; i < MAX_BOUNTY; i++)
1375                         {
1376                                 if ((current_world_ptr->bounty_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
1377                                 {
1378                                         msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1379                                         break;
1380                                 }
1381                         }
1382                 }
1383
1384                 /* Generate treasure */
1385                 monster_death(target_ptr, m_idx, TRUE);
1386
1387                 /* Mega hack : replace IKETA to BIKETAL */
1388                 if ((m_ptr->r_idx == MON_IKETA) && !(target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out))
1389                 {
1390                         POSITION dummy_y = m_ptr->fy;
1391                         POSITION dummy_x = m_ptr->fx;
1392                         BIT_FLAGS mode = 0L;
1393                         if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1394                         delete_monster_idx(target_ptr, m_idx);
1395                         if (summon_named_creature(target_ptr, 0, dummy_y, dummy_x, MON_BIKETAL, mode))
1396                         {
1397                                 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha!  *I* am Biketal!"));
1398                         }
1399                 }
1400                 else
1401                 {
1402                         delete_monster_idx(target_ptr, m_idx);
1403                 }
1404
1405                 get_exp_from_mon(target_ptr, (long)exp_mon.max_maxhp * 2, &exp_mon);
1406
1407                 /* Not afraid */
1408                 (*fear) = FALSE;
1409
1410                 /* Monster is dead */
1411                 return TRUE;
1412         }
1413
1414 #ifdef ALLOW_FEAR
1415
1416         /* Mega-Hack -- Pain cancels fear */
1417         if (MON_MONFEAR(m_ptr) && (dam > 0))
1418         {
1419                 /* Cure fear */
1420                 if (set_monster_monfear(target_ptr, m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1421                 {
1422                         /* No more fear */
1423                         (*fear) = FALSE;
1424                 }
1425         }
1426
1427         /* Sometimes a monster gets scared by damage */
1428         if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1429         {
1430                 /* Percentage of fully healthy */
1431                 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1432
1433                 /*
1434                  * Run (sometimes) if at 10% or less of max hit points,
1435                  * or (usually) when hit for half its current hit points
1436                  */
1437                 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1438                 {
1439                         /* Hack -- note fear */
1440                         (*fear) = TRUE;
1441
1442                         /* Hack -- Add some timed fear */
1443                         (void)set_monster_monfear(target_ptr, m_idx, (randint1(10) +
1444                                 (((dam >= m_ptr->hp) && (percentage > 7)) ?
1445                                         20 : ((11 - percentage) * 5))));
1446                 }
1447         }
1448
1449 #endif
1450
1451         /* Not dead yet */
1452         return FALSE;
1453 }
1454
1455 bool monster_is_valid(monster_type *m_ptr)
1456 {
1457         return (m_ptr->r_idx != 0);
1458 }