3 #include "monster-status.h"
4 #include "monster-spell.h"
5 #include "spells-summon.h"
6 #include "monsterrace-hook.h"
7 #include "object-curse.h"
14 * @brief モンスターに与えたダメージの修正処理 /
15 * Modify the physical damage done to the monster.
16 * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
18 * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
19 * @return 修正を行った結果のダメージ量
22 * (for example when it's invulnerable or shielded)
23 * ToDo: Accept a damage-type to calculate the modified damage from
24 * things like fire, frost, lightning, poison, ... attacks.
25 * "type" is not yet used and should be 0.
28 HIT_POINT mon_damage_mod(monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
30 monster_race *r_ptr = &r_info[m_ptr->r_idx];
32 if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
35 if ((dam == 0) && one_in_(3)) dam = 1;
38 if (MON_INVULNER(m_ptr))
42 if (!p_ptr->blind && is_seen(m_ptr))
44 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
47 else if (!one_in_(PENETRATE_INVULNERABILITY))
58 * @brief モンスターに与えたダメージを元に経験値を加算する /
59 * Calculate experience point to be get
61 * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
65 * Even the 64 bit operation is not big enough to avoid overflaw
66 * unless we carefully choose orders of multiplication and division.
67 * Get the coefficient first, and multiply (potentially huge) base
68 * experience point of a monster later.
71 static void get_exp_from_mon(HIT_POINT dam, monster_type *m_ptr)
73 monster_race *r_ptr = &r_info[m_ptr->r_idx];
80 if (!monster_is_valid(m_ptr)) return;
81 if (is_pet(m_ptr) || p_ptr->inside_battle) return;
84 * - Ratio of monster's level to player's level effects
85 * - Varying speed effects
86 * - Get a fraction in proportion of damage point
88 new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
91 div_l = (p_ptr->max_plv + 2) * SPEED_TO_ENERGY(r_ptr->speed);
93 /* Use (average maxhp * 2) as a denominator */
94 if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
95 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
97 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
99 /* Special penalty in the wilderness */
100 if (!current_floor_ptr->dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
101 s64b_mul(&div_h, &div_l, 0, 5);
103 /* Do division first to prevent overflaw */
104 s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
106 /* Special penalty for mutiply-monster */
107 if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
109 int monnum_penarty = r_ptr->r_akills / 400;
110 if (monnum_penarty > 8) monnum_penarty = 8;
112 while (monnum_penarty--)
115 s64b_RSHIFT(new_exp, new_exp_frac, 2);
119 /* Special penalty for rest_and_shoot exp scum */
120 if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
122 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
123 if (over_damage > 32) over_damage = 32;
125 while (over_damage--)
128 s64b_mul(&new_exp, &new_exp_frac, 0, 9);
129 s64b_div(&new_exp, &new_exp_frac, 0, 10);
133 /* Finally multiply base experience point of the monster */
134 s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
136 /* Gain experience */
137 gain_exp_64(new_exp, new_exp_frac);
143 * @brief モンスターの時限ステータスを取得する
144 * @return m_idx モンスターの参照ID
145 * @return mproc_type モンスターの時限ステータスID
148 int get_mproc_idx(MONSTER_IDX m_idx, int mproc_type)
150 s16b *cur_mproc_list = current_floor_ptr->mproc_list[mproc_type];
153 for (i = current_floor_ptr->mproc_max[mproc_type] - 1; i >= 0; i--)
155 if (cur_mproc_list[i] == m_idx) return i;
162 * @brief モンスターの時限ステータスリストを追加する
163 * @return m_idx モンスターの参照ID
164 * @return mproc_type 追加したいモンスターの時限ステータスID
167 static void mproc_add(MONSTER_IDX m_idx, int mproc_type)
169 if (current_floor_ptr->mproc_max[mproc_type] < current_floor_ptr->max_m_idx) current_floor_ptr->mproc_list[mproc_type][current_floor_ptr->mproc_max[mproc_type]++] = (s16b)m_idx;
174 * @brief モンスターの時限ステータスリストを削除
175 * @return m_idx モンスターの参照ID
176 * @return mproc_type 削除したいモンスターの時限ステータスID
179 static void mproc_remove(MONSTER_IDX m_idx, int mproc_type)
181 int mproc_idx = get_mproc_idx(m_idx, mproc_type);
182 if (mproc_idx >= 0) current_floor_ptr->mproc_list[mproc_type][mproc_idx] = current_floor_ptr->mproc_list[mproc_type][--current_floor_ptr->mproc_max[mproc_type]];
187 * @brief モンスターの時限ステータスリストを初期化する / Initialize monster process
190 void mproc_init(void)
196 /* Reset "current_floor_ptr->mproc_max[]" */
197 for (cmi = 0; cmi < MAX_MTIMED; cmi++) current_floor_ptr->mproc_max[cmi] = 0;
199 /* Process the monsters (backwards) */
200 for (i = m_max - 1; i >= 1; i--)
202 /* Access the monster */
203 m_ptr = ¤t_floor_ptr->m_list[i];
205 /* Ignore "dead" monsters */
206 if (!monster_is_valid(m_ptr)) continue;
208 for (cmi = 0; cmi < MAX_MTIMED; cmi++)
210 if (m_ptr->mtimed[cmi]) mproc_add(i, cmi);
217 * @brief モンスターの睡眠状態値をセットする。0で起きる。 /
218 * Set "m_ptr->mtimed[MTIMED_CSLEEP]", notice observable changes
219 * @param m_idx モンスター参照ID
221 * @return 別途更新処理が必要な場合TRUEを返す
223 bool set_monster_csleep(MONSTER_IDX m_idx, int v)
225 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
227 v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
232 if (!MON_CSLEEP(m_ptr))
234 mproc_add(m_idx, MTIMED_CSLEEP);
242 if (MON_CSLEEP(m_ptr))
244 mproc_remove(m_idx, MTIMED_CSLEEP);
250 m_ptr->mtimed[MTIMED_CSLEEP] = (s16b)v;
252 if (!notice) return FALSE;
256 /* Update health bar as needed */
257 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
258 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
261 if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
268 * @brief モンスターの加速状態値をセット /
269 * Set "m_ptr->mtimed[MTIMED_FAST]", notice observable changes
270 * @param m_idx モンスター参照ID
272 * @return 別途更新処理が必要な場合TRUEを返す
274 bool set_monster_fast(MONSTER_IDX m_idx, int v)
276 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
278 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
283 if (!MON_FAST(m_ptr))
285 mproc_add(m_idx, MTIMED_FAST);
295 mproc_remove(m_idx, MTIMED_FAST);
301 m_ptr->mtimed[MTIMED_FAST] = (s16b)v;
303 if (!notice) return FALSE;
305 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
312 * Set "m_ptr->mtimed[MTIMED_SLOW]", notice observable changes
314 bool set_monster_slow(MONSTER_IDX m_idx, int v)
316 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
318 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
323 if (!MON_SLOW(m_ptr))
325 mproc_add(m_idx, MTIMED_SLOW);
335 mproc_remove(m_idx, MTIMED_SLOW);
341 m_ptr->mtimed[MTIMED_SLOW] = (s16b)v;
343 if (!notice) return FALSE;
345 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
352 * @brief モンスターの朦朧状態値をセット /
353 * Set "m_ptr->mtimed[MTIMED_STUNNED]", notice observable changes
354 * @param m_idx モンスター参照ID
356 * @return 別途更新処理が必要な場合TRUEを返す
358 bool set_monster_stunned(MONSTER_IDX m_idx, int v)
360 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
362 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
367 if (!MON_STUNNED(m_ptr))
369 mproc_add(m_idx, MTIMED_STUNNED);
377 if (MON_STUNNED(m_ptr))
379 mproc_remove(m_idx, MTIMED_STUNNED);
385 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)v;
392 * @brief モンスターの混乱状態値をセット /
393 * Set "m_ptr->mtimed[MTIMED_CONFUSED]", notice observable changes
394 * @param m_idx モンスター参照ID
396 * @return 別途更新処理が必要な場合TRUEを返す
398 bool set_monster_confused(MONSTER_IDX m_idx, int v)
400 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
402 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
407 if (!MON_CONFUSED(m_ptr))
409 mproc_add(m_idx, MTIMED_CONFUSED);
417 if (MON_CONFUSED(m_ptr))
419 mproc_remove(m_idx, MTIMED_CONFUSED);
425 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)v;
432 * @brief モンスターの恐慌状態値をセット /
433 * Set "m_ptr->mtimed[MTIMED_MONFEAR]", notice observable changes
434 * @param m_idx モンスター参照ID
436 * @return 別途更新処理が必要な場合TRUEを返す
438 bool set_monster_monfear(MONSTER_IDX m_idx, int v)
440 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
442 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
447 if (!MON_MONFEAR(m_ptr))
449 mproc_add(m_idx, MTIMED_MONFEAR);
457 if (MON_MONFEAR(m_ptr))
459 mproc_remove(m_idx, MTIMED_MONFEAR);
465 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)v;
467 if (!notice) return FALSE;
471 /* Update health bar as needed */
472 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
473 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
481 * @brief モンスターの無敵状態値をセット /
482 * Set "m_ptr->mtimed[MTIMED_INVULNER]", notice observable changes
483 * @param m_idx モンスター参照ID
485 * @param energy_need TRUEならば無敵解除時に行動ターン消費を行う
486 * @return 別途更新処理が必要な場合TRUEを返す
488 bool set_monster_invulner(MONSTER_IDX m_idx, int v, bool energy_need)
490 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
492 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
497 if (!MON_INVULNER(m_ptr))
499 mproc_add(m_idx, MTIMED_INVULNER);
507 if (MON_INVULNER(m_ptr))
509 mproc_remove(m_idx, MTIMED_INVULNER);
510 if (energy_need && !p_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
516 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)v;
518 if (!notice) return FALSE;
522 /* Update health bar as needed */
523 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
524 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
531 static u32b csleep_noise;
534 * @brief モンスターの各種状態値を時間経過により更新するサブルーチン
535 * @param m_idx モンスター参照ID
536 * @param mtimed_idx 更新するモンスターの時限ステータスID
539 static void process_monsters_mtimed_aux(MONSTER_IDX m_idx, int mtimed_idx)
541 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
547 monster_race *r_ptr = &r_info[m_ptr->r_idx];
549 /* Assume does not wake up */
552 /* Hack -- Require proximity */
553 if (m_ptr->cdis < AAF_LIMIT)
555 /* Handle "sensing radius" */
556 if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
562 /* Handle "sight" and "aggravation" */
563 else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(m_ptr->fy, m_ptr->fx)))
572 u32b notice = randint0(1024);
574 /* Nightmare monsters are more alert */
575 if (ironman_nightmare) notice /= 2;
577 /* Hack -- See if monster "notices" player */
578 if ((notice * notice * notice) <= csleep_noise)
580 /* Hack -- amount of "waking" */
581 /* Wake up faster near the player */
582 int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
584 /* Hack -- amount of "waking" is affected by speed of player */
585 d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
588 /* Monster wakes up "a little bit" */
591 if (!set_monster_csleep(m_idx, MON_CSLEEP(m_ptr) - d))
593 /* Notice the "not waking up" */
594 if (is_original_ap_and_seen(m_ptr))
596 /* Hack -- Count the ignores */
597 if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++;
604 /* Notice the "waking up" */
607 GAME_TEXT m_name[MAX_NLEN];
608 monster_desc(m_name, m_ptr, 0);
609 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
612 if (is_original_ap_and_seen(m_ptr))
614 /* Hack -- Count the wakings */
615 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
624 /* Reduce by one, note if expires */
625 if (set_monster_fast(m_idx, MON_FAST(m_ptr) - 1))
629 GAME_TEXT m_name[MAX_NLEN];
630 monster_desc(m_name, m_ptr, 0);
631 msg_format(_("%^sはもう加速されていない。", "%^s is no longer fast."), m_name);
637 /* Reduce by one, note if expires */
638 if (set_monster_slow(m_idx, MON_SLOW(m_ptr) - 1))
642 GAME_TEXT m_name[MAX_NLEN];
643 monster_desc(m_name, m_ptr, 0);
644 msg_format(_("%^sはもう減速されていない。", "%^s is no longer slow."), m_name);
651 int rlev = r_info[m_ptr->r_idx].level;
653 /* Recover from stun */
654 if (set_monster_stunned(m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
656 /* Message if visible */
659 GAME_TEXT m_name[MAX_NLEN];
660 monster_desc(m_name, m_ptr, 0);
661 msg_format(_("%^sは朦朧状態から立ち直った。", "%^s is no longer stunned."), m_name);
667 case MTIMED_CONFUSED:
668 /* Reduce the confusion */
669 if (set_monster_confused(m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
671 /* Message if visible */
674 GAME_TEXT m_name[MAX_NLEN];
675 monster_desc(m_name, m_ptr, 0);
676 msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name);
682 /* Reduce the fear */
683 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
688 GAME_TEXT m_name[MAX_NLEN];
692 /* Acquire the monster possessive */
693 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
695 monster_desc(m_name, m_ptr, 0);
697 msg_format("%^sは勇気を取り戻した。", m_name);
699 msg_format("%^s recovers %s courage.", m_name, m_poss);
705 case MTIMED_INVULNER:
706 /* Reduce by one, note if expires */
707 if (set_monster_invulner(m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
711 GAME_TEXT m_name[MAX_NLEN];
712 monster_desc(m_name, m_ptr, 0);
713 msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name);
722 * @brief 全モンスターの各種状態値を時間経過により更新するメインルーチン
723 * @param mtimed_idx 更新するモンスターの時限ステータスID
726 * Process the counters of monsters (once per 10 game turns)\n
727 * These functions are to process monsters' counters same as player's.
729 void process_monsters_mtimed(int mtimed_idx)
732 s16b *cur_mproc_list = current_floor_ptr->mproc_list[mtimed_idx];
734 /* Hack -- calculate the "player noise" */
735 if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - p_ptr->skill_stl));
737 /* Process the monsters (backwards) */
738 for (i = current_floor_ptr->mproc_max[mtimed_idx] - 1; i >= 0; i--)
740 /* Access the monster */
741 process_monsters_mtimed_aux(cur_mproc_list[i], mtimed_idx);
746 * @brief モンスターへの魔力消去処理
747 * @param m_idx 魔力消去を受けるモンスターの参照ID
750 void dispel_monster_status(MONSTER_IDX m_idx)
752 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
753 GAME_TEXT m_name[MAX_NLEN];
755 monster_desc(m_name, m_ptr, 0);
756 if (set_monster_invulner(m_idx, 0, TRUE))
758 if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name);
760 if (set_monster_fast(m_idx, 0))
762 if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name);
764 if (set_monster_slow(m_idx, 0))
766 if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name);
771 * @brief モンスターの時間停止処理
772 * @param num 時間停止を行った敵が行動できる回数
773 * @param who 時間停止処理の主体ID
774 * @param vs_player TRUEならば時間停止開始処理を行う
775 * @return 時間停止が行われている状態ならばTRUEを返す
777 bool process_the_world(int num, MONSTER_IDX who, bool vs_player)
779 monster_type *m_ptr = ¤t_floor_ptr->m_list[hack_m_idx]; /* the world monster */
781 if (current_world_ptr->timewalk_m_idx) return (FALSE);
785 GAME_TEXT m_name[MAX_NLEN];
786 monster_desc(m_name, m_ptr, 0);
789 msg_format(_("「『ザ・ワールド』!時は止まった!」", "%s yells 'The World! Time has stopped!'"), m_name);
791 msg_format(_("「時よ!」", "%s yells 'Time!'"), m_name);
792 else msg_print("hek!");
797 /* This monster cast spells */
798 current_world_ptr->timewalk_m_idx = hack_m_idx;
800 if (vs_player) do_cmd_redraw();
804 if (!monster_is_valid(m_ptr)) break;
805 process_monster(current_world_ptr->timewalk_m_idx);
809 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
812 p_ptr->redraw |= (PR_MAP);
813 p_ptr->update |= (PU_MONSTERS);
814 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
816 current_world_ptr->timewalk_m_idx = 0;
817 if (vs_player || (player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)))
819 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
828 * @brief モンスターの経験値取得処理
829 * @param m_idx 経験値を得るモンスターの参照ID
830 * @param s_idx 撃破されたモンスター種族の参照ID
833 void monster_gain_exp(MONSTER_IDX m_idx, IDX s_idx)
839 if (m_idx <= 0 || s_idx <= 0) return;
841 m_ptr = ¤t_floor_ptr->m_list[m_idx];
843 if (!monster_is_valid(m_ptr)) return;
845 r_ptr = &r_info[m_ptr->r_idx];
846 s_ptr = &r_info[s_idx];
848 if (p_ptr->inside_battle) return;
850 if (!r_ptr->next_exp) return;
852 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
853 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
854 if (!current_floor_ptr->dun_level) new_exp /= 5;
855 m_ptr->exp += new_exp;
856 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
858 if (m_ptr->exp >= r_ptr->next_exp)
860 GAME_TEXT m_name[MAX_NLEN];
861 int old_hp = m_ptr->hp;
862 int old_maxhp = m_ptr->max_maxhp;
863 int old_r_idx = m_ptr->r_idx;
864 byte old_sub_align = m_ptr->sub_align;
866 /* Hack -- Reduce the racial counter of previous monster */
867 real_r_ptr(m_ptr)->cur_num--;
869 monster_desc(m_name, m_ptr, 0);
870 m_ptr->r_idx = r_ptr->next_r_idx;
872 /* Count the monsters on the level */
873 real_r_ptr(m_ptr)->cur_num++;
875 m_ptr->ap_r_idx = m_ptr->r_idx;
876 r_ptr = &r_info[m_ptr->r_idx];
878 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
880 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
884 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
886 if (ironman_nightmare)
888 HIT_POINT hp = m_ptr->max_maxhp * 2L;
889 m_ptr->max_maxhp = MIN(30000, hp);
891 m_ptr->maxhp = m_ptr->max_maxhp;
892 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
894 /* dealt damage is 0 at initial*/
895 m_ptr->dealt_damage = 0;
897 /* Extract the monster base speed */
898 m_ptr->mspeed = get_mspeed(r_ptr);
900 /* Sub-alignment of a monster */
901 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
902 m_ptr->sub_align = old_sub_align;
905 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
906 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
907 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
912 if (is_pet(m_ptr) || m_ptr->ml)
914 if (!ignore_unview || player_can_see_bold(m_ptr->fy, m_ptr->fx))
918 monster_race *hallu_race;
922 hallu_race = &r_info[randint1(max_r_idx - 1)];
923 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
924 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name);
928 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name);
932 if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
934 /* Now you feel very close to this pet. */
935 m_ptr->parent_m_idx = 0;
937 update_monster(m_idx, FALSE);
938 lite_spot(m_ptr->fy, m_ptr->fx);
940 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;
944 * @brief モンスターのHPをダメージに応じて減算する /
945 * Decreases monsters hit points, handling monster death.
946 * @param dam 与えたダメージ量
947 * @param m_idx ダメージを与えたモンスターのID
948 * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
949 * @param note モンスターが倒された際の特別なメッセージ述語
953 * We return TRUE if the monster has been killed (and deleted).
954 * We announce monster death (using an optional "death message"
955 * if given, and a otherwise a generic killed/destroyed message).
956 * Only "physical attacks" can induce the "You have slain" message.
957 * Missile and Spell attacks will induce the "dies" message, or
958 * various "specialized" messages. Note that "You have destroyed"
959 * and "is destroyed" are synonyms for "You have slain" and "dies".
960 * Hack -- unseen monsters yield "You have killed it." message.
961 * Added fear (DGK) and check whether to print fear messages -CWS
962 * Made name, sex, and capitalization generic -BEN-
963 * As always, the "ghost" processing is a total hack.
964 * Hack -- we "delay" fear messages by passing around a "fear" flag.
965 * Consider decreasing monster experience over time, say,
966 * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
967 * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
968 * monster worth more than subsequent monsters. This would also need
969 * to induce changes in the monster recall code.
972 bool mon_take_hit(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
974 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
975 monster_race *r_ptr = &r_info[m_ptr->r_idx];
976 monster_type exp_mon;
978 /* Innocent until proven otherwise */
979 bool innocent = TRUE, thief = FALSE;
983 (void)COPY(&exp_mon, m_ptr, monster_type);
985 expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
987 get_exp_from_mon(expdam, &exp_mon);
989 /* Genocided by chaos patron */
990 if (!monster_is_valid(m_ptr)) m_idx = 0;
992 /* Redraw (later) if needed */
993 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
994 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
996 (void)set_monster_csleep(m_idx, 0);
998 /* Hack - Cancel any special player stealth magics. -LM- */
999 if (p_ptr->special_defense & NINJA_S_STEALTH)
1001 set_superstealth(FALSE);
1004 /* Genocided by chaos patron */
1005 if (!m_idx) return TRUE;
1008 m_ptr->dealt_damage += dam;
1010 if (m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
1014 msg_format(_("合計%d/%dのダメージを与えた。", "You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
1017 /* It is dead now */
1020 GAME_TEXT m_name[MAX_NLEN];
1022 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1024 /* You might have unmasked Tanuki first time */
1025 r_ptr = &r_info[m_ptr->r_idx];
1026 m_ptr->ap_r_idx = m_ptr->r_idx;
1027 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1030 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1032 /* You might have unmasked Chameleon first time */
1033 r_ptr = real_r_ptr(m_ptr);
1034 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1037 if (!(m_ptr->smart & SM_CLONED))
1039 /* When the player kills a Unique, it stays dead */
1040 if (r_ptr->flags1 & RF1_UNIQUE)
1044 /* Mega-Hack -- Banor & Lupart */
1045 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1047 r_info[MON_BANORLUPART].max_num = 0;
1048 r_info[MON_BANORLUPART].r_pkills++;
1049 r_info[MON_BANORLUPART].r_akills++;
1050 if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1052 else if (m_ptr->r_idx == MON_BANORLUPART)
1054 r_info[MON_BANOR].max_num = 0;
1055 r_info[MON_BANOR].r_pkills++;
1056 r_info[MON_BANOR].r_akills++;
1057 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1058 r_info[MON_LUPART].max_num = 0;
1059 r_info[MON_LUPART].r_pkills++;
1060 r_info[MON_LUPART].r_akills++;
1061 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1065 /* When the player kills a Nazgul, it stays dead */
1066 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1069 /* Count all monsters killed */
1070 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1072 /* Recall even invisible uniques or winners */
1073 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1075 /* Count kills this life */
1076 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1077 else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1079 /* Count kills in all lives */
1080 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1081 else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1083 /* Hack -- Auto-recall */
1084 monster_race_track(m_ptr->ap_r_idx);
1087 /* Extract monster name */
1088 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1090 /* Don't kill Amberites */
1091 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1093 int curses = 1 + randint1(3);
1094 bool stop_ty = FALSE;
1097 msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
1098 curse_equipment(100, 50);
1102 stop_ty = activate_ty_curse(stop_ty, &count);
1106 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1108 char line_got[1024];
1109 if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
1111 msg_format("%^s %s", m_name, line_got);
1115 if (m_ptr->r_idx == MON_SERPENT)
1117 screen_dump = make_screen_dump();
1122 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1124 if (!current_floor_ptr->dun_level && !p_ptr->ambush_flag && !p_ptr->inside_arena)
1126 chg_virtue(V_VALOUR, -1);
1128 else if (r_ptr->level > current_floor_ptr->dun_level)
1130 if (randint1(10) <= (r_ptr->level - current_floor_ptr->dun_level))
1131 chg_virtue(V_VALOUR, 1);
1133 if (r_ptr->level > 60)
1135 chg_virtue(V_VALOUR, 1);
1137 if (r_ptr->level >= 2 * (p_ptr->lev + 1))
1138 chg_virtue(V_VALOUR, 2);
1141 if (r_ptr->flags1 & RF1_UNIQUE)
1143 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
1145 if (r_ptr->flags3 & RF3_GOOD)
1147 chg_virtue(V_UNLIFE, 2);
1148 chg_virtue(V_VITALITY, -2);
1151 if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
1154 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1156 chg_virtue(V_COMPASSION, -1);
1159 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100)))
1160 chg_virtue(V_UNLIFE, 1);
1162 if (r_ptr->d_char == 'A')
1164 if (r_ptr->flags1 & RF1_UNIQUE)
1165 chg_virtue(V_FAITH, -2);
1166 else if ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100))
1168 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
1169 else chg_virtue(V_FAITH, 1);
1172 else if (r_ptr->flags3 & RF3_DEMON)
1174 if (r_ptr->flags1 & RF1_UNIQUE)
1175 chg_virtue(V_FAITH, 2);
1176 else if ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100))
1177 chg_virtue(V_FAITH, 1);
1180 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1181 chg_virtue(V_VITALITY, 2);
1183 if (r_ptr->r_deaths)
1185 if (r_ptr->flags1 & RF1_UNIQUE)
1187 chg_virtue(V_HONOUR, 10);
1189 else if ((r_ptr->level) / 10 + (2 * current_floor_ptr->dun_level) >= randint1(100))
1191 chg_virtue(V_HONOUR, 1);
1194 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1196 chg_virtue(V_VALOUR, -1);
1199 for (i = 0; i < 4; i++)
1201 if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1203 if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1204 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1206 thief = TRUE; /* Thief! */
1209 /* The new law says it is illegal to live in the dungeon */
1210 if (r_ptr->level != 0) innocent = FALSE;
1214 if (r_ptr->flags1 & RF1_UNIQUE)
1215 chg_virtue(V_JUSTICE, 3);
1216 else if (1 + ((r_ptr->level) / 10 + (2 * current_floor_ptr->dun_level)) >= randint1(100))
1217 chg_virtue(V_JUSTICE, 1);
1221 chg_virtue(V_JUSTICE, -1);
1224 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)))
1226 if (one_in_(4)) chg_virtue(V_NATURE, -1);
1229 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1232 sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
1233 do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
1239 /* Death by Missile/Spell attack */
1242 msg_format("%^s%s", m_name, note);
1245 /* Death by physical attack -- invisible monster */
1246 else if (!m_ptr->ml)
1249 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1250 msg_format("せっかくだから%sを殺した。", m_name);
1252 msg_format("%sを殺した。", m_name);
1254 msg_format("You have killed %s.", m_name);
1259 /* Death by Physical attack -- non-living monster */
1260 else if (!monster_living(m_ptr->r_idx))
1262 bool explode = FALSE;
1264 for (i = 0; i < 4; i++)
1266 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1269 /* Special note at death */
1271 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
1275 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1276 msg_format("せっかくだから%sを倒した。", m_name);
1278 msg_format("%sを倒した。", m_name);
1280 msg_format("You have destroyed %s.", m_name);
1285 /* Death by Physical attack -- living monster */
1289 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1290 msg_format("せっかくだから%sを葬り去った。", m_name);
1292 msg_format("%sを葬り去った。", m_name);
1294 msg_format("You have slain %s.", m_name);
1298 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
1300 for (i = 0; i < MAX_KUBI; i++)
1302 if ((current_world_ptr->bounty_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
1304 msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1310 /* Generate treasure */
1311 monster_death(m_idx, TRUE);
1313 /* Mega hack : replace IKETA to BIKETAL */
1314 if ((m_ptr->r_idx == MON_IKETA) && !(p_ptr->inside_arena || p_ptr->inside_battle))
1316 POSITION dummy_y = m_ptr->fy;
1317 POSITION dummy_x = m_ptr->fx;
1318 BIT_FLAGS mode = 0L;
1319 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1320 delete_monster_idx(m_idx);
1321 if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1323 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha! *I* am Biketal!"));
1328 delete_monster_idx(m_idx);
1331 get_exp_from_mon((long)exp_mon.max_maxhp * 2, &exp_mon);
1336 /* Monster is dead */
1343 /* Mega-Hack -- Pain cancels fear */
1344 if (MON_MONFEAR(m_ptr) && (dam > 0))
1347 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1354 /* Sometimes a monster gets scared by damage */
1355 if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1357 /* Percentage of fully healthy */
1358 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1361 * Run (sometimes) if at 10% or less of max hit points,
1362 * or (usually) when hit for half its current hit points
1364 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1366 /* Hack -- note fear */
1369 /* Hack -- Add some timed fear */
1370 (void)set_monster_monfear(m_idx, (randint1(10) +
1371 (((dam >= m_ptr->hp) && (percentage > 7)) ?
1372 20 : ((11 - percentage) * 5))));
1382 bool monster_is_valid(monster_type *m_ptr)
1384 return (m_ptr->r_idx != 0);