5 #include "monster-status.h"
6 #include "monster-spell.h"
7 #include "monster-process.h"
8 #include "spells-summon.h"
9 #include "monsterrace-hook.h"
10 #include "object-curse.h"
17 * @brief モンスターIDからPOWERFULフラグの有無を取得する /
18 * @param m_idx モンスターID
19 * @return POWERFULフラグがあればTRUE、なければFALSEを返す。
21 bool monster_is_powerful(MONSTER_IDX m_idx)
23 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
24 monster_race *r_ptr = &r_info[m_ptr->r_idx];
25 bool powerful = r_ptr->flags2 & RF2_POWERFUL ? TRUE : FALSE;
30 * @brief モンスターIDからモンスターのレベルを取得する(ただし最低1を保証する) /
31 * @param m_idx モンスターID
34 DEPTH monster_level_idx(MONSTER_IDX m_idx)
36 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
37 monster_race *r_ptr = &r_info[m_ptr->r_idx];
38 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
43 * @brief モンスターに与えたダメージの修正処理 /
44 * Modify the physical damage done to the monster.
45 * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
47 * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
48 * @return 修正を行った結果のダメージ量
51 * (for example when it's invulnerable or shielded)
52 * ToDo: Accept a damage-type to calculate the modified damage from
53 * things like fire, frost, lightning, poison, ... attacks.
54 * "type" is not yet used and should be 0.
57 HIT_POINT mon_damage_mod(monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
59 monster_race *r_ptr = &r_info[m_ptr->r_idx];
61 if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
64 if ((dam == 0) && one_in_(3)) dam = 1;
67 if (MON_INVULNER(m_ptr))
71 if (!p_ptr->blind && is_seen(m_ptr))
73 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
76 else if (!one_in_(PENETRATE_INVULNERABILITY))
87 * @brief モンスターに与えたダメージを元に経験値を加算する /
88 * Calculate experience point to be get
90 * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
94 * Even the 64 bit operation is not big enough to avoid overflaw
95 * unless we carefully choose orders of multiplication and division.
96 * Get the coefficient first, and multiply (potentially huge) base
97 * experience point of a monster later.
100 static void get_exp_from_mon(HIT_POINT dam, monster_type *m_ptr)
102 monster_race *r_ptr = &r_info[m_ptr->r_idx];
109 if (!monster_is_valid(m_ptr)) return;
110 if (is_pet(m_ptr) || p_ptr->inside_battle) return;
113 * - Ratio of monster's level to player's level effects
114 * - Varying speed effects
115 * - Get a fraction in proportion of damage point
117 new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
120 div_l = (p_ptr->max_plv + 2) * SPEED_TO_ENERGY(r_ptr->speed);
122 /* Use (average maxhp * 2) as a denominator */
123 if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
124 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
126 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
128 /* Special penalty in the wilderness */
129 if (!current_floor_ptr->dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
130 s64b_mul(&div_h, &div_l, 0, 5);
132 /* Do division first to prevent overflaw */
133 s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
135 /* Special penalty for mutiply-monster */
136 if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
138 int monnum_penarty = r_ptr->r_akills / 400;
139 if (monnum_penarty > 8) monnum_penarty = 8;
141 while (monnum_penarty--)
144 s64b_RSHIFT(new_exp, new_exp_frac, 2);
148 /* Special penalty for rest_and_shoot exp scum */
149 if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
151 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
152 if (over_damage > 32) over_damage = 32;
154 while (over_damage--)
157 s64b_mul(&new_exp, &new_exp_frac, 0, 9);
158 s64b_div(&new_exp, &new_exp_frac, 0, 10);
162 /* Finally multiply base experience point of the monster */
163 s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
165 /* Gain experience */
166 gain_exp_64(new_exp, new_exp_frac);
172 * @brief モンスターの時限ステータスを取得する
173 * @return m_idx モンスターの参照ID
174 * @return mproc_type モンスターの時限ステータスID
177 int get_mproc_idx(MONSTER_IDX m_idx, int mproc_type)
179 s16b *cur_mproc_list = current_floor_ptr->mproc_list[mproc_type];
182 for (i = current_floor_ptr->mproc_max[mproc_type] - 1; i >= 0; i--)
184 if (cur_mproc_list[i] == m_idx) return i;
191 * @brief モンスターの時限ステータスリストを追加する
192 * @return m_idx モンスターの参照ID
193 * @return mproc_type 追加したいモンスターの時限ステータスID
196 static void mproc_add(MONSTER_IDX m_idx, int mproc_type)
198 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;
203 * @brief モンスターの時限ステータスリストを削除
204 * @return m_idx モンスターの参照ID
205 * @return mproc_type 削除したいモンスターの時限ステータスID
208 static void mproc_remove(MONSTER_IDX m_idx, int mproc_type)
210 int mproc_idx = get_mproc_idx(m_idx, mproc_type);
211 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]];
216 * @brief モンスターの時限ステータスリストを初期化する / Initialize monster process
219 void mproc_init(void)
225 /* Reset "current_floor_ptr->mproc_max[]" */
226 for (cmi = 0; cmi < MAX_MTIMED; cmi++) current_floor_ptr->mproc_max[cmi] = 0;
228 /* Process the monsters (backwards) */
229 for (i = m_max - 1; i >= 1; i--)
231 /* Access the monster */
232 m_ptr = ¤t_floor_ptr->m_list[i];
234 /* Ignore "dead" monsters */
235 if (!monster_is_valid(m_ptr)) continue;
237 for (cmi = 0; cmi < MAX_MTIMED; cmi++)
239 if (m_ptr->mtimed[cmi]) mproc_add(i, cmi);
246 * @brief モンスターの睡眠状態値をセットする。0で起きる。 /
247 * Set "m_ptr->mtimed[MTIMED_CSLEEP]", notice observable changes
248 * @param m_idx モンスター参照ID
250 * @return 別途更新処理が必要な場合TRUEを返す
252 bool set_monster_csleep(MONSTER_IDX m_idx, int v)
254 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
256 v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
261 if (!MON_CSLEEP(m_ptr))
263 mproc_add(m_idx, MTIMED_CSLEEP);
271 if (MON_CSLEEP(m_ptr))
273 mproc_remove(m_idx, MTIMED_CSLEEP);
279 m_ptr->mtimed[MTIMED_CSLEEP] = (s16b)v;
281 if (!notice) return FALSE;
285 /* Update health bar as needed */
286 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
287 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
290 if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
297 * @brief モンスターの加速状態値をセット /
298 * Set "m_ptr->mtimed[MTIMED_FAST]", notice observable changes
299 * @param m_idx モンスター参照ID
301 * @return 別途更新処理が必要な場合TRUEを返す
303 bool set_monster_fast(MONSTER_IDX m_idx, int v)
305 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
307 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
312 if (!MON_FAST(m_ptr))
314 mproc_add(m_idx, MTIMED_FAST);
324 mproc_remove(m_idx, MTIMED_FAST);
330 m_ptr->mtimed[MTIMED_FAST] = (s16b)v;
332 if (!notice) return FALSE;
334 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
341 * Set "m_ptr->mtimed[MTIMED_SLOW]", notice observable changes
343 bool set_monster_slow(MONSTER_IDX m_idx, int v)
345 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
347 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
352 if (!MON_SLOW(m_ptr))
354 mproc_add(m_idx, MTIMED_SLOW);
364 mproc_remove(m_idx, MTIMED_SLOW);
370 m_ptr->mtimed[MTIMED_SLOW] = (s16b)v;
372 if (!notice) return FALSE;
374 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
381 * @brief モンスターの朦朧状態値をセット /
382 * Set "m_ptr->mtimed[MTIMED_STUNNED]", notice observable changes
383 * @param m_idx モンスター参照ID
385 * @return 別途更新処理が必要な場合TRUEを返す
387 bool set_monster_stunned(MONSTER_IDX m_idx, int v)
389 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
391 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
396 if (!MON_STUNNED(m_ptr))
398 mproc_add(m_idx, MTIMED_STUNNED);
406 if (MON_STUNNED(m_ptr))
408 mproc_remove(m_idx, MTIMED_STUNNED);
414 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)v;
421 * @brief モンスターの混乱状態値をセット /
422 * Set "m_ptr->mtimed[MTIMED_CONFUSED]", notice observable changes
423 * @param m_idx モンスター参照ID
425 * @return 別途更新処理が必要な場合TRUEを返す
427 bool set_monster_confused(MONSTER_IDX m_idx, int v)
429 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
431 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
436 if (!MON_CONFUSED(m_ptr))
438 mproc_add(m_idx, MTIMED_CONFUSED);
446 if (MON_CONFUSED(m_ptr))
448 mproc_remove(m_idx, MTIMED_CONFUSED);
454 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)v;
461 * @brief モンスターの恐慌状態値をセット /
462 * Set "m_ptr->mtimed[MTIMED_MONFEAR]", notice observable changes
463 * @param m_idx モンスター参照ID
465 * @return 別途更新処理が必要な場合TRUEを返す
467 bool set_monster_monfear(MONSTER_IDX m_idx, int v)
469 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
471 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
476 if (!MON_MONFEAR(m_ptr))
478 mproc_add(m_idx, MTIMED_MONFEAR);
486 if (MON_MONFEAR(m_ptr))
488 mproc_remove(m_idx, MTIMED_MONFEAR);
494 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)v;
496 if (!notice) return FALSE;
500 /* Update health bar as needed */
501 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
502 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
510 * @brief モンスターの無敵状態値をセット /
511 * Set "m_ptr->mtimed[MTIMED_INVULNER]", notice observable changes
512 * @param m_idx モンスター参照ID
514 * @param energy_need TRUEならば無敵解除時に行動ターン消費を行う
515 * @return 別途更新処理が必要な場合TRUEを返す
517 bool set_monster_invulner(MONSTER_IDX m_idx, int v, bool energy_need)
519 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
521 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
526 if (!MON_INVULNER(m_ptr))
528 mproc_add(m_idx, MTIMED_INVULNER);
536 if (MON_INVULNER(m_ptr))
538 mproc_remove(m_idx, MTIMED_INVULNER);
539 if (energy_need && !p_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
545 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)v;
547 if (!notice) return FALSE;
551 /* Update health bar as needed */
552 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
553 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
560 static u32b csleep_noise;
563 * @brief モンスターの各種状態値を時間経過により更新するサブルーチン
564 * @param m_idx モンスター参照ID
565 * @param mtimed_idx 更新するモンスターの時限ステータスID
568 static void process_monsters_mtimed_aux(MONSTER_IDX m_idx, int mtimed_idx)
570 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
576 monster_race *r_ptr = &r_info[m_ptr->r_idx];
578 /* Assume does not wake up */
581 /* Hack -- Require proximity */
582 if (m_ptr->cdis < AAF_LIMIT)
584 /* Handle "sensing radius" */
585 if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
591 /* Handle "sight" and "aggravation" */
592 else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(m_ptr->fy, m_ptr->fx)))
601 u32b notice = randint0(1024);
603 /* Nightmare monsters are more alert */
604 if (ironman_nightmare) notice /= 2;
606 /* Hack -- See if monster "notices" player */
607 if ((notice * notice * notice) <= csleep_noise)
609 /* Hack -- amount of "waking" */
610 /* Wake up faster near the player */
611 int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
613 /* Hack -- amount of "waking" is affected by speed of player */
614 d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
617 /* Monster wakes up "a little bit" */
620 if (!set_monster_csleep(m_idx, MON_CSLEEP(m_ptr) - d))
622 /* Notice the "not waking up" */
623 if (is_original_ap_and_seen(m_ptr))
625 /* Hack -- Count the ignores */
626 if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++;
633 /* Notice the "waking up" */
636 GAME_TEXT m_name[MAX_NLEN];
637 monster_desc(m_name, m_ptr, 0);
638 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
641 if (is_original_ap_and_seen(m_ptr))
643 /* Hack -- Count the wakings */
644 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
653 /* Reduce by one, note if expires */
654 if (set_monster_fast(m_idx, MON_FAST(m_ptr) - 1))
658 GAME_TEXT m_name[MAX_NLEN];
659 monster_desc(m_name, m_ptr, 0);
660 msg_format(_("%^sはもう加速されていない。", "%^s is no longer fast."), m_name);
666 /* Reduce by one, note if expires */
667 if (set_monster_slow(m_idx, MON_SLOW(m_ptr) - 1))
671 GAME_TEXT m_name[MAX_NLEN];
672 monster_desc(m_name, m_ptr, 0);
673 msg_format(_("%^sはもう減速されていない。", "%^s is no longer slow."), m_name);
680 int rlev = r_info[m_ptr->r_idx].level;
682 /* Recover from stun */
683 if (set_monster_stunned(m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
685 /* Message if visible */
688 GAME_TEXT m_name[MAX_NLEN];
689 monster_desc(m_name, m_ptr, 0);
690 msg_format(_("%^sは朦朧状態から立ち直った。", "%^s is no longer stunned."), m_name);
696 case MTIMED_CONFUSED:
697 /* Reduce the confusion */
698 if (set_monster_confused(m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
700 /* Message if visible */
703 GAME_TEXT m_name[MAX_NLEN];
704 monster_desc(m_name, m_ptr, 0);
705 msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name);
711 /* Reduce the fear */
712 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
717 GAME_TEXT m_name[MAX_NLEN];
721 /* Acquire the monster possessive */
722 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
724 monster_desc(m_name, m_ptr, 0);
726 msg_format("%^sは勇気を取り戻した。", m_name);
728 msg_format("%^s recovers %s courage.", m_name, m_poss);
734 case MTIMED_INVULNER:
735 /* Reduce by one, note if expires */
736 if (set_monster_invulner(m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
740 GAME_TEXT m_name[MAX_NLEN];
741 monster_desc(m_name, m_ptr, 0);
742 msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name);
751 * @brief 全モンスターの各種状態値を時間経過により更新するメインルーチン
752 * @param mtimed_idx 更新するモンスターの時限ステータスID
755 * Process the counters of monsters (once per 10 game turns)\n
756 * These functions are to process monsters' counters same as player's.
758 void process_monsters_mtimed(int mtimed_idx)
761 s16b *cur_mproc_list = current_floor_ptr->mproc_list[mtimed_idx];
763 /* Hack -- calculate the "player noise" */
764 if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - p_ptr->skill_stl));
766 /* Process the monsters (backwards) */
767 for (i = current_floor_ptr->mproc_max[mtimed_idx] - 1; i >= 0; i--)
769 /* Access the monster */
770 process_monsters_mtimed_aux(cur_mproc_list[i], mtimed_idx);
775 * @brief モンスターへの魔力消去処理
776 * @param m_idx 魔力消去を受けるモンスターの参照ID
779 void dispel_monster_status(MONSTER_IDX m_idx)
781 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
782 GAME_TEXT m_name[MAX_NLEN];
784 monster_desc(m_name, m_ptr, 0);
785 if (set_monster_invulner(m_idx, 0, TRUE))
787 if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name);
789 if (set_monster_fast(m_idx, 0))
791 if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name);
793 if (set_monster_slow(m_idx, 0))
795 if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name);
800 * @brief モンスターの時間停止処理
801 * @param num 時間停止を行った敵が行動できる回数
802 * @param who 時間停止処理の主体ID
803 * @param vs_player TRUEならば時間停止開始処理を行う
804 * @return 時間停止が行われている状態ならばTRUEを返す
806 bool set_monster_timewalk(int num, MONSTER_IDX who, bool vs_player)
808 monster_type *m_ptr = ¤t_floor_ptr->m_list[hack_m_idx]; /* the world monster */
810 if (current_world_ptr->timewalk_m_idx) return (FALSE);
814 GAME_TEXT m_name[MAX_NLEN];
815 monster_desc(m_name, m_ptr, 0);
818 msg_format(_("「『ザ・ワールド』!時は止まった!」", "%s yells 'The World! Time has stopped!'"), m_name);
820 msg_format(_("「時よ!」", "%s yells 'Time!'"), m_name);
821 else msg_print("hek!");
826 /* This monster cast spells */
827 current_world_ptr->timewalk_m_idx = hack_m_idx;
829 if (vs_player) do_cmd_redraw();
833 if (!monster_is_valid(m_ptr)) break;
834 process_monster(current_world_ptr->timewalk_m_idx);
838 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
841 p_ptr->redraw |= (PR_MAP);
842 p_ptr->update |= (PU_MONSTERS);
843 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
845 current_world_ptr->timewalk_m_idx = 0;
846 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)))
848 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
857 * @brief モンスターの経験値取得処理
858 * @param m_idx 経験値を得るモンスターの参照ID
859 * @param s_idx 撃破されたモンスター種族の参照ID
862 void monster_gain_exp(MONSTER_IDX m_idx, MONRACE_IDX s_idx)
868 if (m_idx <= 0 || s_idx <= 0) return;
870 m_ptr = ¤t_floor_ptr->m_list[m_idx];
872 if (!monster_is_valid(m_ptr)) return;
874 r_ptr = &r_info[m_ptr->r_idx];
875 s_ptr = &r_info[s_idx];
877 if (p_ptr->inside_battle) return;
879 if (!r_ptr->next_exp) return;
881 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
882 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
883 if (!current_floor_ptr->dun_level) new_exp /= 5;
884 m_ptr->exp += new_exp;
885 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
887 if (m_ptr->exp >= r_ptr->next_exp)
889 GAME_TEXT m_name[MAX_NLEN];
890 int old_hp = m_ptr->hp;
891 int old_maxhp = m_ptr->max_maxhp;
892 int old_r_idx = m_ptr->r_idx;
893 byte old_sub_align = m_ptr->sub_align;
895 /* Hack -- Reduce the racial counter of previous monster */
896 real_r_ptr(m_ptr)->cur_num--;
898 monster_desc(m_name, m_ptr, 0);
899 m_ptr->r_idx = r_ptr->next_r_idx;
901 /* Count the monsters on the level */
902 real_r_ptr(m_ptr)->cur_num++;
904 m_ptr->ap_r_idx = m_ptr->r_idx;
905 r_ptr = &r_info[m_ptr->r_idx];
907 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
909 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
913 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
915 if (ironman_nightmare)
917 HIT_POINT hp = m_ptr->max_maxhp * 2L;
918 m_ptr->max_maxhp = MIN(30000, hp);
920 m_ptr->maxhp = m_ptr->max_maxhp;
921 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
923 /* dealt damage is 0 at initial*/
924 m_ptr->dealt_damage = 0;
926 /* Extract the monster base speed */
927 m_ptr->mspeed = get_mspeed(r_ptr);
929 /* Sub-alignment of a monster */
930 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
931 m_ptr->sub_align = old_sub_align;
934 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
935 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
936 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
941 if (is_pet(m_ptr) || m_ptr->ml)
943 if (!ignore_unview || player_can_see_bold(m_ptr->fy, m_ptr->fx))
947 monster_race *hallu_race;
951 hallu_race = &r_info[randint1(max_r_idx - 1)];
952 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
953 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name);
957 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name);
961 if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
963 /* Now you feel very close to this pet. */
964 m_ptr->parent_m_idx = 0;
966 update_monster(m_idx, FALSE);
967 lite_spot(m_ptr->fy, m_ptr->fx);
969 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;
973 * @brief モンスターのHPをダメージに応じて減算する /
974 * Decreases monsters hit points, handling monster death.
975 * @param dam 与えたダメージ量
976 * @param m_idx ダメージを与えたモンスターのID
977 * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
978 * @param note モンスターが倒された際の特別なメッセージ述語
982 * We return TRUE if the monster has been killed (and deleted).
983 * We announce monster death (using an optional "death message"
984 * if given, and a otherwise a generic killed/destroyed message).
985 * Only "physical attacks" can induce the "You have slain" message.
986 * Missile and Spell attacks will induce the "dies" message, or
987 * various "specialized" messages. Note that "You have destroyed"
988 * and "is destroyed" are synonyms for "You have slain" and "dies".
989 * Hack -- unseen monsters yield "You have killed it." message.
990 * Added fear (DGK) and check whether to print fear messages -CWS
991 * Made name, sex, and capitalization generic -BEN-
992 * As always, the "ghost" processing is a total hack.
993 * Hack -- we "delay" fear messages by passing around a "fear" flag.
994 * Consider decreasing monster experience over time, say,
995 * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
996 * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
997 * monster worth more than subsequent monsters. This would also need
998 * to induce changes in the monster recall code.
1001 bool mon_take_hit(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
1003 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1004 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1005 monster_type exp_mon;
1007 /* Innocent until proven otherwise */
1008 bool innocent = TRUE, thief = FALSE;
1012 (void)COPY(&exp_mon, m_ptr, monster_type);
1014 expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
1016 get_exp_from_mon(expdam, &exp_mon);
1018 /* Genocided by chaos patron */
1019 if (!monster_is_valid(m_ptr)) m_idx = 0;
1021 /* Redraw (later) if needed */
1022 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1023 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1025 (void)set_monster_csleep(m_idx, 0);
1027 /* Hack - Cancel any special player stealth magics. -LM- */
1028 if (p_ptr->special_defense & NINJA_S_STEALTH)
1030 set_superstealth(FALSE);
1033 /* Genocided by chaos patron */
1034 if (!m_idx) return TRUE;
1037 m_ptr->dealt_damage += dam;
1039 if (m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
1043 msg_format(_("合計%d/%dのダメージを与えた。", "You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
1046 /* It is dead now */
1049 GAME_TEXT m_name[MAX_NLEN];
1051 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1053 /* You might have unmasked Tanuki first time */
1054 r_ptr = &r_info[m_ptr->r_idx];
1055 m_ptr->ap_r_idx = m_ptr->r_idx;
1056 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1059 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1061 /* You might have unmasked Chameleon first time */
1062 r_ptr = real_r_ptr(m_ptr);
1063 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1066 if (!(m_ptr->smart & SM_CLONED))
1068 /* When the player kills a Unique, it stays dead */
1069 if (r_ptr->flags1 & RF1_UNIQUE)
1073 /* Mega-Hack -- Banor & Lupart */
1074 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1076 r_info[MON_BANORLUPART].max_num = 0;
1077 r_info[MON_BANORLUPART].r_pkills++;
1078 r_info[MON_BANORLUPART].r_akills++;
1079 if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1081 else if (m_ptr->r_idx == MON_BANORLUPART)
1083 r_info[MON_BANOR].max_num = 0;
1084 r_info[MON_BANOR].r_pkills++;
1085 r_info[MON_BANOR].r_akills++;
1086 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1087 r_info[MON_LUPART].max_num = 0;
1088 r_info[MON_LUPART].r_pkills++;
1089 r_info[MON_LUPART].r_akills++;
1090 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1094 /* When the player kills a Nazgul, it stays dead */
1095 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1098 /* Count all monsters killed */
1099 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1101 /* Recall even invisible uniques or winners */
1102 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1104 /* Count kills this life */
1105 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1106 else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1108 /* Count kills in all lives */
1109 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1110 else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1112 /* Hack -- Auto-recall */
1113 monster_race_track(m_ptr->ap_r_idx);
1116 /* Extract monster name */
1117 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1119 /* Don't kill Amberites */
1120 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1122 int curses = 1 + randint1(3);
1123 bool stop_ty = FALSE;
1126 msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
1127 curse_equipment(100, 50);
1131 stop_ty = activate_ty_curse(stop_ty, &count);
1135 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1137 char line_got[1024];
1138 if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
1140 msg_format("%^s %s", m_name, line_got);
1144 if (m_ptr->r_idx == MON_SERPENT)
1146 screen_dump = make_screen_dump();
1151 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1153 if (!current_floor_ptr->dun_level && !p_ptr->ambush_flag && !p_ptr->inside_arena)
1155 chg_virtue(V_VALOUR, -1);
1157 else if (r_ptr->level > current_floor_ptr->dun_level)
1159 if (randint1(10) <= (r_ptr->level - current_floor_ptr->dun_level))
1160 chg_virtue(V_VALOUR, 1);
1162 if (r_ptr->level > 60)
1164 chg_virtue(V_VALOUR, 1);
1166 if (r_ptr->level >= 2 * (p_ptr->lev + 1))
1167 chg_virtue(V_VALOUR, 2);
1170 if (r_ptr->flags1 & RF1_UNIQUE)
1172 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
1174 if (r_ptr->flags3 & RF3_GOOD)
1176 chg_virtue(V_UNLIFE, 2);
1177 chg_virtue(V_VITALITY, -2);
1180 if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
1183 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1185 chg_virtue(V_COMPASSION, -1);
1188 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100)))
1189 chg_virtue(V_UNLIFE, 1);
1191 if (r_ptr->d_char == 'A')
1193 if (r_ptr->flags1 & RF1_UNIQUE)
1194 chg_virtue(V_FAITH, -2);
1195 else if ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100))
1197 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
1198 else chg_virtue(V_FAITH, 1);
1201 else if (r_ptr->flags3 & RF3_DEMON)
1203 if (r_ptr->flags1 & RF1_UNIQUE)
1204 chg_virtue(V_FAITH, 2);
1205 else if ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100))
1206 chg_virtue(V_FAITH, 1);
1209 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1210 chg_virtue(V_VITALITY, 2);
1212 if (r_ptr->r_deaths)
1214 if (r_ptr->flags1 & RF1_UNIQUE)
1216 chg_virtue(V_HONOUR, 10);
1218 else if ((r_ptr->level) / 10 + (2 * current_floor_ptr->dun_level) >= randint1(100))
1220 chg_virtue(V_HONOUR, 1);
1223 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1225 chg_virtue(V_VALOUR, -1);
1228 for (i = 0; i < 4; i++)
1230 if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1232 if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1233 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1235 thief = TRUE; /* Thief! */
1238 /* The new law says it is illegal to live in the dungeon */
1239 if (r_ptr->level != 0) innocent = FALSE;
1243 if (r_ptr->flags1 & RF1_UNIQUE)
1244 chg_virtue(V_JUSTICE, 3);
1245 else if (1 + ((r_ptr->level) / 10 + (2 * current_floor_ptr->dun_level)) >= randint1(100))
1246 chg_virtue(V_JUSTICE, 1);
1250 chg_virtue(V_JUSTICE, -1);
1253 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)))
1255 if (one_in_(4)) chg_virtue(V_NATURE, -1);
1258 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1261 sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
1262 do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
1268 /* Death by Missile/Spell attack */
1271 msg_format("%^s%s", m_name, note);
1274 /* Death by physical attack -- invisible monster */
1275 else if (!m_ptr->ml)
1278 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1279 msg_format("せっかくだから%sを殺した。", m_name);
1281 msg_format("%sを殺した。", m_name);
1283 msg_format("You have killed %s.", m_name);
1288 /* Death by Physical attack -- non-living monster */
1289 else if (!monster_living(m_ptr->r_idx))
1291 bool explode = FALSE;
1293 for (i = 0; i < 4; i++)
1295 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1298 /* Special note at death */
1300 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
1304 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1305 msg_format("せっかくだから%sを倒した。", m_name);
1307 msg_format("%sを倒した。", m_name);
1309 msg_format("You have destroyed %s.", m_name);
1314 /* Death by Physical attack -- living monster */
1318 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1319 msg_format("せっかくだから%sを葬り去った。", m_name);
1321 msg_format("%sを葬り去った。", m_name);
1323 msg_format("You have slain %s.", m_name);
1327 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
1329 for (i = 0; i < MAX_KUBI; i++)
1331 if ((current_world_ptr->bounty_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
1333 msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1339 /* Generate treasure */
1340 monster_death(m_idx, TRUE);
1342 /* Mega hack : replace IKETA to BIKETAL */
1343 if ((m_ptr->r_idx == MON_IKETA) && !(p_ptr->inside_arena || p_ptr->inside_battle))
1345 POSITION dummy_y = m_ptr->fy;
1346 POSITION dummy_x = m_ptr->fx;
1347 BIT_FLAGS mode = 0L;
1348 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1349 delete_monster_idx(m_idx);
1350 if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1352 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha! *I* am Biketal!"));
1357 delete_monster_idx(m_idx);
1360 get_exp_from_mon((long)exp_mon.max_maxhp * 2, &exp_mon);
1365 /* Monster is dead */
1372 /* Mega-Hack -- Pain cancels fear */
1373 if (MON_MONFEAR(m_ptr) && (dam > 0))
1376 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1383 /* Sometimes a monster gets scared by damage */
1384 if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1386 /* Percentage of fully healthy */
1387 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1390 * Run (sometimes) if at 10% or less of max hit points,
1391 * or (usually) when hit for half its current hit points
1393 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1395 /* Hack -- note fear */
1398 /* Hack -- Add some timed fear */
1399 (void)set_monster_monfear(m_idx, (randint1(10) +
1400 (((dam >= m_ptr->hp) && (percentage > 7)) ?
1401 20 : ((11 - percentage) * 5))));
1411 bool monster_is_valid(monster_type *m_ptr)
1413 return (m_ptr->r_idx != 0);