OSDN Git Service

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