3 #include "monster-status.h"
4 #include "spells-summon.h"
5 #include "monsterrace-hook.h"
6 #include "object-curse.h"
13 * @brief モンスターに与えたダメージの修正処理 /
14 * Modify the physical damage done to the monster.
15 * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
17 * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
18 * @return 修正を行った結果のダメージ量
21 * (for example when it's invulnerable or shielded)
22 * ToDo: Accept a damage-type to calculate the modified damage from
23 * things like fire, frost, lightning, poison, ... attacks.
24 * "type" is not yet used and should be 0.
27 HIT_POINT mon_damage_mod(monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
29 monster_race *r_ptr = &r_info[m_ptr->r_idx];
31 if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
34 if ((dam == 0) && one_in_(3)) dam = 1;
37 if (MON_INVULNER(m_ptr))
41 if (!p_ptr->blind && is_seen(m_ptr))
43 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
46 else if (!one_in_(PENETRATE_INVULNERABILITY))
57 * @brief モンスターに与えたダメージを元に経験値を加算する /
58 * Calculate experience point to be get
60 * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
64 * Even the 64 bit operation is not big enough to avoid overflaw
65 * unless we carefully choose orders of multiplication and division.
66 * Get the coefficient first, and multiply (potentially huge) base
67 * experience point of a monster later.
70 static void get_exp_from_mon(HIT_POINT dam, monster_type *m_ptr)
72 monster_race *r_ptr = &r_info[m_ptr->r_idx];
79 if (!m_ptr->r_idx) return;
80 if (is_pet(m_ptr) || p_ptr->inside_battle) return;
83 * - Ratio of monster's level to player's level effects
84 * - Varying speed effects
85 * - Get a fraction in proportion of damage point
87 new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
90 div_l = (p_ptr->max_plv + 2) * SPEED_TO_ENERGY(r_ptr->speed);
92 /* Use (average maxhp * 2) as a denominator */
93 if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
94 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
96 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
98 /* Special penalty in the wilderness */
99 if (!dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
100 s64b_mul(&div_h, &div_l, 0, 5);
102 /* Do division first to prevent overflaw */
103 s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
105 /* Special penalty for mutiply-monster */
106 if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
108 int monnum_penarty = r_ptr->r_akills / 400;
109 if (monnum_penarty > 8) monnum_penarty = 8;
111 while (monnum_penarty--)
114 s64b_RSHIFT(new_exp, new_exp_frac, 2);
118 /* Special penalty for rest_and_shoot exp scum */
119 if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
121 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
122 if (over_damage > 32) over_damage = 32;
124 while (over_damage--)
127 s64b_mul(&new_exp, &new_exp_frac, 0, 9);
128 s64b_div(&new_exp, &new_exp_frac, 0, 10);
132 /* Finally multiply base experience point of the monster */
133 s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
135 /* Gain experience */
136 gain_exp_64(new_exp, new_exp_frac);
142 * @brief モンスターの時限ステータスを取得する
143 * @return m_idx モンスターの参照ID
144 * @return mproc_type モンスターの時限ステータスID
147 int get_mproc_idx(MONSTER_IDX m_idx, int mproc_type)
149 s16b *cur_mproc_list = mproc_list[mproc_type];
152 for (i = mproc_max[mproc_type] - 1; i >= 0; i--)
154 if (cur_mproc_list[i] == m_idx) return i;
161 * @brief モンスターの時限ステータスリストを追加する
162 * @return m_idx モンスターの参照ID
163 * @return mproc_type 追加したいモンスターの時限ステータスID
166 static void mproc_add(MONSTER_IDX m_idx, int mproc_type)
168 if (mproc_max[mproc_type] < max_m_idx) mproc_list[mproc_type][mproc_max[mproc_type]++] = (s16b)m_idx;
173 * @brief モンスターの時限ステータスリストを削除
174 * @return m_idx モンスターの参照ID
175 * @return mproc_type 削除したいモンスターの時限ステータスID
178 static void mproc_remove(MONSTER_IDX m_idx, int mproc_type)
180 int mproc_idx = get_mproc_idx(m_idx, mproc_type);
181 if (mproc_idx >= 0) mproc_list[mproc_type][mproc_idx] = mproc_list[mproc_type][--mproc_max[mproc_type]];
186 * @brief モンスターの時限ステータスリストを初期化する / Initialize monster process
189 void mproc_init(void)
195 /* Reset "mproc_max[]" */
196 for (cmi = 0; cmi < MAX_MTIMED; cmi++) mproc_max[cmi] = 0;
198 /* Process the monsters (backwards) */
199 for (i = m_max - 1; i >= 1; i--)
201 /* Access the monster */
204 /* Ignore "dead" monsters */
205 if (!m_ptr->r_idx) continue;
207 for (cmi = 0; cmi < MAX_MTIMED; cmi++)
209 if (m_ptr->mtimed[cmi]) mproc_add(i, cmi);
216 * @brief モンスターの睡眠状態値をセットする /
217 * Set "m_ptr->mtimed[MTIMED_CSLEEP]", notice observable changes
218 * @param m_idx モンスター参照ID
220 * @return 別途更新処理が必要な場合TRUEを返す
222 bool set_monster_csleep(MONSTER_IDX m_idx, int v)
224 monster_type *m_ptr = &m_list[m_idx];
226 v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
231 if (!MON_CSLEEP(m_ptr))
233 mproc_add(m_idx, MTIMED_CSLEEP);
241 if (MON_CSLEEP(m_ptr))
243 mproc_remove(m_idx, MTIMED_CSLEEP);
249 m_ptr->mtimed[MTIMED_CSLEEP] = (s16b)v;
251 if (!notice) return FALSE;
255 /* Update health bar as needed */
256 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
257 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
260 if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
267 * @brief モンスターの加速状態値をセット /
268 * Set "m_ptr->mtimed[MTIMED_FAST]", notice observable changes
269 * @param m_idx モンスター参照ID
271 * @return 別途更新処理が必要な場合TRUEを返す
273 bool set_monster_fast(MONSTER_IDX m_idx, int v)
275 monster_type *m_ptr = &m_list[m_idx];
277 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
282 if (!MON_FAST(m_ptr))
284 mproc_add(m_idx, MTIMED_FAST);
294 mproc_remove(m_idx, MTIMED_FAST);
300 m_ptr->mtimed[MTIMED_FAST] = (s16b)v;
302 if (!notice) return FALSE;
304 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
311 * Set "m_ptr->mtimed[MTIMED_SLOW]", notice observable changes
313 bool set_monster_slow(MONSTER_IDX m_idx, int v)
315 monster_type *m_ptr = &m_list[m_idx];
317 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
322 if (!MON_SLOW(m_ptr))
324 mproc_add(m_idx, MTIMED_SLOW);
334 mproc_remove(m_idx, MTIMED_SLOW);
340 m_ptr->mtimed[MTIMED_SLOW] = (s16b)v;
342 if (!notice) return FALSE;
344 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
351 * @brief モンスターの朦朧状態値をセット /
352 * Set "m_ptr->mtimed[MTIMED_STUNNED]", notice observable changes
353 * @param m_idx モンスター参照ID
355 * @return 別途更新処理が必要な場合TRUEを返す
357 bool set_monster_stunned(MONSTER_IDX m_idx, int v)
359 monster_type *m_ptr = &m_list[m_idx];
361 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
366 if (!MON_STUNNED(m_ptr))
368 mproc_add(m_idx, MTIMED_STUNNED);
376 if (MON_STUNNED(m_ptr))
378 mproc_remove(m_idx, MTIMED_STUNNED);
384 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)v;
391 * @brief モンスターの混乱状態値をセット /
392 * Set "m_ptr->mtimed[MTIMED_CONFUSED]", notice observable changes
393 * @param m_idx モンスター参照ID
395 * @return 別途更新処理が必要な場合TRUEを返す
397 bool set_monster_confused(MONSTER_IDX m_idx, int v)
399 monster_type *m_ptr = &m_list[m_idx];
401 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
406 if (!MON_CONFUSED(m_ptr))
408 mproc_add(m_idx, MTIMED_CONFUSED);
416 if (MON_CONFUSED(m_ptr))
418 mproc_remove(m_idx, MTIMED_CONFUSED);
424 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)v;
431 * @brief モンスターの恐慌状態値をセット /
432 * Set "m_ptr->mtimed[MTIMED_MONFEAR]", notice observable changes
433 * @param m_idx モンスター参照ID
435 * @return 別途更新処理が必要な場合TRUEを返す
437 bool set_monster_monfear(MONSTER_IDX m_idx, int v)
439 monster_type *m_ptr = &m_list[m_idx];
441 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
446 if (!MON_MONFEAR(m_ptr))
448 mproc_add(m_idx, MTIMED_MONFEAR);
456 if (MON_MONFEAR(m_ptr))
458 mproc_remove(m_idx, MTIMED_MONFEAR);
464 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)v;
466 if (!notice) return FALSE;
470 /* Update health bar as needed */
471 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
472 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
480 * @brief モンスターの無敵状態値をセット /
481 * Set "m_ptr->mtimed[MTIMED_INVULNER]", notice observable changes
482 * @param m_idx モンスター参照ID
484 * @param energy_need TRUEならば無敵解除時に行動ターン消費を行う
485 * @return 別途更新処理が必要な場合TRUEを返す
487 bool set_monster_invulner(MONSTER_IDX m_idx, int v, bool energy_need)
489 monster_type *m_ptr = &m_list[m_idx];
491 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
496 if (!MON_INVULNER(m_ptr))
498 mproc_add(m_idx, MTIMED_INVULNER);
506 if (MON_INVULNER(m_ptr))
508 mproc_remove(m_idx, MTIMED_INVULNER);
509 if (energy_need && !p_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
515 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)v;
517 if (!notice) return FALSE;
521 /* Update health bar as needed */
522 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
523 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
530 static u32b csleep_noise;
533 * @brief モンスターの各種状態値を時間経過により更新するサブルーチン
534 * @param m_idx モンスター参照ID
535 * @param mtimed_idx 更新するモンスターの時限ステータスID
538 static void process_monsters_mtimed_aux(MONSTER_IDX m_idx, int mtimed_idx)
540 monster_type *m_ptr = &m_list[m_idx];
546 monster_race *r_ptr = &r_info[m_ptr->r_idx];
548 /* Assume does not wake up */
551 /* Hack -- Require proximity */
552 if (m_ptr->cdis < AAF_LIMIT)
554 /* Handle "sensing radius" */
555 if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
561 /* Handle "sight" and "aggravation" */
562 else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(m_ptr->fy, m_ptr->fx)))
571 u32b notice = randint0(1024);
573 /* Nightmare monsters are more alert */
574 if (ironman_nightmare) notice /= 2;
576 /* Hack -- See if monster "notices" player */
577 if ((notice * notice * notice) <= csleep_noise)
579 /* Hack -- amount of "waking" */
580 /* Wake up faster near the player */
581 int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
583 /* Hack -- amount of "waking" is affected by speed of player */
584 d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
587 /* Monster wakes up "a little bit" */
590 if (!set_monster_csleep(m_idx, MON_CSLEEP(m_ptr) - d))
592 /* Notice the "not waking up" */
593 if (is_original_ap_and_seen(m_ptr))
595 /* Hack -- Count the ignores */
596 if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++;
603 /* Notice the "waking up" */
606 GAME_TEXT m_name[MAX_NLEN];
607 monster_desc(m_name, m_ptr, 0);
608 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
611 if (is_original_ap_and_seen(m_ptr))
613 /* Hack -- Count the wakings */
614 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
623 /* Reduce by one, note if expires */
624 if (set_monster_fast(m_idx, MON_FAST(m_ptr) - 1))
628 GAME_TEXT m_name[MAX_NLEN];
629 monster_desc(m_name, m_ptr, 0);
630 msg_format(_("%^sはもう加速されていない。", "%^s is no longer fast."), m_name);
636 /* Reduce by one, note if expires */
637 if (set_monster_slow(m_idx, MON_SLOW(m_ptr) - 1))
641 GAME_TEXT m_name[MAX_NLEN];
642 monster_desc(m_name, m_ptr, 0);
643 msg_format(_("%^sはもう減速されていない。", "%^s is no longer slow."), m_name);
650 int rlev = r_info[m_ptr->r_idx].level;
652 /* Recover from stun */
653 if (set_monster_stunned(m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
655 /* Message if visible */
658 GAME_TEXT m_name[MAX_NLEN];
659 monster_desc(m_name, m_ptr, 0);
660 msg_format(_("%^sは朦朧状態から立ち直った。", "%^s is no longer stunned."), m_name);
666 case MTIMED_CONFUSED:
667 /* Reduce the confusion */
668 if (set_monster_confused(m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
670 /* Message if visible */
673 GAME_TEXT m_name[MAX_NLEN];
674 monster_desc(m_name, m_ptr, 0);
675 msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name);
681 /* Reduce the fear */
682 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
687 GAME_TEXT m_name[MAX_NLEN];
691 /* Acquire the monster possessive */
692 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
694 monster_desc(m_name, m_ptr, 0);
696 msg_format("%^sは勇気を取り戻した。", m_name);
698 msg_format("%^s recovers %s courage.", m_name, m_poss);
704 case MTIMED_INVULNER:
705 /* Reduce by one, note if expires */
706 if (set_monster_invulner(m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
710 GAME_TEXT m_name[MAX_NLEN];
711 monster_desc(m_name, m_ptr, 0);
712 msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name);
721 * @brief 全モンスターの各種状態値を時間経過により更新するメインルーチン
722 * @param mtimed_idx 更新するモンスターの時限ステータスID
725 * Process the counters of monsters (once per 10 game turns)\n
726 * These functions are to process monsters' counters same as player's.
728 void process_monsters_mtimed(int mtimed_idx)
731 s16b *cur_mproc_list = mproc_list[mtimed_idx];
733 /* Hack -- calculate the "player noise" */
734 if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - p_ptr->skill_stl));
736 /* Process the monsters (backwards) */
737 for (i = mproc_max[mtimed_idx] - 1; i >= 0; i--)
739 /* Access the monster */
740 process_monsters_mtimed_aux(cur_mproc_list[i], mtimed_idx);
745 * @brief モンスターへの魔力消去処理
746 * @param m_idx 魔力消去を受けるモンスターの参照ID
749 void dispel_monster_status(MONSTER_IDX m_idx)
751 monster_type *m_ptr = &m_list[m_idx];
752 GAME_TEXT m_name[MAX_NLEN];
754 monster_desc(m_name, m_ptr, 0);
755 if (set_monster_invulner(m_idx, 0, TRUE))
757 if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name);
759 if (set_monster_fast(m_idx, 0))
761 if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name);
763 if (set_monster_slow(m_idx, 0))
765 if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name);
770 * @brief モンスターの時間停止処理
771 * @param num 時間停止を行った敵が行動できる回数
772 * @param who 時間停止処理の主体ID
773 * @param vs_player TRUEならば時間停止開始処理を行う
774 * @return 時間停止が行われている状態ならばTRUEを返す
776 bool process_the_world(int num, MONSTER_IDX who, bool vs_player)
778 monster_type *m_ptr = &m_list[hack_m_idx]; /* the world monster */
780 if (world_monster) return (FALSE);
784 GAME_TEXT m_name[MAX_NLEN];
785 monster_desc(m_name, m_ptr, 0);
788 msg_format(_("「『ザ・ワールド』!時は止まった!」", "%s yells 'The World! Time has stopped!'"), m_name);
790 msg_format(_("「時よ!」", "%s yells 'Time!'"), m_name);
791 else msg_print("hek!");
796 /* This monster cast spells */
797 world_monster = hack_m_idx;
799 if (vs_player) do_cmd_redraw();
803 if (!m_ptr->r_idx) break;
804 process_monster(world_monster);
808 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
811 p_ptr->redraw |= (PR_MAP);
812 p_ptr->update |= (PU_MONSTERS);
813 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
816 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)))
818 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
827 * @brief モンスターの経験値取得処理
828 * @param m_idx 経験値を得るモンスターの参照ID
829 * @param s_idx 撃破されたモンスター種族の参照ID
832 void monster_gain_exp(MONSTER_IDX m_idx, IDX s_idx)
840 if (m_idx <= 0 || s_idx <= 0) return;
842 m_ptr = &m_list[m_idx];
844 /* Paranoia -- Skip dead monsters */
845 if (!m_ptr->r_idx) return;
847 r_ptr = &r_info[m_ptr->r_idx];
848 s_ptr = &r_info[s_idx];
850 if (p_ptr->inside_battle) return;
852 if (!r_ptr->next_exp) return;
854 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
855 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
856 if (!dun_level) new_exp /= 5;
857 m_ptr->exp += new_exp;
858 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
860 if (m_ptr->exp >= r_ptr->next_exp)
862 GAME_TEXT m_name[MAX_NLEN];
863 int old_hp = m_ptr->hp;
864 int old_maxhp = m_ptr->max_maxhp;
865 int old_r_idx = m_ptr->r_idx;
866 byte old_sub_align = m_ptr->sub_align;
868 /* Hack -- Reduce the racial counter of previous monster */
869 real_r_ptr(m_ptr)->cur_num--;
871 monster_desc(m_name, m_ptr, 0);
872 m_ptr->r_idx = r_ptr->next_r_idx;
874 /* Count the monsters on the level */
875 real_r_ptr(m_ptr)->cur_num++;
877 m_ptr->ap_r_idx = m_ptr->r_idx;
878 r_ptr = &r_info[m_ptr->r_idx];
880 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
882 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
886 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
888 if (ironman_nightmare)
890 HIT_POINT hp = m_ptr->max_maxhp * 2L;
891 m_ptr->max_maxhp = MIN(30000, hp);
893 m_ptr->maxhp = m_ptr->max_maxhp;
894 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
896 /* dealt damage is 0 at initial*/
897 m_ptr->dealt_damage = 0;
899 /* Extract the monster base speed */
900 m_ptr->mspeed = get_mspeed(r_ptr);
902 /* Sub-alignment of a monster */
903 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
904 m_ptr->sub_align = old_sub_align;
907 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
908 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
909 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
914 if (is_pet(m_ptr) || m_ptr->ml)
916 if (!ignore_unview || player_can_see_bold(m_ptr->fy, m_ptr->fx))
920 monster_race *hallu_race;
924 hallu_race = &r_info[randint1(max_r_idx - 1)];
925 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
926 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name);
930 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name);
934 if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
936 /* Now you feel very close to this pet. */
937 m_ptr->parent_m_idx = 0;
939 update_monster(m_idx, FALSE);
940 lite_spot(m_ptr->fy, m_ptr->fx);
942 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;
946 * @brief モンスターのHPをダメージに応じて減算する /
947 * Decreases monsters hit points, handling monster death.
948 * @param dam 与えたダメージ量
949 * @param m_idx ダメージを与えたモンスターのID
950 * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
951 * @param note モンスターが倒された際の特別なメッセージ述語
955 * We return TRUE if the monster has been killed (and deleted).
956 * We announce monster death (using an optional "death message"
957 * if given, and a otherwise a generic killed/destroyed message).
958 * Only "physical attacks" can induce the "You have slain" message.
959 * Missile and Spell attacks will induce the "dies" message, or
960 * various "specialized" messages. Note that "You have destroyed"
961 * and "is destroyed" are synonyms for "You have slain" and "dies".
962 * Hack -- unseen monsters yield "You have killed it." message.
963 * Added fear (DGK) and check whether to print fear messages -CWS
964 * Made name, sex, and capitalization generic -BEN-
965 * As always, the "ghost" processing is a total hack.
966 * Hack -- we "delay" fear messages by passing around a "fear" flag.
967 * Consider decreasing monster experience over time, say,
968 * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
969 * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
970 * monster worth more than subsequent monsters. This would also need
971 * to induce changes in the monster recall code.
974 bool mon_take_hit(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
976 monster_type *m_ptr = &m_list[m_idx];
977 monster_race *r_ptr = &r_info[m_ptr->r_idx];
978 monster_type exp_mon;
980 /* Innocent until proven otherwise */
981 bool innocent = TRUE, thief = FALSE;
985 (void)COPY(&exp_mon, m_ptr, monster_type);
987 expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
989 get_exp_from_mon(expdam, &exp_mon);
991 /* Genocided by chaos patron */
992 if (!m_ptr->r_idx) m_idx = 0;
994 /* Redraw (later) if needed */
995 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
996 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
998 (void)set_monster_csleep(m_idx, 0);
1000 /* Hack - Cancel any special player stealth magics. -LM- */
1001 if (p_ptr->special_defense & NINJA_S_STEALTH)
1003 set_superstealth(FALSE);
1006 /* Genocided by chaos patron */
1007 if (!m_idx) return TRUE;
1010 m_ptr->dealt_damage += dam;
1012 if (m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
1016 msg_format(_("合計%d/%dのダメージを与えた。", "You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
1019 /* It is dead now */
1022 GAME_TEXT m_name[MAX_NLEN];
1024 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1026 /* You might have unmasked Tanuki first time */
1027 r_ptr = &r_info[m_ptr->r_idx];
1028 m_ptr->ap_r_idx = m_ptr->r_idx;
1029 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1032 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1034 /* You might have unmasked Chameleon first time */
1035 r_ptr = real_r_ptr(m_ptr);
1036 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1039 if (!(m_ptr->smart & SM_CLONED))
1041 /* When the player kills a Unique, it stays dead */
1042 if (r_ptr->flags1 & RF1_UNIQUE)
1046 /* Mega-Hack -- Banor & Lupart */
1047 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1049 r_info[MON_BANORLUPART].max_num = 0;
1050 r_info[MON_BANORLUPART].r_pkills++;
1051 r_info[MON_BANORLUPART].r_akills++;
1052 if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1054 else if (m_ptr->r_idx == MON_BANORLUPART)
1056 r_info[MON_BANOR].max_num = 0;
1057 r_info[MON_BANOR].r_pkills++;
1058 r_info[MON_BANOR].r_akills++;
1059 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1060 r_info[MON_LUPART].max_num = 0;
1061 r_info[MON_LUPART].r_pkills++;
1062 r_info[MON_LUPART].r_akills++;
1063 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1067 /* When the player kills a Nazgul, it stays dead */
1068 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1071 /* Count all monsters killed */
1072 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1074 /* Recall even invisible uniques or winners */
1075 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1077 /* Count kills this life */
1078 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1079 else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1081 /* Count kills in all lives */
1082 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1083 else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1085 /* Hack -- Auto-recall */
1086 monster_race_track(m_ptr->ap_r_idx);
1089 /* Extract monster name */
1090 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1092 /* Don't kill Amberites */
1093 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1095 int curses = 1 + randint1(3);
1096 bool stop_ty = FALSE;
1099 msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
1100 curse_equipment(100, 50);
1104 stop_ty = activate_ty_curse(stop_ty, &count);
1108 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1110 char line_got[1024];
1111 if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
1113 msg_format("%^s %s", m_name, line_got);
1117 if (m_ptr->r_idx == MON_SERPENT)
1119 screen_dump = make_screen_dump();
1124 if (!(d_info[dungeon_type].flags1 & DF1_BEGINNER))
1126 if (!dun_level && !ambush_flag && !p_ptr->inside_arena)
1128 chg_virtue(V_VALOUR, -1);
1130 else if (r_ptr->level > dun_level)
1132 if (randint1(10) <= (r_ptr->level - dun_level))
1133 chg_virtue(V_VALOUR, 1);
1135 if (r_ptr->level > 60)
1137 chg_virtue(V_VALOUR, 1);
1139 if (r_ptr->level >= 2 * (p_ptr->lev + 1))
1140 chg_virtue(V_VALOUR, 2);
1143 if (r_ptr->flags1 & RF1_UNIQUE)
1145 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
1147 if (r_ptr->flags3 & RF3_GOOD)
1149 chg_virtue(V_UNLIFE, 2);
1150 chg_virtue(V_VITALITY, -2);
1153 if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
1156 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1158 chg_virtue(V_COMPASSION, -1);
1161 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100)))
1162 chg_virtue(V_UNLIFE, 1);
1164 if (r_ptr->d_char == 'A')
1166 if (r_ptr->flags1 & RF1_UNIQUE)
1167 chg_virtue(V_FAITH, -2);
1168 else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1170 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
1171 else chg_virtue(V_FAITH, 1);
1174 else if (r_ptr->flags3 & RF3_DEMON)
1176 if (r_ptr->flags1 & RF1_UNIQUE)
1177 chg_virtue(V_FAITH, 2);
1178 else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1179 chg_virtue(V_FAITH, 1);
1182 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1183 chg_virtue(V_VITALITY, 2);
1185 if (r_ptr->r_deaths)
1187 if (r_ptr->flags1 & RF1_UNIQUE)
1189 chg_virtue(V_HONOUR, 10);
1191 else if ((r_ptr->level) / 10 + (2 * dun_level) >= randint1(100))
1193 chg_virtue(V_HONOUR, 1);
1196 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1198 chg_virtue(V_VALOUR, -1);
1201 for (i = 0; i < 4; i++)
1203 if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1205 if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1206 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1208 thief = TRUE; /* Thief! */
1211 /* The new law says it is illegal to live in the dungeon */
1212 if (r_ptr->level != 0) innocent = FALSE;
1216 if (r_ptr->flags1 & RF1_UNIQUE)
1217 chg_virtue(V_JUSTICE, 3);
1218 else if (1 + ((r_ptr->level) / 10 + (2 * dun_level)) >= randint1(100))
1219 chg_virtue(V_JUSTICE, 1);
1223 chg_virtue(V_JUSTICE, -1);
1226 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)))
1228 if (one_in_(4)) chg_virtue(V_NATURE, -1);
1231 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1234 sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
1235 do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
1241 /* Death by Missile/Spell attack */
1244 msg_format("%^s%s", m_name, note);
1247 /* Death by physical attack -- invisible monster */
1248 else if (!m_ptr->ml)
1251 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1252 msg_format("せっかくだから%sを殺した。", m_name);
1254 msg_format("%sを殺した。", m_name);
1256 msg_format("You have killed %s.", m_name);
1261 /* Death by Physical attack -- non-living monster */
1262 else if (!monster_living(m_ptr->r_idx))
1264 bool explode = FALSE;
1266 for (i = 0; i < 4; i++)
1268 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1271 /* Special note at death */
1273 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
1277 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1278 msg_format("せっかくだから%sを倒した。", m_name);
1280 msg_format("%sを倒した。", m_name);
1282 msg_format("You have destroyed %s.", m_name);
1287 /* Death by Physical attack -- living monster */
1291 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1292 msg_format("せっかくだから%sを葬り去った。", m_name);
1294 msg_format("%sを葬り去った。", m_name);
1296 msg_format("You have slain %s.", m_name);
1300 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
1302 for (i = 0; i < MAX_KUBI; i++)
1304 if ((kubi_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
1306 msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1312 /* Generate treasure */
1313 monster_death(m_idx, TRUE);
1315 /* Mega hack : replace IKETA to BIKETAL */
1316 if ((m_ptr->r_idx == MON_IKETA) && !(p_ptr->inside_arena || p_ptr->inside_battle))
1318 POSITION dummy_y = m_ptr->fy;
1319 POSITION dummy_x = m_ptr->fx;
1320 BIT_FLAGS mode = 0L;
1321 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1322 delete_monster_idx(m_idx);
1323 if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1325 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha! *I* am Biketal!"));
1330 delete_monster_idx(m_idx);
1333 get_exp_from_mon((long)exp_mon.max_maxhp * 2, &exp_mon);
1338 /* Monster is dead */
1345 /* Mega-Hack -- Pain cancels fear */
1346 if (MON_MONFEAR(m_ptr) && (dam > 0))
1349 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1356 /* Sometimes a monster gets scared by damage */
1357 if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1359 /* Percentage of fully healthy */
1360 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1363 * Run (sometimes) if at 10% or less of max hit points,
1364 * or (usually) when hit for half its current hit points
1366 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1368 /* Hack -- note fear */
1371 /* Hack -- Add some timed fear */
1372 (void)set_monster_monfear(m_idx, (randint1(10) +
1373 (((dam >= m_ptr->hp) && (percentage > 7)) ?
1374 20 : ((11 - percentage) * 5))));