OSDN Git Service

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