7 #include "monster-status.h"
8 #include "monster-spell.h"
9 #include "monster-process.h"
10 #include "spells-summon.h"
11 #include "monsterrace-hook.h"
12 #include "object-curse.h"
16 #include "player-effects.h"
20 * @brief モンスターIDからPOWERFULフラグの有無を取得する /
21 * @param m_idx モンスターID
22 * @return POWERFULフラグがあればTRUE、なければFALSEを返す。
24 bool monster_is_powerful(MONSTER_IDX m_idx)
26 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
27 monster_race *r_ptr = &r_info[m_ptr->r_idx];
28 bool powerful = r_ptr->flags2 & RF2_POWERFUL ? TRUE : FALSE;
33 * @brief モンスターIDからモンスターのレベルを取得する(ただし最低1を保証する) /
34 * @param m_idx モンスターID
37 DEPTH monster_level_idx(MONSTER_IDX m_idx)
39 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
40 monster_race *r_ptr = &r_info[m_ptr->r_idx];
41 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
46 * @brief モンスターに与えたダメージの修正処理 /
47 * Modify the physical damage done to the monster.
48 * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
50 * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
51 * @return 修正を行った結果のダメージ量
54 * (for example when it's invulnerable or shielded)
55 * ToDo: Accept a damage-type to calculate the modified damage from
56 * things like fire, frost, lightning, poison, ... attacks.
57 * "type" is not yet used and should be 0.
60 HIT_POINT mon_damage_mod(monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
62 monster_race *r_ptr = &r_info[m_ptr->r_idx];
64 if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
67 if ((dam == 0) && one_in_(3)) dam = 1;
70 if (MON_INVULNER(m_ptr))
74 if (!p_ptr->blind && is_seen(m_ptr))
76 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
79 else if (!one_in_(PENETRATE_INVULNERABILITY))
90 * @brief モンスターに与えたダメージを元に経験値を加算する /
91 * Calculate experience point to be get
93 * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
97 * Even the 64 bit operation is not big enough to avoid overflaw
98 * unless we carefully choose orders of multiplication and division.
99 * Get the coefficient first, and multiply (potentially huge) base
100 * experience point of a monster later.
103 static void get_exp_from_mon(HIT_POINT dam, monster_type *m_ptr)
105 monster_race *r_ptr = &r_info[m_ptr->r_idx];
112 if (!monster_is_valid(m_ptr)) return;
113 if (is_pet(m_ptr) || p_ptr->inside_battle) return;
116 * - Ratio of monster's level to player's level effects
117 * - Varying speed effects
118 * - Get a fraction in proportion of damage point
120 new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
123 div_l = (p_ptr->max_plv + 2) * SPEED_TO_ENERGY(r_ptr->speed);
125 /* Use (average maxhp * 2) as a denominator */
126 if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
127 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
129 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
131 /* Special penalty in the wilderness */
132 if (!current_floor_ptr->dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
133 s64b_mul(&div_h, &div_l, 0, 5);
135 /* Do division first to prevent overflaw */
136 s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
138 /* Special penalty for mutiply-monster */
139 if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
141 int monnum_penarty = r_ptr->r_akills / 400;
142 if (monnum_penarty > 8) monnum_penarty = 8;
144 while (monnum_penarty--)
147 s64b_RSHIFT(new_exp, new_exp_frac, 2);
151 /* Special penalty for rest_and_shoot exp scum */
152 if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
154 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
155 if (over_damage > 32) over_damage = 32;
157 while (over_damage--)
160 s64b_mul(&new_exp, &new_exp_frac, 0, 9);
161 s64b_div(&new_exp, &new_exp_frac, 0, 10);
165 /* Finally multiply base experience point of the monster */
166 s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
168 /* Gain experience */
169 gain_exp_64(new_exp, new_exp_frac);
175 * @brief モンスターの時限ステータスを取得する
176 * @return m_idx モンスターの参照ID
177 * @return mproc_type モンスターの時限ステータスID
180 int get_mproc_idx(MONSTER_IDX m_idx, int mproc_type)
182 s16b *cur_mproc_list = current_floor_ptr->mproc_list[mproc_type];
185 for (i = current_floor_ptr->mproc_max[mproc_type] - 1; i >= 0; i--)
187 if (cur_mproc_list[i] == m_idx) return i;
194 * @brief モンスターの時限ステータスリストを追加する
195 * @return m_idx モンスターの参照ID
196 * @return mproc_type 追加したいモンスターの時限ステータスID
199 static void mproc_add(MONSTER_IDX m_idx, int mproc_type)
201 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;
206 * @brief モンスターの時限ステータスリストを削除
207 * @return m_idx モンスターの参照ID
208 * @return mproc_type 削除したいモンスターの時限ステータスID
211 static void mproc_remove(MONSTER_IDX m_idx, int mproc_type)
213 int mproc_idx = get_mproc_idx(m_idx, mproc_type);
214 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]];
219 * @brief モンスターの時限ステータスリストを初期化する / Initialize monster process
222 void mproc_init(void)
228 /* Reset "current_floor_ptr->mproc_max[]" */
229 for (cmi = 0; cmi < MAX_MTIMED; cmi++) current_floor_ptr->mproc_max[cmi] = 0;
231 /* Process the monsters (backwards) */
232 for (i = m_max - 1; i >= 1; i--)
234 /* Access the monster */
235 m_ptr = ¤t_floor_ptr->m_list[i];
237 /* Ignore "dead" monsters */
238 if (!monster_is_valid(m_ptr)) continue;
240 for (cmi = 0; cmi < MAX_MTIMED; cmi++)
242 if (m_ptr->mtimed[cmi]) mproc_add(i, cmi);
249 * @brief モンスターの睡眠状態値をセットする。0で起きる。 /
250 * Set "m_ptr->mtimed[MTIMED_CSLEEP]", notice observable changes
251 * @param m_idx モンスター参照ID
253 * @return 別途更新処理が必要な場合TRUEを返す
255 bool set_monster_csleep(MONSTER_IDX m_idx, int v)
257 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
259 v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
264 if (!MON_CSLEEP(m_ptr))
266 mproc_add(m_idx, MTIMED_CSLEEP);
274 if (MON_CSLEEP(m_ptr))
276 mproc_remove(m_idx, MTIMED_CSLEEP);
282 m_ptr->mtimed[MTIMED_CSLEEP] = (s16b)v;
284 if (!notice) return FALSE;
288 /* Update health bar as needed */
289 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
290 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
293 if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
300 * @brief モンスターの加速状態値をセット /
301 * Set "m_ptr->mtimed[MTIMED_FAST]", notice observable changes
302 * @param m_idx モンスター参照ID
304 * @return 別途更新処理が必要な場合TRUEを返す
306 bool set_monster_fast(MONSTER_IDX m_idx, int v)
308 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
310 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
315 if (!MON_FAST(m_ptr))
317 mproc_add(m_idx, MTIMED_FAST);
327 mproc_remove(m_idx, MTIMED_FAST);
333 m_ptr->mtimed[MTIMED_FAST] = (s16b)v;
335 if (!notice) return FALSE;
337 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
344 * Set "m_ptr->mtimed[MTIMED_SLOW]", notice observable changes
346 bool set_monster_slow(MONSTER_IDX m_idx, int v)
348 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
350 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
355 if (!MON_SLOW(m_ptr))
357 mproc_add(m_idx, MTIMED_SLOW);
367 mproc_remove(m_idx, MTIMED_SLOW);
373 m_ptr->mtimed[MTIMED_SLOW] = (s16b)v;
375 if (!notice) return FALSE;
377 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
384 * @brief モンスターの朦朧状態値をセット /
385 * Set "m_ptr->mtimed[MTIMED_STUNNED]", notice observable changes
386 * @param m_idx モンスター参照ID
388 * @return 別途更新処理が必要な場合TRUEを返す
390 bool set_monster_stunned(MONSTER_IDX m_idx, int v)
392 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
394 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
399 if (!MON_STUNNED(m_ptr))
401 mproc_add(m_idx, MTIMED_STUNNED);
409 if (MON_STUNNED(m_ptr))
411 mproc_remove(m_idx, MTIMED_STUNNED);
417 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)v;
424 * @brief モンスターの混乱状態値をセット /
425 * Set "m_ptr->mtimed[MTIMED_CONFUSED]", notice observable changes
426 * @param m_idx モンスター参照ID
428 * @return 別途更新処理が必要な場合TRUEを返す
430 bool set_monster_confused(MONSTER_IDX m_idx, int v)
432 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
434 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
439 if (!MON_CONFUSED(m_ptr))
441 mproc_add(m_idx, MTIMED_CONFUSED);
449 if (MON_CONFUSED(m_ptr))
451 mproc_remove(m_idx, MTIMED_CONFUSED);
457 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)v;
464 * @brief モンスターの恐慌状態値をセット /
465 * Set "m_ptr->mtimed[MTIMED_MONFEAR]", notice observable changes
466 * @param m_idx モンスター参照ID
468 * @return 別途更新処理が必要な場合TRUEを返す
470 bool set_monster_monfear(MONSTER_IDX m_idx, int v)
472 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
474 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
479 if (!MON_MONFEAR(m_ptr))
481 mproc_add(m_idx, MTIMED_MONFEAR);
489 if (MON_MONFEAR(m_ptr))
491 mproc_remove(m_idx, MTIMED_MONFEAR);
497 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)v;
499 if (!notice) return FALSE;
503 /* Update health bar as needed */
504 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
505 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
513 * @brief モンスターの無敵状態値をセット /
514 * Set "m_ptr->mtimed[MTIMED_INVULNER]", notice observable changes
515 * @param m_idx モンスター参照ID
517 * @param energy_need TRUEならば無敵解除時に行動ターン消費を行う
518 * @return 別途更新処理が必要な場合TRUEを返す
520 bool set_monster_invulner(MONSTER_IDX m_idx, int v, bool energy_need)
522 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
524 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
529 if (!MON_INVULNER(m_ptr))
531 mproc_add(m_idx, MTIMED_INVULNER);
539 if (MON_INVULNER(m_ptr))
541 mproc_remove(m_idx, MTIMED_INVULNER);
542 if (energy_need && !p_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
548 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)v;
550 if (!notice) return FALSE;
554 /* Update health bar as needed */
555 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
556 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
563 static u32b csleep_noise;
566 * @brief モンスターの各種状態値を時間経過により更新するサブルーチン
567 * @param m_idx モンスター参照ID
568 * @param mtimed_idx 更新するモンスターの時限ステータスID
571 static void process_monsters_mtimed_aux(MONSTER_IDX m_idx, int mtimed_idx)
573 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
579 monster_race *r_ptr = &r_info[m_ptr->r_idx];
581 /* Assume does not wake up */
584 /* Hack -- Require proximity */
585 if (m_ptr->cdis < AAF_LIMIT)
587 /* Handle "sensing radius" */
588 if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
594 /* Handle "sight" and "aggravation" */
595 else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(m_ptr->fy, m_ptr->fx)))
604 u32b notice = randint0(1024);
606 /* Nightmare monsters are more alert */
607 if (ironman_nightmare) notice /= 2;
609 /* Hack -- See if monster "notices" player */
610 if ((notice * notice * notice) <= csleep_noise)
612 /* Hack -- amount of "waking" */
613 /* Wake up faster near the player */
614 int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
616 /* Hack -- amount of "waking" is affected by speed of player */
617 d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
620 /* Monster wakes up "a little bit" */
623 if (!set_monster_csleep(m_idx, MON_CSLEEP(m_ptr) - d))
625 /* Notice the "not waking up" */
626 if (is_original_ap_and_seen(m_ptr))
628 /* Hack -- Count the ignores */
629 if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++;
636 /* Notice the "waking up" */
639 GAME_TEXT m_name[MAX_NLEN];
640 monster_desc(m_name, m_ptr, 0);
641 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
644 if (is_original_ap_and_seen(m_ptr))
646 /* Hack -- Count the wakings */
647 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
656 /* Reduce by one, note if expires */
657 if (set_monster_fast(m_idx, MON_FAST(m_ptr) - 1))
661 GAME_TEXT m_name[MAX_NLEN];
662 monster_desc(m_name, m_ptr, 0);
663 msg_format(_("%^sはもう加速されていない。", "%^s is no longer fast."), m_name);
669 /* Reduce by one, note if expires */
670 if (set_monster_slow(m_idx, MON_SLOW(m_ptr) - 1))
674 GAME_TEXT m_name[MAX_NLEN];
675 monster_desc(m_name, m_ptr, 0);
676 msg_format(_("%^sはもう減速されていない。", "%^s is no longer slow."), m_name);
683 int rlev = r_info[m_ptr->r_idx].level;
685 /* Recover from stun */
686 if (set_monster_stunned(m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
688 /* Message if visible */
691 GAME_TEXT m_name[MAX_NLEN];
692 monster_desc(m_name, m_ptr, 0);
693 msg_format(_("%^sは朦朧状態から立ち直った。", "%^s is no longer stunned."), m_name);
699 case MTIMED_CONFUSED:
700 /* Reduce the confusion */
701 if (set_monster_confused(m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
703 /* Message if visible */
706 GAME_TEXT m_name[MAX_NLEN];
707 monster_desc(m_name, m_ptr, 0);
708 msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name);
714 /* Reduce the fear */
715 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
720 GAME_TEXT m_name[MAX_NLEN];
724 /* Acquire the monster possessive */
725 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
727 monster_desc(m_name, m_ptr, 0);
729 msg_format("%^sは勇気を取り戻した。", m_name);
731 msg_format("%^s recovers %s courage.", m_name, m_poss);
737 case MTIMED_INVULNER:
738 /* Reduce by one, note if expires */
739 if (set_monster_invulner(m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
743 GAME_TEXT m_name[MAX_NLEN];
744 monster_desc(m_name, m_ptr, 0);
745 msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name);
754 * @brief 全モンスターの各種状態値を時間経過により更新するメインルーチン
755 * @param mtimed_idx 更新するモンスターの時限ステータスID
758 * Process the counters of monsters (once per 10 game turns)\n
759 * These functions are to process monsters' counters same as player's.
761 void process_monsters_mtimed(int mtimed_idx)
764 s16b *cur_mproc_list = current_floor_ptr->mproc_list[mtimed_idx];
766 /* Hack -- calculate the "player noise" */
767 if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - p_ptr->skill_stl));
769 /* Process the monsters (backwards) */
770 for (i = current_floor_ptr->mproc_max[mtimed_idx] - 1; i >= 0; i--)
772 /* Access the monster */
773 process_monsters_mtimed_aux(cur_mproc_list[i], mtimed_idx);
778 * @brief モンスターへの魔力消去処理
779 * @param m_idx 魔力消去を受けるモンスターの参照ID
782 void dispel_monster_status(MONSTER_IDX m_idx)
784 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
785 GAME_TEXT m_name[MAX_NLEN];
787 monster_desc(m_name, m_ptr, 0);
788 if (set_monster_invulner(m_idx, 0, TRUE))
790 if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name);
792 if (set_monster_fast(m_idx, 0))
794 if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name);
796 if (set_monster_slow(m_idx, 0))
798 if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name);
803 * @brief モンスターの時間停止処理
804 * @param num 時間停止を行った敵が行動できる回数
805 * @param who 時間停止処理の主体ID
806 * @param vs_player TRUEならば時間停止開始処理を行う
807 * @return 時間停止が行われている状態ならばTRUEを返す
809 bool set_monster_timewalk(int num, MONSTER_IDX who, bool vs_player)
811 monster_type *m_ptr = ¤t_floor_ptr->m_list[hack_m_idx]; /* the world monster */
813 if (current_world_ptr->timewalk_m_idx) return (FALSE);
817 GAME_TEXT m_name[MAX_NLEN];
818 monster_desc(m_name, m_ptr, 0);
821 msg_format(_("「『ザ・ワールド』!時は止まった!」", "%s yells 'The World! Time has stopped!'"), m_name);
823 msg_format(_("「時よ!」", "%s yells 'Time!'"), m_name);
824 else msg_print("hek!");
829 /* This monster cast spells */
830 current_world_ptr->timewalk_m_idx = hack_m_idx;
832 if (vs_player) do_cmd_redraw();
836 if (!monster_is_valid(m_ptr)) break;
837 process_monster(current_world_ptr->timewalk_m_idx);
841 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
844 p_ptr->redraw |= (PR_MAP);
845 p_ptr->update |= (PU_MONSTERS);
846 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
848 current_world_ptr->timewalk_m_idx = 0;
849 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)))
851 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
860 * @brief モンスターの経験値取得処理
861 * @param m_idx 経験値を得るモンスターの参照ID
862 * @param s_idx 撃破されたモンスター種族の参照ID
865 void monster_gain_exp(MONSTER_IDX m_idx, MONRACE_IDX s_idx)
871 if (m_idx <= 0 || s_idx <= 0) return;
873 m_ptr = ¤t_floor_ptr->m_list[m_idx];
875 if (!monster_is_valid(m_ptr)) return;
877 r_ptr = &r_info[m_ptr->r_idx];
878 s_ptr = &r_info[s_idx];
880 if (p_ptr->inside_battle) return;
882 if (!r_ptr->next_exp) return;
884 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
885 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
886 if (!current_floor_ptr->dun_level) new_exp /= 5;
887 m_ptr->exp += new_exp;
888 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
890 if (m_ptr->exp >= r_ptr->next_exp)
892 GAME_TEXT m_name[MAX_NLEN];
893 int old_hp = m_ptr->hp;
894 int old_maxhp = m_ptr->max_maxhp;
895 int old_r_idx = m_ptr->r_idx;
896 byte old_sub_align = m_ptr->sub_align;
898 /* Hack -- Reduce the racial counter of previous monster */
899 real_r_ptr(m_ptr)->cur_num--;
901 monster_desc(m_name, m_ptr, 0);
902 m_ptr->r_idx = r_ptr->next_r_idx;
904 /* Count the monsters on the level */
905 real_r_ptr(m_ptr)->cur_num++;
907 m_ptr->ap_r_idx = m_ptr->r_idx;
908 r_ptr = &r_info[m_ptr->r_idx];
910 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
912 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
916 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
918 if (ironman_nightmare)
920 HIT_POINT hp = m_ptr->max_maxhp * 2L;
921 m_ptr->max_maxhp = MIN(30000, hp);
923 m_ptr->maxhp = m_ptr->max_maxhp;
924 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
926 /* dealt damage is 0 at initial*/
927 m_ptr->dealt_damage = 0;
929 /* Extract the monster base speed */
930 m_ptr->mspeed = get_mspeed(r_ptr);
932 /* Sub-alignment of a monster */
933 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
934 m_ptr->sub_align = old_sub_align;
937 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
938 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
939 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
944 if (is_pet(m_ptr) || m_ptr->ml)
946 if (!ignore_unview || player_can_see_bold(m_ptr->fy, m_ptr->fx))
950 monster_race *hallu_race;
954 hallu_race = &r_info[randint1(max_r_idx - 1)];
955 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
956 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name);
960 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name);
964 if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
966 /* Now you feel very close to this pet. */
967 m_ptr->parent_m_idx = 0;
969 update_monster(m_idx, FALSE);
970 lite_spot(m_ptr->fy, m_ptr->fx);
972 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;
976 * @brief モンスターのHPをダメージに応じて減算する /
977 * Decreases monsters hit points, handling monster death.
978 * @param dam 与えたダメージ量
979 * @param m_idx ダメージを与えたモンスターのID
980 * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
981 * @param note モンスターが倒された際の特別なメッセージ述語
985 * We return TRUE if the monster has been killed (and deleted).
986 * We announce monster death (using an optional "death message"
987 * if given, and a otherwise a generic killed/destroyed message).
988 * Only "physical attacks" can induce the "You have slain" message.
989 * Missile and Spell attacks will induce the "dies" message, or
990 * various "specialized" messages. Note that "You have destroyed"
991 * and "is destroyed" are synonyms for "You have slain" and "dies".
992 * Hack -- unseen monsters yield "You have killed it." message.
993 * Added fear (DGK) and check whether to print fear messages -CWS
994 * Made name, sex, and capitalization generic -BEN-
995 * As always, the "ghost" processing is a total hack.
996 * Hack -- we "delay" fear messages by passing around a "fear" flag.
997 * Consider decreasing monster experience over time, say,
998 * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
999 * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
1000 * monster worth more than subsequent monsters. This would also need
1001 * to induce changes in the monster recall code.
1004 bool mon_take_hit(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
1006 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1007 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1008 monster_type exp_mon;
1010 /* Innocent until proven otherwise */
1011 bool innocent = TRUE, thief = FALSE;
1015 (void)COPY(&exp_mon, m_ptr, monster_type);
1017 expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
1019 get_exp_from_mon(expdam, &exp_mon);
1021 /* Genocided by chaos patron */
1022 if (!monster_is_valid(m_ptr)) m_idx = 0;
1024 /* Redraw (later) if needed */
1025 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1026 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1028 (void)set_monster_csleep(m_idx, 0);
1030 /* Hack - Cancel any special player stealth magics. -LM- */
1031 if (p_ptr->special_defense & NINJA_S_STEALTH)
1033 set_superstealth(FALSE);
1036 /* Genocided by chaos patron */
1037 if (!m_idx) return TRUE;
1040 m_ptr->dealt_damage += dam;
1042 if (m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
1046 msg_format(_("合計%d/%dのダメージを与えた。", "You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
1049 /* It is dead now */
1052 GAME_TEXT m_name[MAX_NLEN];
1054 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1056 /* You might have unmasked Tanuki first time */
1057 r_ptr = &r_info[m_ptr->r_idx];
1058 m_ptr->ap_r_idx = m_ptr->r_idx;
1059 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1062 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1064 /* You might have unmasked Chameleon first time */
1065 r_ptr = real_r_ptr(m_ptr);
1066 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1069 if (!(m_ptr->smart & SM_CLONED))
1071 /* When the player kills a Unique, it stays dead */
1072 if (r_ptr->flags1 & RF1_UNIQUE)
1076 /* Mega-Hack -- Banor & Lupart */
1077 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1079 r_info[MON_BANORLUPART].max_num = 0;
1080 r_info[MON_BANORLUPART].r_pkills++;
1081 r_info[MON_BANORLUPART].r_akills++;
1082 if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1084 else if (m_ptr->r_idx == MON_BANORLUPART)
1086 r_info[MON_BANOR].max_num = 0;
1087 r_info[MON_BANOR].r_pkills++;
1088 r_info[MON_BANOR].r_akills++;
1089 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1090 r_info[MON_LUPART].max_num = 0;
1091 r_info[MON_LUPART].r_pkills++;
1092 r_info[MON_LUPART].r_akills++;
1093 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1097 /* When the player kills a Nazgul, it stays dead */
1098 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1101 /* Count all monsters killed */
1102 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1104 /* Recall even invisible uniques or winners */
1105 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1107 /* Count kills this life */
1108 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1109 else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1111 /* Count kills in all lives */
1112 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1113 else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1115 /* Hack -- Auto-recall */
1116 monster_race_track(m_ptr->ap_r_idx);
1119 /* Extract monster name */
1120 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1122 /* Don't kill Amberites */
1123 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1125 int curses = 1 + randint1(3);
1126 bool stop_ty = FALSE;
1129 msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
1130 curse_equipment(100, 50);
1134 stop_ty = activate_ty_curse(stop_ty, &count);
1138 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1140 char line_got[1024];
1141 if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
1143 msg_format("%^s %s", m_name, line_got);
1147 if (m_ptr->r_idx == MON_SERPENT)
1149 screen_dump = make_screen_dump();
1154 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1156 if (!current_floor_ptr->dun_level && !p_ptr->ambush_flag && !p_ptr->inside_arena)
1158 chg_virtue(V_VALOUR, -1);
1160 else if (r_ptr->level > current_floor_ptr->dun_level)
1162 if (randint1(10) <= (r_ptr->level - current_floor_ptr->dun_level))
1163 chg_virtue(V_VALOUR, 1);
1165 if (r_ptr->level > 60)
1167 chg_virtue(V_VALOUR, 1);
1169 if (r_ptr->level >= 2 * (p_ptr->lev + 1))
1170 chg_virtue(V_VALOUR, 2);
1173 if (r_ptr->flags1 & RF1_UNIQUE)
1175 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
1177 if (r_ptr->flags3 & RF3_GOOD)
1179 chg_virtue(V_UNLIFE, 2);
1180 chg_virtue(V_VITALITY, -2);
1183 if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
1186 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1188 chg_virtue(V_COMPASSION, -1);
1191 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100)))
1192 chg_virtue(V_UNLIFE, 1);
1194 if (r_ptr->d_char == 'A')
1196 if (r_ptr->flags1 & RF1_UNIQUE)
1197 chg_virtue(V_FAITH, -2);
1198 else if ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100))
1200 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
1201 else chg_virtue(V_FAITH, 1);
1204 else if (r_ptr->flags3 & RF3_DEMON)
1206 if (r_ptr->flags1 & RF1_UNIQUE)
1207 chg_virtue(V_FAITH, 2);
1208 else if ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100))
1209 chg_virtue(V_FAITH, 1);
1212 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1213 chg_virtue(V_VITALITY, 2);
1215 if (r_ptr->r_deaths)
1217 if (r_ptr->flags1 & RF1_UNIQUE)
1219 chg_virtue(V_HONOUR, 10);
1221 else if ((r_ptr->level) / 10 + (2 * current_floor_ptr->dun_level) >= randint1(100))
1223 chg_virtue(V_HONOUR, 1);
1226 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1228 chg_virtue(V_VALOUR, -1);
1231 for (i = 0; i < 4; i++)
1233 if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1235 if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1236 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1238 thief = TRUE; /* Thief! */
1241 /* The new law says it is illegal to live in the dungeon */
1242 if (r_ptr->level != 0) innocent = FALSE;
1246 if (r_ptr->flags1 & RF1_UNIQUE)
1247 chg_virtue(V_JUSTICE, 3);
1248 else if (1 + ((r_ptr->level) / 10 + (2 * current_floor_ptr->dun_level)) >= randint1(100))
1249 chg_virtue(V_JUSTICE, 1);
1253 chg_virtue(V_JUSTICE, -1);
1256 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)))
1258 if (one_in_(4)) chg_virtue(V_NATURE, -1);
1261 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1264 sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
1265 do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
1271 /* Death by Missile/Spell attack */
1274 msg_format("%^s%s", m_name, note);
1277 /* Death by physical attack -- invisible monster */
1278 else if (!m_ptr->ml)
1281 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1282 msg_format("せっかくだから%sを殺した。", m_name);
1284 msg_format("%sを殺した。", m_name);
1286 msg_format("You have killed %s.", m_name);
1291 /* Death by Physical attack -- non-living monster */
1292 else if (!monster_living(m_ptr->r_idx))
1294 bool explode = FALSE;
1296 for (i = 0; i < 4; i++)
1298 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1301 /* Special note at death */
1303 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
1307 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1308 msg_format("せっかくだから%sを倒した。", m_name);
1310 msg_format("%sを倒した。", m_name);
1312 msg_format("You have destroyed %s.", m_name);
1317 /* Death by Physical attack -- living monster */
1321 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1322 msg_format("せっかくだから%sを葬り去った。", m_name);
1324 msg_format("%sを葬り去った。", m_name);
1326 msg_format("You have slain %s.", m_name);
1330 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
1332 for (i = 0; i < MAX_KUBI; i++)
1334 if ((current_world_ptr->bounty_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
1336 msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1342 /* Generate treasure */
1343 monster_death(m_idx, TRUE);
1345 /* Mega hack : replace IKETA to BIKETAL */
1346 if ((m_ptr->r_idx == MON_IKETA) && !(p_ptr->inside_arena || p_ptr->inside_battle))
1348 POSITION dummy_y = m_ptr->fy;
1349 POSITION dummy_x = m_ptr->fx;
1350 BIT_FLAGS mode = 0L;
1351 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1352 delete_monster_idx(m_idx);
1353 if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1355 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha! *I* am Biketal!"));
1360 delete_monster_idx(m_idx);
1363 get_exp_from_mon((long)exp_mon.max_maxhp * 2, &exp_mon);
1368 /* Monster is dead */
1375 /* Mega-Hack -- Pain cancels fear */
1376 if (MON_MONFEAR(m_ptr) && (dam > 0))
1379 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1386 /* Sometimes a monster gets scared by damage */
1387 if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1389 /* Percentage of fully healthy */
1390 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1393 * Run (sometimes) if at 10% or less of max hit points,
1394 * or (usually) when hit for half its current hit points
1396 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1398 /* Hack -- note fear */
1401 /* Hack -- Add some timed fear */
1402 (void)set_monster_monfear(m_idx, (randint1(10) +
1403 (((dam >= m_ptr->hp) && (percentage > 7)) ?
1404 20 : ((11 - percentage) * 5))));
1414 bool monster_is_valid(monster_type *m_ptr)
1416 return (m_ptr->r_idx != 0);