10 #include "monster-status.h"
11 #include "monster-spell.h"
12 #include "monster-process.h"
14 #include "spells-summon.h"
15 #include "monsterrace-hook.h"
16 #include "object-curse.h"
20 #include "player-effects.h"
21 #include "view-mainwindow.h"
27 * @brief モンスターIDからPOWERFULフラグの有無を取得する /
28 * @param m_idx モンスターID
29 * @return POWERFULフラグがあればTRUE、なければFALSEを返す。
31 bool monster_is_powerful(MONSTER_IDX m_idx)
33 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
34 monster_race *r_ptr = &r_info[m_ptr->r_idx];
35 bool powerful = r_ptr->flags2 & RF2_POWERFUL ? TRUE : FALSE;
40 * @brief モンスターIDからモンスターのレベルを取得する(ただし最低1を保証する) /
41 * @param m_idx モンスターID
44 DEPTH monster_level_idx(MONSTER_IDX m_idx)
46 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
47 monster_race *r_ptr = &r_info[m_ptr->r_idx];
48 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
53 * @brief モンスターに与えたダメージの修正処理 /
54 * Modify the physical damage done to the monster.
55 * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
57 * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
58 * @return 修正を行った結果のダメージ量
61 * (for example when it's invulnerable or shielded)
62 * ToDo: Accept a damage-type to calculate the modified damage from
63 * things like fire, frost, lightning, poison, ... attacks.
64 * "type" is not yet used and should be 0.
67 HIT_POINT mon_damage_mod(monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
69 monster_race *r_ptr = &r_info[m_ptr->r_idx];
71 if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
74 if ((dam == 0) && one_in_(3)) dam = 1;
77 if (MON_INVULNER(m_ptr))
81 if (!p_ptr->blind && is_seen(m_ptr))
83 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
86 else if (!one_in_(PENETRATE_INVULNERABILITY))
97 * @brief モンスターに与えたダメージを元に経験値を加算する /
98 * Calculate experience point to be get
100 * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
104 * Even the 64 bit operation is not big enough to avoid overflaw
105 * unless we carefully choose orders of multiplication and division.
106 * Get the coefficient first, and multiply (potentially huge) base
107 * experience point of a monster later.
110 static void get_exp_from_mon(HIT_POINT dam, monster_type *m_ptr)
112 monster_race *r_ptr = &r_info[m_ptr->r_idx];
119 if (!monster_is_valid(m_ptr)) return;
120 if (is_pet(m_ptr) || p_ptr->inside_battle) return;
123 * - Ratio of monster's level to player's level effects
124 * - Varying speed effects
125 * - Get a fraction in proportion of damage point
127 new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
130 div_l = (p_ptr->max_plv + 2) * SPEED_TO_ENERGY(r_ptr->speed);
132 /* Use (average maxhp * 2) as a denominator */
133 if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
134 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
136 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
138 /* Special penalty in the wilderness */
139 if (!current_floor_ptr->dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
140 s64b_mul(&div_h, &div_l, 0, 5);
142 /* Do division first to prevent overflaw */
143 s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
145 /* Special penalty for mutiply-monster */
146 if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
148 int monnum_penarty = r_ptr->r_akills / 400;
149 if (monnum_penarty > 8) monnum_penarty = 8;
151 while (monnum_penarty--)
154 s64b_RSHIFT(new_exp, new_exp_frac, 2);
158 /* Special penalty for rest_and_shoot exp scum */
159 if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
161 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
162 if (over_damage > 32) over_damage = 32;
164 while (over_damage--)
167 s64b_mul(&new_exp, &new_exp_frac, 0, 9);
168 s64b_div(&new_exp, &new_exp_frac, 0, 10);
172 /* Finally multiply base experience point of the monster */
173 s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
175 /* Gain experience */
176 gain_exp_64(new_exp, new_exp_frac);
182 * @brief モンスターの時限ステータスを取得する
183 * @return m_idx モンスターの参照ID
184 * @return mproc_type モンスターの時限ステータスID
187 int get_mproc_idx(MONSTER_IDX m_idx, int mproc_type)
189 s16b *cur_mproc_list = current_floor_ptr->mproc_list[mproc_type];
192 for (i = current_floor_ptr->mproc_max[mproc_type] - 1; i >= 0; i--)
194 if (cur_mproc_list[i] == m_idx) return i;
201 * @brief モンスターの時限ステータスリストを追加する
202 * @return m_idx モンスターの参照ID
203 * @return mproc_type 追加したいモンスターの時限ステータスID
206 static void mproc_add(MONSTER_IDX m_idx, int mproc_type)
208 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;
213 * @brief モンスターの時限ステータスリストを削除
214 * @return m_idx モンスターの参照ID
215 * @return mproc_type 削除したいモンスターの時限ステータスID
218 static void mproc_remove(MONSTER_IDX m_idx, int mproc_type)
220 int mproc_idx = get_mproc_idx(m_idx, mproc_type);
221 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]];
226 * @brief モンスターの時限ステータスリストを初期化する / Initialize monster process
229 void mproc_init(void)
235 /* Reset "current_floor_ptr->mproc_max[]" */
236 for (cmi = 0; cmi < MAX_MTIMED; cmi++) current_floor_ptr->mproc_max[cmi] = 0;
238 /* Process the monsters (backwards) */
239 for (i = current_floor_ptr->m_max - 1; i >= 1; i--)
241 /* Access the monster */
242 m_ptr = ¤t_floor_ptr->m_list[i];
244 /* Ignore "dead" monsters */
245 if (!monster_is_valid(m_ptr)) continue;
247 for (cmi = 0; cmi < MAX_MTIMED; cmi++)
249 if (m_ptr->mtimed[cmi]) mproc_add(i, cmi);
256 * @brief モンスターの睡眠状態値をセットする。0で起きる。 /
257 * Set "m_ptr->mtimed[MTIMED_CSLEEP]", notice observable changes
258 * @param m_idx モンスター参照ID
260 * @return 別途更新処理が必要な場合TRUEを返す
262 bool set_monster_csleep(MONSTER_IDX m_idx, int v)
264 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
266 v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
271 if (!MON_CSLEEP(m_ptr))
273 mproc_add(m_idx, MTIMED_CSLEEP);
281 if (MON_CSLEEP(m_ptr))
283 mproc_remove(m_idx, MTIMED_CSLEEP);
289 m_ptr->mtimed[MTIMED_CSLEEP] = (s16b)v;
291 if (!notice) return FALSE;
295 /* Update health bar as needed */
296 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
297 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
300 if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
307 * @brief モンスターの加速状態値をセット /
308 * Set "m_ptr->mtimed[MTIMED_FAST]", notice observable changes
309 * @param m_idx モンスター参照ID
311 * @return 別途更新処理が必要な場合TRUEを返す
313 bool set_monster_fast(MONSTER_IDX m_idx, int v)
315 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
317 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
322 if (!MON_FAST(m_ptr))
324 mproc_add(m_idx, MTIMED_FAST);
334 mproc_remove(m_idx, MTIMED_FAST);
340 m_ptr->mtimed[MTIMED_FAST] = (s16b)v;
342 if (!notice) return FALSE;
344 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
351 * Set "m_ptr->mtimed[MTIMED_SLOW]", notice observable changes
353 bool set_monster_slow(MONSTER_IDX m_idx, int v)
355 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
357 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
362 if (!MON_SLOW(m_ptr))
364 mproc_add(m_idx, MTIMED_SLOW);
374 mproc_remove(m_idx, MTIMED_SLOW);
380 m_ptr->mtimed[MTIMED_SLOW] = (s16b)v;
382 if (!notice) return FALSE;
384 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
391 * @brief モンスターの朦朧状態値をセット /
392 * Set "m_ptr->mtimed[MTIMED_STUNNED]", notice observable changes
393 * @param m_idx モンスター参照ID
395 * @return 別途更新処理が必要な場合TRUEを返す
397 bool set_monster_stunned(MONSTER_IDX m_idx, int v)
399 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
401 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
406 if (!MON_STUNNED(m_ptr))
408 mproc_add(m_idx, MTIMED_STUNNED);
416 if (MON_STUNNED(m_ptr))
418 mproc_remove(m_idx, MTIMED_STUNNED);
424 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)v;
431 * @brief モンスターの混乱状態値をセット /
432 * Set "m_ptr->mtimed[MTIMED_CONFUSED]", notice observable changes
433 * @param m_idx モンスター参照ID
435 * @return 別途更新処理が必要な場合TRUEを返す
437 bool set_monster_confused(MONSTER_IDX m_idx, int v)
439 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
441 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
446 if (!MON_CONFUSED(m_ptr))
448 mproc_add(m_idx, MTIMED_CONFUSED);
456 if (MON_CONFUSED(m_ptr))
458 mproc_remove(m_idx, MTIMED_CONFUSED);
464 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)v;
471 * @brief モンスターの恐慌状態値をセット /
472 * Set "m_ptr->mtimed[MTIMED_MONFEAR]", notice observable changes
473 * @param m_idx モンスター参照ID
475 * @return 別途更新処理が必要な場合TRUEを返す
477 bool set_monster_monfear(MONSTER_IDX m_idx, int v)
479 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
481 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
486 if (!MON_MONFEAR(m_ptr))
488 mproc_add(m_idx, MTIMED_MONFEAR);
496 if (MON_MONFEAR(m_ptr))
498 mproc_remove(m_idx, MTIMED_MONFEAR);
504 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)v;
506 if (!notice) return FALSE;
510 /* Update health bar as needed */
511 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
512 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
520 * @brief モンスターの無敵状態値をセット /
521 * Set "m_ptr->mtimed[MTIMED_INVULNER]", notice observable changes
522 * @param m_idx モンスター参照ID
524 * @param energy_need TRUEならば無敵解除時に行動ターン消費を行う
525 * @return 別途更新処理が必要な場合TRUEを返す
527 bool set_monster_invulner(MONSTER_IDX m_idx, int v, bool energy_need)
529 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
531 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
536 if (!MON_INVULNER(m_ptr))
538 mproc_add(m_idx, MTIMED_INVULNER);
546 if (MON_INVULNER(m_ptr))
548 mproc_remove(m_idx, MTIMED_INVULNER);
549 if (energy_need && !p_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
555 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)v;
557 if (!notice) return FALSE;
561 /* Update health bar as needed */
562 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
563 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
570 static u32b csleep_noise;
573 * @brief モンスターの各種状態値を時間経過により更新するサブルーチン
574 * @param m_idx モンスター参照ID
575 * @param mtimed_idx 更新するモンスターの時限ステータスID
578 static void process_monsters_mtimed_aux(MONSTER_IDX m_idx, int mtimed_idx)
580 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
586 monster_race *r_ptr = &r_info[m_ptr->r_idx];
588 /* Assume does not wake up */
591 /* Hack -- Require proximity */
592 if (m_ptr->cdis < AAF_LIMIT)
594 /* Handle "sensing radius" */
595 if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
601 /* Handle "sight" and "aggravation" */
602 else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(m_ptr->fy, m_ptr->fx)))
611 u32b notice = randint0(1024);
613 /* Nightmare monsters are more alert */
614 if (ironman_nightmare) notice /= 2;
616 /* Hack -- See if monster "notices" player */
617 if ((notice * notice * notice) <= csleep_noise)
619 /* Hack -- amount of "waking" */
620 /* Wake up faster near the player */
621 int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
623 /* Hack -- amount of "waking" is affected by speed of player */
624 d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
627 /* Monster wakes up "a little bit" */
630 if (!set_monster_csleep(m_idx, MON_CSLEEP(m_ptr) - d))
632 /* Notice the "not waking up" */
633 if (is_original_ap_and_seen(m_ptr))
635 /* Hack -- Count the ignores */
636 if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++;
643 /* Notice the "waking up" */
646 GAME_TEXT m_name[MAX_NLEN];
647 monster_desc(m_name, m_ptr, 0);
648 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
651 if (is_original_ap_and_seen(m_ptr))
653 /* Hack -- Count the wakings */
654 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
663 /* Reduce by one, note if expires */
664 if (set_monster_fast(m_idx, MON_FAST(m_ptr) - 1))
668 GAME_TEXT m_name[MAX_NLEN];
669 monster_desc(m_name, m_ptr, 0);
670 msg_format(_("%^sはもう加速されていない。", "%^s is no longer fast."), m_name);
676 /* Reduce by one, note if expires */
677 if (set_monster_slow(m_idx, MON_SLOW(m_ptr) - 1))
681 GAME_TEXT m_name[MAX_NLEN];
682 monster_desc(m_name, m_ptr, 0);
683 msg_format(_("%^sはもう減速されていない。", "%^s is no longer slow."), m_name);
690 int rlev = r_info[m_ptr->r_idx].level;
692 /* Recover from stun */
693 if (set_monster_stunned(m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
695 /* Message if visible */
698 GAME_TEXT m_name[MAX_NLEN];
699 monster_desc(m_name, m_ptr, 0);
700 msg_format(_("%^sは朦朧状態から立ち直った。", "%^s is no longer stunned."), m_name);
706 case MTIMED_CONFUSED:
707 /* Reduce the confusion */
708 if (set_monster_confused(m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
710 /* Message if visible */
713 GAME_TEXT m_name[MAX_NLEN];
714 monster_desc(m_name, m_ptr, 0);
715 msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name);
721 /* Reduce the fear */
722 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
727 GAME_TEXT m_name[MAX_NLEN];
731 /* Acquire the monster possessive */
732 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
734 monster_desc(m_name, m_ptr, 0);
736 msg_format("%^sは勇気を取り戻した。", m_name);
738 msg_format("%^s recovers %s courage.", m_name, m_poss);
744 case MTIMED_INVULNER:
745 /* Reduce by one, note if expires */
746 if (set_monster_invulner(m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
750 GAME_TEXT m_name[MAX_NLEN];
751 monster_desc(m_name, m_ptr, 0);
752 msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name);
761 * @brief 全モンスターの各種状態値を時間経過により更新するメインルーチン
762 * @param mtimed_idx 更新するモンスターの時限ステータスID
765 * Process the counters of monsters (once per 10 game turns)\n
766 * These functions are to process monsters' counters same as player's.
768 void process_monsters_mtimed(int mtimed_idx)
771 s16b *cur_mproc_list = current_floor_ptr->mproc_list[mtimed_idx];
773 /* Hack -- calculate the "player noise" */
774 if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - p_ptr->skill_stl));
776 /* Process the monsters (backwards) */
777 for (i = current_floor_ptr->mproc_max[mtimed_idx] - 1; i >= 0; i--)
779 /* Access the monster */
780 process_monsters_mtimed_aux(cur_mproc_list[i], mtimed_idx);
785 * @brief モンスターへの魔力消去処理
786 * @param m_idx 魔力消去を受けるモンスターの参照ID
789 void dispel_monster_status(MONSTER_IDX m_idx)
791 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
792 GAME_TEXT m_name[MAX_NLEN];
794 monster_desc(m_name, m_ptr, 0);
795 if (set_monster_invulner(m_idx, 0, TRUE))
797 if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name);
799 if (set_monster_fast(m_idx, 0))
801 if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name);
803 if (set_monster_slow(m_idx, 0))
805 if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name);
810 * @brief モンスターの時間停止処理
811 * @param num 時間停止を行った敵が行動できる回数
812 * @param who 時間停止処理の主体ID
813 * @param vs_player TRUEならば時間停止開始処理を行う
814 * @return 時間停止が行われている状態ならばTRUEを返す
816 bool set_monster_timewalk(int num, MONSTER_IDX who, bool vs_player)
818 monster_type *m_ptr = ¤t_floor_ptr->m_list[hack_m_idx]; /* the world monster */
820 if (current_world_ptr->timewalk_m_idx) return (FALSE);
824 GAME_TEXT m_name[MAX_NLEN];
825 monster_desc(m_name, m_ptr, 0);
828 msg_format(_("「『ザ・ワールド』!時は止まった!」", "%s yells 'The World! Time has stopped!'"), m_name);
830 msg_format(_("「時よ!」", "%s yells 'Time!'"), m_name);
831 else msg_print("hek!");
836 /* This monster cast spells */
837 current_world_ptr->timewalk_m_idx = hack_m_idx;
839 if (vs_player) do_cmd_redraw();
843 if (!monster_is_valid(m_ptr)) break;
844 process_monster(current_world_ptr->timewalk_m_idx);
848 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
851 p_ptr->redraw |= (PR_MAP);
852 p_ptr->update |= (PU_MONSTERS);
853 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
855 current_world_ptr->timewalk_m_idx = 0;
856 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)))
858 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
867 * @brief モンスターの経験値取得処理
868 * @param m_idx 経験値を得るモンスターの参照ID
869 * @param s_idx 撃破されたモンスター種族の参照ID
872 void monster_gain_exp(MONSTER_IDX m_idx, MONRACE_IDX s_idx)
878 if (m_idx <= 0 || s_idx <= 0) return;
880 m_ptr = ¤t_floor_ptr->m_list[m_idx];
882 if (!monster_is_valid(m_ptr)) return;
884 r_ptr = &r_info[m_ptr->r_idx];
885 s_ptr = &r_info[s_idx];
887 if (p_ptr->inside_battle) return;
889 if (!r_ptr->next_exp) return;
891 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
892 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
893 if (!current_floor_ptr->dun_level) new_exp /= 5;
894 m_ptr->exp += new_exp;
895 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
897 if (m_ptr->exp >= r_ptr->next_exp)
899 GAME_TEXT m_name[MAX_NLEN];
900 int old_hp = m_ptr->hp;
901 int old_maxhp = m_ptr->max_maxhp;
902 int old_r_idx = m_ptr->r_idx;
903 byte old_sub_align = m_ptr->sub_align;
905 /* Hack -- Reduce the racial counter of previous monster */
906 real_r_ptr(m_ptr)->cur_num--;
908 monster_desc(m_name, m_ptr, 0);
909 m_ptr->r_idx = r_ptr->next_r_idx;
911 /* Count the monsters on the level */
912 real_r_ptr(m_ptr)->cur_num++;
914 m_ptr->ap_r_idx = m_ptr->r_idx;
915 r_ptr = &r_info[m_ptr->r_idx];
917 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
919 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
923 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
925 if (ironman_nightmare)
927 HIT_POINT hp = m_ptr->max_maxhp * 2L;
928 m_ptr->max_maxhp = MIN(30000, hp);
930 m_ptr->maxhp = m_ptr->max_maxhp;
931 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
933 /* dealt damage is 0 at initial*/
934 m_ptr->dealt_damage = 0;
936 /* Extract the monster base speed */
937 m_ptr->mspeed = get_mspeed(r_ptr);
939 /* Sub-alignment of a monster */
940 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
941 m_ptr->sub_align = old_sub_align;
944 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
945 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
946 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
951 if (is_pet(m_ptr) || m_ptr->ml)
953 if (!ignore_unview || player_can_see_bold(m_ptr->fy, m_ptr->fx))
957 monster_race *hallu_race;
961 hallu_race = &r_info[randint1(max_r_idx - 1)];
962 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
963 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name);
967 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name);
971 if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
973 /* Now you feel very close to this pet. */
974 m_ptr->parent_m_idx = 0;
976 update_monster(m_idx, FALSE);
977 lite_spot(m_ptr->fy, m_ptr->fx);
979 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;
983 * @brief モンスターのHPをダメージに応じて減算する /
984 * Decreases monsters hit points, handling monster death.
985 * @param dam 与えたダメージ量
986 * @param m_idx ダメージを与えたモンスターのID
987 * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
988 * @param note モンスターが倒された際の特別なメッセージ述語
992 * We return TRUE if the monster has been killed (and deleted).
993 * We announce monster death (using an optional "death message"
994 * if given, and a otherwise a generic killed/destroyed message).
995 * Only "physical attacks" can induce the "You have slain" message.
996 * Missile and Spell attacks will induce the "dies" message, or
997 * various "specialized" messages. Note that "You have destroyed"
998 * and "is destroyed" are synonyms for "You have slain" and "dies".
999 * Hack -- unseen monsters yield "You have killed it." message.
1000 * Added fear (DGK) and check whether to print fear messages -CWS
1001 * Made name, sex, and capitalization generic -BEN-
1002 * As always, the "ghost" processing is a total hack.
1003 * Hack -- we "delay" fear messages by passing around a "fear" flag.
1004 * Consider decreasing monster experience over time, say,
1005 * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
1006 * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
1007 * monster worth more than subsequent monsters. This would also need
1008 * to induce changes in the monster recall code.
1011 bool mon_take_hit(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
1013 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1014 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1015 monster_type exp_mon;
1017 /* Innocent until proven otherwise */
1018 bool innocent = TRUE, thief = FALSE;
1022 (void)COPY(&exp_mon, m_ptr, monster_type);
1024 expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
1026 get_exp_from_mon(expdam, &exp_mon);
1028 /* Genocided by chaos patron */
1029 if (!monster_is_valid(m_ptr)) m_idx = 0;
1031 /* Redraw (later) if needed */
1032 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1033 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1035 (void)set_monster_csleep(m_idx, 0);
1037 /* Hack - Cancel any special player stealth magics. -LM- */
1038 if (p_ptr->special_defense & NINJA_S_STEALTH)
1040 set_superstealth(FALSE);
1043 /* Genocided by chaos patron */
1044 if (!m_idx) return TRUE;
1047 m_ptr->dealt_damage += dam;
1049 if (m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
1053 msg_format(_("合計%d/%dのダメージを与えた。", "You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
1056 /* It is dead now */
1059 GAME_TEXT m_name[MAX_NLEN];
1061 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1063 /* You might have unmasked Tanuki first time */
1064 r_ptr = &r_info[m_ptr->r_idx];
1065 m_ptr->ap_r_idx = m_ptr->r_idx;
1066 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1069 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1071 /* You might have unmasked Chameleon first time */
1072 r_ptr = real_r_ptr(m_ptr);
1073 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1076 if (!(m_ptr->smart & SM_CLONED))
1078 /* When the player kills a Unique, it stays dead */
1079 if (r_ptr->flags1 & RF1_UNIQUE)
1083 /* Mega-Hack -- Banor & Lupart */
1084 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1086 r_info[MON_BANORLUPART].max_num = 0;
1087 r_info[MON_BANORLUPART].r_pkills++;
1088 r_info[MON_BANORLUPART].r_akills++;
1089 if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1091 else if (m_ptr->r_idx == MON_BANORLUPART)
1093 r_info[MON_BANOR].max_num = 0;
1094 r_info[MON_BANOR].r_pkills++;
1095 r_info[MON_BANOR].r_akills++;
1096 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1097 r_info[MON_LUPART].max_num = 0;
1098 r_info[MON_LUPART].r_pkills++;
1099 r_info[MON_LUPART].r_akills++;
1100 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1104 /* When the player kills a Nazgul, it stays dead */
1105 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1108 /* Count all monsters killed */
1109 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1111 /* Recall even invisible uniques or winners */
1112 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1114 /* Count kills this life */
1115 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1116 else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1118 /* Count kills in all lives */
1119 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1120 else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1122 /* Hack -- Auto-recall */
1123 monster_race_track(m_ptr->ap_r_idx);
1126 /* Extract monster name */
1127 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1129 /* Don't kill Amberites */
1130 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1132 int curses = 1 + randint1(3);
1133 bool stop_ty = FALSE;
1136 msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
1137 curse_equipment(100, 50);
1141 stop_ty = activate_ty_curse(stop_ty, &count);
1145 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1147 char line_got[1024];
1148 if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
1150 msg_format("%^s %s", m_name, line_got);
1154 if (m_ptr->r_idx == MON_SERPENT)
1156 screen_dump = make_screen_dump();
1161 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1163 if (!current_floor_ptr->dun_level && !p_ptr->ambush_flag && !p_ptr->inside_arena)
1165 chg_virtue(V_VALOUR, -1);
1167 else if (r_ptr->level > current_floor_ptr->dun_level)
1169 if (randint1(10) <= (r_ptr->level - current_floor_ptr->dun_level))
1170 chg_virtue(V_VALOUR, 1);
1172 if (r_ptr->level > 60)
1174 chg_virtue(V_VALOUR, 1);
1176 if (r_ptr->level >= 2 * (p_ptr->lev + 1))
1177 chg_virtue(V_VALOUR, 2);
1180 if (r_ptr->flags1 & RF1_UNIQUE)
1182 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
1184 if (r_ptr->flags3 & RF3_GOOD)
1186 chg_virtue(V_UNLIFE, 2);
1187 chg_virtue(V_VITALITY, -2);
1190 if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
1193 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1195 chg_virtue(V_COMPASSION, -1);
1198 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100)))
1199 chg_virtue(V_UNLIFE, 1);
1201 if (r_ptr->d_char == 'A')
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))
1207 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
1208 else chg_virtue(V_FAITH, 1);
1211 else if (r_ptr->flags3 & RF3_DEMON)
1213 if (r_ptr->flags1 & RF1_UNIQUE)
1214 chg_virtue(V_FAITH, 2);
1215 else if ((r_ptr->level) / 10 + (3 * current_floor_ptr->dun_level) >= randint1(100))
1216 chg_virtue(V_FAITH, 1);
1219 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1220 chg_virtue(V_VITALITY, 2);
1222 if (r_ptr->r_deaths)
1224 if (r_ptr->flags1 & RF1_UNIQUE)
1226 chg_virtue(V_HONOUR, 10);
1228 else if ((r_ptr->level) / 10 + (2 * current_floor_ptr->dun_level) >= randint1(100))
1230 chg_virtue(V_HONOUR, 1);
1233 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1235 chg_virtue(V_VALOUR, -1);
1238 for (i = 0; i < 4; i++)
1240 if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1242 if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1243 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1245 thief = TRUE; /* Thief! */
1248 /* The new law says it is illegal to live in the dungeon */
1249 if (r_ptr->level != 0) innocent = FALSE;
1253 if (r_ptr->flags1 & RF1_UNIQUE)
1254 chg_virtue(V_JUSTICE, 3);
1255 else if (1 + ((r_ptr->level) / 10 + (2 * current_floor_ptr->dun_level)) >= randint1(100))
1256 chg_virtue(V_JUSTICE, 1);
1260 chg_virtue(V_JUSTICE, -1);
1263 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)))
1265 if (one_in_(4)) chg_virtue(V_NATURE, -1);
1268 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1271 sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
1272 do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
1278 /* Death by Missile/Spell attack */
1281 msg_format("%^s%s", m_name, note);
1284 /* Death by physical attack -- invisible monster */
1285 else if (!m_ptr->ml)
1288 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (p_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1289 msg_format("せっかくだから%sを殺した。", m_name);
1291 msg_format("%sを殺した。", m_name);
1293 msg_format("You have killed %s.", m_name);
1298 /* Death by Physical attack -- non-living monster */
1299 else if (!monster_living(m_ptr->r_idx))
1301 bool explode = FALSE;
1303 for (i = 0; i < 4; i++)
1305 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1308 /* Special note at death */
1310 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
1314 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (p_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1315 msg_format("せっかくだから%sを倒した。", m_name);
1317 msg_format("%sを倒した。", m_name);
1319 msg_format("You have destroyed %s.", m_name);
1324 /* Death by Physical attack -- living monster */
1328 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (p_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1329 msg_format("せっかくだから%sを葬り去った。", m_name);
1331 msg_format("%sを葬り去った。", m_name);
1333 msg_format("You have slain %s.", m_name);
1337 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
1339 for (i = 0; i < MAX_KUBI; i++)
1341 if ((current_world_ptr->bounty_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
1343 msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1349 /* Generate treasure */
1350 monster_death(m_idx, TRUE);
1352 /* Mega hack : replace IKETA to BIKETAL */
1353 if ((m_ptr->r_idx == MON_IKETA) && !(p_ptr->inside_arena || p_ptr->inside_battle))
1355 POSITION dummy_y = m_ptr->fy;
1356 POSITION dummy_x = m_ptr->fx;
1357 BIT_FLAGS mode = 0L;
1358 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1359 delete_monster_idx(m_idx);
1360 if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1362 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha! *I* am Biketal!"));
1367 delete_monster_idx(m_idx);
1370 get_exp_from_mon((long)exp_mon.max_maxhp * 2, &exp_mon);
1375 /* Monster is dead */
1382 /* Mega-Hack -- Pain cancels fear */
1383 if (MON_MONFEAR(m_ptr) && (dam > 0))
1386 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1393 /* Sometimes a monster gets scared by damage */
1394 if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1396 /* Percentage of fully healthy */
1397 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1400 * Run (sometimes) if at 10% or less of max hit points,
1401 * or (usually) when hit for half its current hit points
1403 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1405 /* Hack -- note fear */
1408 /* Hack -- Add some timed fear */
1409 (void)set_monster_monfear(m_idx, (randint1(10) +
1410 (((dam >= m_ptr->hp) && (percentage > 7)) ?
1411 20 : ((11 - percentage) * 5))));
1421 bool monster_is_valid(monster_type *m_ptr)
1423 return (m_ptr->r_idx != 0);