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"
14 #include "player-effects.h"
18 * @brief モンスターIDからPOWERFULフラグの有無を取得する /
19 * @param m_idx モンスターID
20 * @return POWERFULフラグがあればTRUE、なければFALSEを返す。
22 bool monster_is_powerful(MONSTER_IDX m_idx)
24 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
25 monster_race *r_ptr = &r_info[m_ptr->r_idx];
26 bool powerful = r_ptr->flags2 & RF2_POWERFUL ? TRUE : FALSE;
31 * @brief モンスターIDからモンスターのレベルを取得する(ただし最低1を保証する) /
32 * @param m_idx モンスターID
35 DEPTH monster_level_idx(MONSTER_IDX m_idx)
37 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
38 monster_race *r_ptr = &r_info[m_ptr->r_idx];
39 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
44 * @brief モンスターに与えたダメージの修正処理 /
45 * Modify the physical damage done to the monster.
46 * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
48 * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
49 * @return 修正を行った結果のダメージ量
52 * (for example when it's invulnerable or shielded)
53 * ToDo: Accept a damage-type to calculate the modified damage from
54 * things like fire, frost, lightning, poison, ... attacks.
55 * "type" is not yet used and should be 0.
58 HIT_POINT mon_damage_mod(monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
60 monster_race *r_ptr = &r_info[m_ptr->r_idx];
62 if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
65 if ((dam == 0) && one_in_(3)) dam = 1;
68 if (MON_INVULNER(m_ptr))
72 if (!p_ptr->blind && is_seen(m_ptr))
74 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
77 else if (!one_in_(PENETRATE_INVULNERABILITY))
88 * @brief モンスターに与えたダメージを元に経験値を加算する /
89 * Calculate experience point to be get
91 * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
95 * Even the 64 bit operation is not big enough to avoid overflaw
96 * unless we carefully choose orders of multiplication and division.
97 * Get the coefficient first, and multiply (potentially huge) base
98 * experience point of a monster later.
101 static void get_exp_from_mon(HIT_POINT dam, monster_type *m_ptr)
103 monster_race *r_ptr = &r_info[m_ptr->r_idx];
110 if (!monster_is_valid(m_ptr)) return;
111 if (is_pet(m_ptr) || p_ptr->inside_battle) return;
114 * - Ratio of monster's level to player's level effects
115 * - Varying speed effects
116 * - Get a fraction in proportion of damage point
118 new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
121 div_l = (p_ptr->max_plv + 2) * SPEED_TO_ENERGY(r_ptr->speed);
123 /* Use (average maxhp * 2) as a denominator */
124 if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
125 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
127 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
129 /* Special penalty in the wilderness */
130 if (!current_floor_ptr->dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
131 s64b_mul(&div_h, &div_l, 0, 5);
133 /* Do division first to prevent overflaw */
134 s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
136 /* Special penalty for mutiply-monster */
137 if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
139 int monnum_penarty = r_ptr->r_akills / 400;
140 if (monnum_penarty > 8) monnum_penarty = 8;
142 while (monnum_penarty--)
145 s64b_RSHIFT(new_exp, new_exp_frac, 2);
149 /* Special penalty for rest_and_shoot exp scum */
150 if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
152 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
153 if (over_damage > 32) over_damage = 32;
155 while (over_damage--)
158 s64b_mul(&new_exp, &new_exp_frac, 0, 9);
159 s64b_div(&new_exp, &new_exp_frac, 0, 10);
163 /* Finally multiply base experience point of the monster */
164 s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
166 /* Gain experience */
167 gain_exp_64(new_exp, new_exp_frac);
173 * @brief モンスターの時限ステータスを取得する
174 * @return m_idx モンスターの参照ID
175 * @return mproc_type モンスターの時限ステータスID
178 int get_mproc_idx(MONSTER_IDX m_idx, int mproc_type)
180 s16b *cur_mproc_list = current_floor_ptr->mproc_list[mproc_type];
183 for (i = current_floor_ptr->mproc_max[mproc_type] - 1; i >= 0; i--)
185 if (cur_mproc_list[i] == m_idx) return i;
192 * @brief モンスターの時限ステータスリストを追加する
193 * @return m_idx モンスターの参照ID
194 * @return mproc_type 追加したいモンスターの時限ステータスID
197 static void mproc_add(MONSTER_IDX m_idx, int mproc_type)
199 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;
204 * @brief モンスターの時限ステータスリストを削除
205 * @return m_idx モンスターの参照ID
206 * @return mproc_type 削除したいモンスターの時限ステータスID
209 static void mproc_remove(MONSTER_IDX m_idx, int mproc_type)
211 int mproc_idx = get_mproc_idx(m_idx, mproc_type);
212 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]];
217 * @brief モンスターの時限ステータスリストを初期化する / Initialize monster process
220 void mproc_init(void)
226 /* Reset "current_floor_ptr->mproc_max[]" */
227 for (cmi = 0; cmi < MAX_MTIMED; cmi++) current_floor_ptr->mproc_max[cmi] = 0;
229 /* Process the monsters (backwards) */
230 for (i = m_max - 1; i >= 1; i--)
232 /* Access the monster */
233 m_ptr = ¤t_floor_ptr->m_list[i];
235 /* Ignore "dead" monsters */
236 if (!monster_is_valid(m_ptr)) continue;
238 for (cmi = 0; cmi < MAX_MTIMED; cmi++)
240 if (m_ptr->mtimed[cmi]) mproc_add(i, cmi);
247 * @brief モンスターの睡眠状態値をセットする。0で起きる。 /
248 * Set "m_ptr->mtimed[MTIMED_CSLEEP]", notice observable changes
249 * @param m_idx モンスター参照ID
251 * @return 別途更新処理が必要な場合TRUEを返す
253 bool set_monster_csleep(MONSTER_IDX m_idx, int v)
255 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
257 v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
262 if (!MON_CSLEEP(m_ptr))
264 mproc_add(m_idx, MTIMED_CSLEEP);
272 if (MON_CSLEEP(m_ptr))
274 mproc_remove(m_idx, MTIMED_CSLEEP);
280 m_ptr->mtimed[MTIMED_CSLEEP] = (s16b)v;
282 if (!notice) return FALSE;
286 /* Update health bar as needed */
287 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
288 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
291 if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
298 * @brief モンスターの加速状態値をセット /
299 * Set "m_ptr->mtimed[MTIMED_FAST]", notice observable changes
300 * @param m_idx モンスター参照ID
302 * @return 別途更新処理が必要な場合TRUEを返す
304 bool set_monster_fast(MONSTER_IDX m_idx, int v)
306 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
308 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
313 if (!MON_FAST(m_ptr))
315 mproc_add(m_idx, MTIMED_FAST);
325 mproc_remove(m_idx, MTIMED_FAST);
331 m_ptr->mtimed[MTIMED_FAST] = (s16b)v;
333 if (!notice) return FALSE;
335 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
342 * Set "m_ptr->mtimed[MTIMED_SLOW]", notice observable changes
344 bool set_monster_slow(MONSTER_IDX m_idx, int v)
346 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
348 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
353 if (!MON_SLOW(m_ptr))
355 mproc_add(m_idx, MTIMED_SLOW);
365 mproc_remove(m_idx, MTIMED_SLOW);
371 m_ptr->mtimed[MTIMED_SLOW] = (s16b)v;
373 if (!notice) return FALSE;
375 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
382 * @brief モンスターの朦朧状態値をセット /
383 * Set "m_ptr->mtimed[MTIMED_STUNNED]", notice observable changes
384 * @param m_idx モンスター参照ID
386 * @return 別途更新処理が必要な場合TRUEを返す
388 bool set_monster_stunned(MONSTER_IDX m_idx, int v)
390 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
392 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
397 if (!MON_STUNNED(m_ptr))
399 mproc_add(m_idx, MTIMED_STUNNED);
407 if (MON_STUNNED(m_ptr))
409 mproc_remove(m_idx, MTIMED_STUNNED);
415 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)v;
422 * @brief モンスターの混乱状態値をセット /
423 * Set "m_ptr->mtimed[MTIMED_CONFUSED]", notice observable changes
424 * @param m_idx モンスター参照ID
426 * @return 別途更新処理が必要な場合TRUEを返す
428 bool set_monster_confused(MONSTER_IDX m_idx, int v)
430 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
432 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
437 if (!MON_CONFUSED(m_ptr))
439 mproc_add(m_idx, MTIMED_CONFUSED);
447 if (MON_CONFUSED(m_ptr))
449 mproc_remove(m_idx, MTIMED_CONFUSED);
455 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)v;
462 * @brief モンスターの恐慌状態値をセット /
463 * Set "m_ptr->mtimed[MTIMED_MONFEAR]", notice observable changes
464 * @param m_idx モンスター参照ID
466 * @return 別途更新処理が必要な場合TRUEを返す
468 bool set_monster_monfear(MONSTER_IDX m_idx, int v)
470 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
472 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
477 if (!MON_MONFEAR(m_ptr))
479 mproc_add(m_idx, MTIMED_MONFEAR);
487 if (MON_MONFEAR(m_ptr))
489 mproc_remove(m_idx, MTIMED_MONFEAR);
495 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)v;
497 if (!notice) return FALSE;
501 /* Update health bar as needed */
502 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
503 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
511 * @brief モンスターの無敵状態値をセット /
512 * Set "m_ptr->mtimed[MTIMED_INVULNER]", notice observable changes
513 * @param m_idx モンスター参照ID
515 * @param energy_need TRUEならば無敵解除時に行動ターン消費を行う
516 * @return 別途更新処理が必要な場合TRUEを返す
518 bool set_monster_invulner(MONSTER_IDX m_idx, int v, bool energy_need)
520 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
522 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
527 if (!MON_INVULNER(m_ptr))
529 mproc_add(m_idx, MTIMED_INVULNER);
537 if (MON_INVULNER(m_ptr))
539 mproc_remove(m_idx, MTIMED_INVULNER);
540 if (energy_need && !p_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
546 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)v;
548 if (!notice) return FALSE;
552 /* Update health bar as needed */
553 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
554 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
561 static u32b csleep_noise;
564 * @brief モンスターの各種状態値を時間経過により更新するサブルーチン
565 * @param m_idx モンスター参照ID
566 * @param mtimed_idx 更新するモンスターの時限ステータスID
569 static void process_monsters_mtimed_aux(MONSTER_IDX m_idx, int mtimed_idx)
571 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
577 monster_race *r_ptr = &r_info[m_ptr->r_idx];
579 /* Assume does not wake up */
582 /* Hack -- Require proximity */
583 if (m_ptr->cdis < AAF_LIMIT)
585 /* Handle "sensing radius" */
586 if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
592 /* Handle "sight" and "aggravation" */
593 else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(m_ptr->fy, m_ptr->fx)))
602 u32b notice = randint0(1024);
604 /* Nightmare monsters are more alert */
605 if (ironman_nightmare) notice /= 2;
607 /* Hack -- See if monster "notices" player */
608 if ((notice * notice * notice) <= csleep_noise)
610 /* Hack -- amount of "waking" */
611 /* Wake up faster near the player */
612 int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
614 /* Hack -- amount of "waking" is affected by speed of player */
615 d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
618 /* Monster wakes up "a little bit" */
621 if (!set_monster_csleep(m_idx, MON_CSLEEP(m_ptr) - d))
623 /* Notice the "not waking up" */
624 if (is_original_ap_and_seen(m_ptr))
626 /* Hack -- Count the ignores */
627 if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++;
634 /* Notice the "waking up" */
637 GAME_TEXT m_name[MAX_NLEN];
638 monster_desc(m_name, m_ptr, 0);
639 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
642 if (is_original_ap_and_seen(m_ptr))
644 /* Hack -- Count the wakings */
645 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
654 /* Reduce by one, note if expires */
655 if (set_monster_fast(m_idx, MON_FAST(m_ptr) - 1))
659 GAME_TEXT m_name[MAX_NLEN];
660 monster_desc(m_name, m_ptr, 0);
661 msg_format(_("%^sはもう加速されていない。", "%^s is no longer fast."), m_name);
667 /* Reduce by one, note if expires */
668 if (set_monster_slow(m_idx, MON_SLOW(m_ptr) - 1))
672 GAME_TEXT m_name[MAX_NLEN];
673 monster_desc(m_name, m_ptr, 0);
674 msg_format(_("%^sはもう減速されていない。", "%^s is no longer slow."), m_name);
681 int rlev = r_info[m_ptr->r_idx].level;
683 /* Recover from stun */
684 if (set_monster_stunned(m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
686 /* Message if visible */
689 GAME_TEXT m_name[MAX_NLEN];
690 monster_desc(m_name, m_ptr, 0);
691 msg_format(_("%^sは朦朧状態から立ち直った。", "%^s is no longer stunned."), m_name);
697 case MTIMED_CONFUSED:
698 /* Reduce the confusion */
699 if (set_monster_confused(m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
701 /* Message if visible */
704 GAME_TEXT m_name[MAX_NLEN];
705 monster_desc(m_name, m_ptr, 0);
706 msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name);
712 /* Reduce the fear */
713 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
718 GAME_TEXT m_name[MAX_NLEN];
722 /* Acquire the monster possessive */
723 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
725 monster_desc(m_name, m_ptr, 0);
727 msg_format("%^sは勇気を取り戻した。", m_name);
729 msg_format("%^s recovers %s courage.", m_name, m_poss);
735 case MTIMED_INVULNER:
736 /* Reduce by one, note if expires */
737 if (set_monster_invulner(m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
741 GAME_TEXT m_name[MAX_NLEN];
742 monster_desc(m_name, m_ptr, 0);
743 msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name);
752 * @brief 全モンスターの各種状態値を時間経過により更新するメインルーチン
753 * @param mtimed_idx 更新するモンスターの時限ステータスID
756 * Process the counters of monsters (once per 10 game turns)\n
757 * These functions are to process monsters' counters same as player's.
759 void process_monsters_mtimed(int mtimed_idx)
762 s16b *cur_mproc_list = current_floor_ptr->mproc_list[mtimed_idx];
764 /* Hack -- calculate the "player noise" */
765 if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - p_ptr->skill_stl));
767 /* Process the monsters (backwards) */
768 for (i = current_floor_ptr->mproc_max[mtimed_idx] - 1; i >= 0; i--)
770 /* Access the monster */
771 process_monsters_mtimed_aux(cur_mproc_list[i], mtimed_idx);
776 * @brief モンスターへの魔力消去処理
777 * @param m_idx 魔力消去を受けるモンスターの参照ID
780 void dispel_monster_status(MONSTER_IDX m_idx)
782 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
783 GAME_TEXT m_name[MAX_NLEN];
785 monster_desc(m_name, m_ptr, 0);
786 if (set_monster_invulner(m_idx, 0, TRUE))
788 if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name);
790 if (set_monster_fast(m_idx, 0))
792 if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name);
794 if (set_monster_slow(m_idx, 0))
796 if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name);
801 * @brief モンスターの時間停止処理
802 * @param num 時間停止を行った敵が行動できる回数
803 * @param who 時間停止処理の主体ID
804 * @param vs_player TRUEならば時間停止開始処理を行う
805 * @return 時間停止が行われている状態ならばTRUEを返す
807 bool set_monster_timewalk(int num, MONSTER_IDX who, bool vs_player)
809 monster_type *m_ptr = ¤t_floor_ptr->m_list[hack_m_idx]; /* the world monster */
811 if (current_world_ptr->timewalk_m_idx) return (FALSE);
815 GAME_TEXT m_name[MAX_NLEN];
816 monster_desc(m_name, m_ptr, 0);
819 msg_format(_("「『ザ・ワールド』!時は止まった!」", "%s yells 'The World! Time has stopped!'"), m_name);
821 msg_format(_("「時よ!」", "%s yells 'Time!'"), m_name);
822 else msg_print("hek!");
827 /* This monster cast spells */
828 current_world_ptr->timewalk_m_idx = hack_m_idx;
830 if (vs_player) do_cmd_redraw();
834 if (!monster_is_valid(m_ptr)) break;
835 process_monster(current_world_ptr->timewalk_m_idx);
839 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
842 p_ptr->redraw |= (PR_MAP);
843 p_ptr->update |= (PU_MONSTERS);
844 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
846 current_world_ptr->timewalk_m_idx = 0;
847 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)))
849 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
858 * @brief モンスターの経験値取得処理
859 * @param m_idx 経験値を得るモンスターの参照ID
860 * @param s_idx 撃破されたモンスター種族の参照ID
863 void monster_gain_exp(MONSTER_IDX m_idx, MONRACE_IDX s_idx)
869 if (m_idx <= 0 || s_idx <= 0) return;
871 m_ptr = ¤t_floor_ptr->m_list[m_idx];
873 if (!monster_is_valid(m_ptr)) return;
875 r_ptr = &r_info[m_ptr->r_idx];
876 s_ptr = &r_info[s_idx];
878 if (p_ptr->inside_battle) return;
880 if (!r_ptr->next_exp) return;
882 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
883 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
884 if (!current_floor_ptr->dun_level) new_exp /= 5;
885 m_ptr->exp += new_exp;
886 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
888 if (m_ptr->exp >= r_ptr->next_exp)
890 GAME_TEXT m_name[MAX_NLEN];
891 int old_hp = m_ptr->hp;
892 int old_maxhp = m_ptr->max_maxhp;
893 int old_r_idx = m_ptr->r_idx;
894 byte old_sub_align = m_ptr->sub_align;
896 /* Hack -- Reduce the racial counter of previous monster */
897 real_r_ptr(m_ptr)->cur_num--;
899 monster_desc(m_name, m_ptr, 0);
900 m_ptr->r_idx = r_ptr->next_r_idx;
902 /* Count the monsters on the level */
903 real_r_ptr(m_ptr)->cur_num++;
905 m_ptr->ap_r_idx = m_ptr->r_idx;
906 r_ptr = &r_info[m_ptr->r_idx];
908 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
910 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
914 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
916 if (ironman_nightmare)
918 HIT_POINT hp = m_ptr->max_maxhp * 2L;
919 m_ptr->max_maxhp = MIN(30000, hp);
921 m_ptr->maxhp = m_ptr->max_maxhp;
922 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
924 /* dealt damage is 0 at initial*/
925 m_ptr->dealt_damage = 0;
927 /* Extract the monster base speed */
928 m_ptr->mspeed = get_mspeed(r_ptr);
930 /* Sub-alignment of a monster */
931 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
932 m_ptr->sub_align = old_sub_align;
935 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
936 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
937 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
942 if (is_pet(m_ptr) || m_ptr->ml)
944 if (!ignore_unview || player_can_see_bold(m_ptr->fy, m_ptr->fx))
948 monster_race *hallu_race;
952 hallu_race = &r_info[randint1(max_r_idx - 1)];
953 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
954 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name);
958 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name);
962 if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
964 /* Now you feel very close to this pet. */
965 m_ptr->parent_m_idx = 0;
967 update_monster(m_idx, FALSE);
968 lite_spot(m_ptr->fy, m_ptr->fx);
970 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;
974 * @brief モンスターのHPをダメージに応じて減算する /
975 * Decreases monsters hit points, handling monster death.
976 * @param dam 与えたダメージ量
977 * @param m_idx ダメージを与えたモンスターのID
978 * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
979 * @param note モンスターが倒された際の特別なメッセージ述語
983 * We return TRUE if the monster has been killed (and deleted).
984 * We announce monster death (using an optional "death message"
985 * if given, and a otherwise a generic killed/destroyed message).
986 * Only "physical attacks" can induce the "You have slain" message.
987 * Missile and Spell attacks will induce the "dies" message, or
988 * various "specialized" messages. Note that "You have destroyed"
989 * and "is destroyed" are synonyms for "You have slain" and "dies".
990 * Hack -- unseen monsters yield "You have killed it." message.
991 * Added fear (DGK) and check whether to print fear messages -CWS
992 * Made name, sex, and capitalization generic -BEN-
993 * As always, the "ghost" processing is a total hack.
994 * Hack -- we "delay" fear messages by passing around a "fear" flag.
995 * Consider decreasing monster experience over time, say,
996 * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
997 * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
998 * monster worth more than subsequent monsters. This would also need
999 * to induce changes in the monster recall code.
1002 bool mon_take_hit(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
1004 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1005 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1006 monster_type exp_mon;
1008 /* Innocent until proven otherwise */
1009 bool innocent = TRUE, thief = FALSE;
1013 (void)COPY(&exp_mon, m_ptr, monster_type);
1015 expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
1017 get_exp_from_mon(expdam, &exp_mon);
1019 /* Genocided by chaos patron */
1020 if (!monster_is_valid(m_ptr)) m_idx = 0;
1022 /* Redraw (later) if needed */
1023 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1024 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1026 (void)set_monster_csleep(m_idx, 0);
1028 /* Hack - Cancel any special player stealth magics. -LM- */
1029 if (p_ptr->special_defense & NINJA_S_STEALTH)
1031 set_superstealth(FALSE);
1034 /* Genocided by chaos patron */
1035 if (!m_idx) return TRUE;
1038 m_ptr->dealt_damage += dam;
1040 if (m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
1044 msg_format(_("合計%d/%dのダメージを与えた。", "You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
1047 /* It is dead now */
1050 GAME_TEXT m_name[MAX_NLEN];
1052 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1054 /* You might have unmasked Tanuki first time */
1055 r_ptr = &r_info[m_ptr->r_idx];
1056 m_ptr->ap_r_idx = m_ptr->r_idx;
1057 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1060 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1062 /* You might have unmasked Chameleon first time */
1063 r_ptr = real_r_ptr(m_ptr);
1064 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1067 if (!(m_ptr->smart & SM_CLONED))
1069 /* When the player kills a Unique, it stays dead */
1070 if (r_ptr->flags1 & RF1_UNIQUE)
1074 /* Mega-Hack -- Banor & Lupart */
1075 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1077 r_info[MON_BANORLUPART].max_num = 0;
1078 r_info[MON_BANORLUPART].r_pkills++;
1079 r_info[MON_BANORLUPART].r_akills++;
1080 if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1082 else if (m_ptr->r_idx == MON_BANORLUPART)
1084 r_info[MON_BANOR].max_num = 0;
1085 r_info[MON_BANOR].r_pkills++;
1086 r_info[MON_BANOR].r_akills++;
1087 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1088 r_info[MON_LUPART].max_num = 0;
1089 r_info[MON_LUPART].r_pkills++;
1090 r_info[MON_LUPART].r_akills++;
1091 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1095 /* When the player kills a Nazgul, it stays dead */
1096 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1099 /* Count all monsters killed */
1100 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1102 /* Recall even invisible uniques or winners */
1103 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1105 /* Count kills this life */
1106 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1107 else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1109 /* Count kills in all lives */
1110 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1111 else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1113 /* Hack -- Auto-recall */
1114 monster_race_track(m_ptr->ap_r_idx);
1117 /* Extract monster name */
1118 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1120 /* Don't kill Amberites */
1121 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1123 int curses = 1 + randint1(3);
1124 bool stop_ty = FALSE;
1127 msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
1128 curse_equipment(100, 50);
1132 stop_ty = activate_ty_curse(stop_ty, &count);
1136 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1138 char line_got[1024];
1139 if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
1141 msg_format("%^s %s", m_name, line_got);
1145 if (m_ptr->r_idx == MON_SERPENT)
1147 screen_dump = make_screen_dump();
1152 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1154 if (!current_floor_ptr->dun_level && !p_ptr->ambush_flag && !p_ptr->inside_arena)
1156 chg_virtue(V_VALOUR, -1);
1158 else if (r_ptr->level > current_floor_ptr->dun_level)
1160 if (randint1(10) <= (r_ptr->level - current_floor_ptr->dun_level))
1161 chg_virtue(V_VALOUR, 1);
1163 if (r_ptr->level > 60)
1165 chg_virtue(V_VALOUR, 1);
1167 if (r_ptr->level >= 2 * (p_ptr->lev + 1))
1168 chg_virtue(V_VALOUR, 2);
1171 if (r_ptr->flags1 & RF1_UNIQUE)
1173 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
1175 if (r_ptr->flags3 & RF3_GOOD)
1177 chg_virtue(V_UNLIFE, 2);
1178 chg_virtue(V_VITALITY, -2);
1181 if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
1184 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1186 chg_virtue(V_COMPASSION, -1);
1189 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100)))
1190 chg_virtue(V_UNLIFE, 1);
1192 if (r_ptr->d_char == 'A')
1194 if (r_ptr->flags1 & RF1_UNIQUE)
1195 chg_virtue(V_FAITH, -2);
1196 else if ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100))
1198 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
1199 else chg_virtue(V_FAITH, 1);
1202 else if (r_ptr->flags3 & RF3_DEMON)
1204 if (r_ptr->flags1 & RF1_UNIQUE)
1205 chg_virtue(V_FAITH, 2);
1206 else if ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100))
1207 chg_virtue(V_FAITH, 1);
1210 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1211 chg_virtue(V_VITALITY, 2);
1213 if (r_ptr->r_deaths)
1215 if (r_ptr->flags1 & RF1_UNIQUE)
1217 chg_virtue(V_HONOUR, 10);
1219 else if ((r_ptr->level) / 10 + (2 * current_floor_ptr->dun_level) >= randint1(100))
1221 chg_virtue(V_HONOUR, 1);
1224 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1226 chg_virtue(V_VALOUR, -1);
1229 for (i = 0; i < 4; i++)
1231 if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1233 if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1234 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1236 thief = TRUE; /* Thief! */
1239 /* The new law says it is illegal to live in the dungeon */
1240 if (r_ptr->level != 0) innocent = FALSE;
1244 if (r_ptr->flags1 & RF1_UNIQUE)
1245 chg_virtue(V_JUSTICE, 3);
1246 else if (1 + ((r_ptr->level) / 10 + (2 * current_floor_ptr->dun_level)) >= randint1(100))
1247 chg_virtue(V_JUSTICE, 1);
1251 chg_virtue(V_JUSTICE, -1);
1254 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)))
1256 if (one_in_(4)) chg_virtue(V_NATURE, -1);
1259 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1262 sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
1263 do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
1269 /* Death by Missile/Spell attack */
1272 msg_format("%^s%s", m_name, note);
1275 /* Death by physical attack -- invisible monster */
1276 else if (!m_ptr->ml)
1279 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1280 msg_format("せっかくだから%sを殺した。", m_name);
1282 msg_format("%sを殺した。", m_name);
1284 msg_format("You have killed %s.", m_name);
1289 /* Death by Physical attack -- non-living monster */
1290 else if (!monster_living(m_ptr->r_idx))
1292 bool explode = FALSE;
1294 for (i = 0; i < 4; i++)
1296 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1299 /* Special note at death */
1301 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
1305 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1306 msg_format("せっかくだから%sを倒した。", m_name);
1308 msg_format("%sを倒した。", m_name);
1310 msg_format("You have destroyed %s.", m_name);
1315 /* Death by Physical attack -- living monster */
1319 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1320 msg_format("せっかくだから%sを葬り去った。", m_name);
1322 msg_format("%sを葬り去った。", m_name);
1324 msg_format("You have slain %s.", m_name);
1328 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
1330 for (i = 0; i < MAX_KUBI; i++)
1332 if ((current_world_ptr->bounty_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
1334 msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1340 /* Generate treasure */
1341 monster_death(m_idx, TRUE);
1343 /* Mega hack : replace IKETA to BIKETAL */
1344 if ((m_ptr->r_idx == MON_IKETA) && !(p_ptr->inside_arena || p_ptr->inside_battle))
1346 POSITION dummy_y = m_ptr->fy;
1347 POSITION dummy_x = m_ptr->fx;
1348 BIT_FLAGS mode = 0L;
1349 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1350 delete_monster_idx(m_idx);
1351 if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1353 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha! *I* am Biketal!"));
1358 delete_monster_idx(m_idx);
1361 get_exp_from_mon((long)exp_mon.max_maxhp * 2, &exp_mon);
1366 /* Monster is dead */
1373 /* Mega-Hack -- Pain cancels fear */
1374 if (MON_MONFEAR(m_ptr) && (dam > 0))
1377 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1384 /* Sometimes a monster gets scared by damage */
1385 if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1387 /* Percentage of fully healthy */
1388 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1391 * Run (sometimes) if at 10% or less of max hit points,
1392 * or (usually) when hit for half its current hit points
1394 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1396 /* Hack -- note fear */
1399 /* Hack -- Add some timed fear */
1400 (void)set_monster_monfear(m_idx, (randint1(10) +
1401 (((dam >= m_ptr->hp) && (percentage > 7)) ?
1402 20 : ((11 - percentage) * 5))));
1412 bool monster_is_valid(monster_type *m_ptr)
1414 return (m_ptr->r_idx != 0);