3 #include "monster-status.h"
4 #include "spells-summon.h"
5 #include "monsterrace-hook.h"
6 #include "object-curse.h"
10 * @brief モンスターに与えたダメージを元に経験値を加算する /
11 * Calculate experience point to be get
13 * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
17 * Even the 64 bit operation is not big enough to avoid overflaw
18 * unless we carefully choose orders of multiplication and division.
19 * Get the coefficient first, and multiply (potentially huge) base
20 * experience point of a monster later.
23 static void get_exp_from_mon(HIT_POINT dam, monster_type *m_ptr)
25 monster_race *r_ptr = &r_info[m_ptr->r_idx];
32 if (!m_ptr->r_idx) return;
33 if (is_pet(m_ptr) || p_ptr->inside_battle) return;
36 * - Ratio of monster's level to player's level effects
37 * - Varying speed effects
38 * - Get a fraction in proportion of damage point
40 new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
43 div_l = (p_ptr->max_plv + 2) * SPEED_TO_ENERGY(r_ptr->speed);
45 /* Use (average maxhp * 2) as a denominator */
46 if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
47 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
49 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
51 /* Special penalty in the wilderness */
52 if (!dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
53 s64b_mul(&div_h, &div_l, 0, 5);
55 /* Do division first to prevent overflaw */
56 s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
58 /* Special penalty for mutiply-monster */
59 if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
61 int monnum_penarty = r_ptr->r_akills / 400;
62 if (monnum_penarty > 8) monnum_penarty = 8;
64 while (monnum_penarty--)
67 s64b_RSHIFT(new_exp, new_exp_frac, 2);
71 /* Special penalty for rest_and_shoot exp scum */
72 if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
74 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
75 if (over_damage > 32) over_damage = 32;
80 s64b_mul(&new_exp, &new_exp_frac, 0, 9);
81 s64b_div(&new_exp, &new_exp_frac, 0, 10);
85 /* Finally multiply base experience point of the monster */
86 s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
89 gain_exp_64(new_exp, new_exp_frac);
95 * @brief モンスターの時限ステータスを取得する
96 * @return m_idx モンスターの参照ID
97 * @return mproc_type モンスターの時限ステータスID
100 int get_mproc_idx(MONSTER_IDX m_idx, int mproc_type)
102 s16b *cur_mproc_list = mproc_list[mproc_type];
105 for (i = mproc_max[mproc_type] - 1; i >= 0; i--)
107 if (cur_mproc_list[i] == m_idx) return i;
114 * @brief モンスターの時限ステータスリストを追加する
115 * @return m_idx モンスターの参照ID
116 * @return mproc_type 追加したいモンスターの時限ステータスID
119 static void mproc_add(MONSTER_IDX m_idx, int mproc_type)
121 if (mproc_max[mproc_type] < max_m_idx) mproc_list[mproc_type][mproc_max[mproc_type]++] = (s16b)m_idx;
126 * @brief モンスターの時限ステータスリストを削除
127 * @return m_idx モンスターの参照ID
128 * @return mproc_type 削除したいモンスターの時限ステータスID
131 static void mproc_remove(MONSTER_IDX m_idx, int mproc_type)
133 int mproc_idx = get_mproc_idx(m_idx, mproc_type);
134 if (mproc_idx >= 0) mproc_list[mproc_type][mproc_idx] = mproc_list[mproc_type][--mproc_max[mproc_type]];
139 * @brief モンスターの時限ステータスリストを初期化する / Initialize monster process
142 void mproc_init(void)
148 /* Reset "mproc_max[]" */
149 for (cmi = 0; cmi < MAX_MTIMED; cmi++) mproc_max[cmi] = 0;
151 /* Process the monsters (backwards) */
152 for (i = m_max - 1; i >= 1; i--)
154 /* Access the monster */
157 /* Ignore "dead" monsters */
158 if (!m_ptr->r_idx) continue;
160 for (cmi = 0; cmi < MAX_MTIMED; cmi++)
162 if (m_ptr->mtimed[cmi]) mproc_add(i, cmi);
169 * @brief モンスターの睡眠状態値をセットする /
170 * Set "m_ptr->mtimed[MTIMED_CSLEEP]", notice observable changes
171 * @param m_idx モンスター参照ID
173 * @return 別途更新処理が必要な場合TRUEを返す
175 bool set_monster_csleep(MONSTER_IDX m_idx, int v)
177 monster_type *m_ptr = &m_list[m_idx];
180 /* Hack -- Force good values */
181 v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
186 if (!MON_CSLEEP(m_ptr))
188 mproc_add(m_idx, MTIMED_CSLEEP);
196 if (MON_CSLEEP(m_ptr))
198 mproc_remove(m_idx, MTIMED_CSLEEP);
204 m_ptr->mtimed[MTIMED_CSLEEP] = (s16b)v;
206 if (!notice) return FALSE;
210 /* Update health bar as needed */
211 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
212 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
215 if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
222 * @brief モンスターの加速状態値をセット /
223 * Set "m_ptr->mtimed[MTIMED_FAST]", notice observable changes
224 * @param m_idx モンスター参照ID
226 * @return 別途更新処理が必要な場合TRUEを返す
228 bool set_monster_fast(MONSTER_IDX m_idx, int v)
230 monster_type *m_ptr = &m_list[m_idx];
233 /* Hack -- Force good values */
234 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
239 if (!MON_FAST(m_ptr))
241 mproc_add(m_idx, MTIMED_FAST);
251 mproc_remove(m_idx, MTIMED_FAST);
257 m_ptr->mtimed[MTIMED_FAST] = (s16b)v;
259 if (!notice) return FALSE;
261 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
268 * Set "m_ptr->mtimed[MTIMED_SLOW]", notice observable changes
270 bool set_monster_slow(MONSTER_IDX m_idx, int v)
272 monster_type *m_ptr = &m_list[m_idx];
275 /* Hack -- Force good values */
276 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
281 if (!MON_SLOW(m_ptr))
283 mproc_add(m_idx, MTIMED_SLOW);
293 mproc_remove(m_idx, MTIMED_SLOW);
299 m_ptr->mtimed[MTIMED_SLOW] = (s16b)v;
301 if (!notice) return FALSE;
303 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
310 * @brief モンスターの朦朧状態値をセット /
311 * Set "m_ptr->mtimed[MTIMED_STUNNED]", notice observable changes
312 * @param m_idx モンスター参照ID
314 * @return 別途更新処理が必要な場合TRUEを返す
316 bool set_monster_stunned(MONSTER_IDX m_idx, int v)
318 monster_type *m_ptr = &m_list[m_idx];
321 /* Hack -- Force good values */
322 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
327 if (!MON_STUNNED(m_ptr))
329 mproc_add(m_idx, MTIMED_STUNNED);
337 if (MON_STUNNED(m_ptr))
339 mproc_remove(m_idx, MTIMED_STUNNED);
345 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)v;
352 * @brief モンスターの混乱状態値をセット /
353 * Set "m_ptr->mtimed[MTIMED_CONFUSED]", notice observable changes
354 * @param m_idx モンスター参照ID
356 * @return 別途更新処理が必要な場合TRUEを返す
358 bool set_monster_confused(MONSTER_IDX m_idx, int v)
360 monster_type *m_ptr = &m_list[m_idx];
363 /* Hack -- Force good values */
364 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
369 if (!MON_CONFUSED(m_ptr))
371 mproc_add(m_idx, MTIMED_CONFUSED);
379 if (MON_CONFUSED(m_ptr))
381 mproc_remove(m_idx, MTIMED_CONFUSED);
387 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)v;
394 * @brief モンスターの恐慌状態値をセット /
395 * Set "m_ptr->mtimed[MTIMED_MONFEAR]", notice observable changes
396 * @param m_idx モンスター参照ID
398 * @return 別途更新処理が必要な場合TRUEを返す
400 bool set_monster_monfear(MONSTER_IDX m_idx, int v)
402 monster_type *m_ptr = &m_list[m_idx];
405 /* Hack -- Force good values */
406 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
411 if (!MON_MONFEAR(m_ptr))
413 mproc_add(m_idx, MTIMED_MONFEAR);
421 if (MON_MONFEAR(m_ptr))
423 mproc_remove(m_idx, MTIMED_MONFEAR);
429 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)v;
431 if (!notice) return FALSE;
435 /* Update health bar as needed */
436 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
437 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
445 * @brief モンスターの無敵状態値をセット /
446 * Set "m_ptr->mtimed[MTIMED_INVULNER]", notice observable changes
447 * @param m_idx モンスター参照ID
449 * @param energy_need TRUEならば無敵解除時に行動ターン消費を行う
450 * @return 別途更新処理が必要な場合TRUEを返す
452 bool set_monster_invulner(MONSTER_IDX m_idx, int v, bool energy_need)
454 monster_type *m_ptr = &m_list[m_idx];
457 /* Hack -- Force good values */
458 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
463 if (!MON_INVULNER(m_ptr))
465 mproc_add(m_idx, MTIMED_INVULNER);
473 if (MON_INVULNER(m_ptr))
475 mproc_remove(m_idx, MTIMED_INVULNER);
476 if (energy_need && !p_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
482 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)v;
484 if (!notice) return FALSE;
488 /* Update health bar as needed */
489 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
490 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
497 static u32b csleep_noise;
500 * @brief モンスターの各種状態値を時間経過により更新するサブルーチン
501 * @param m_idx モンスター参照ID
502 * @param mtimed_idx 更新するモンスターの時限ステータスID
505 static void process_monsters_mtimed_aux(MONSTER_IDX m_idx, int mtimed_idx)
507 monster_type *m_ptr = &m_list[m_idx];
513 monster_race *r_ptr = &r_info[m_ptr->r_idx];
515 /* Assume does not wake up */
518 /* Hack -- Require proximity */
519 if (m_ptr->cdis < AAF_LIMIT)
521 /* Handle "sensing radius" */
522 if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
528 /* Handle "sight" and "aggravation" */
529 else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(m_ptr->fy, m_ptr->fx)))
538 u32b notice = randint0(1024);
540 /* Nightmare monsters are more alert */
541 if (ironman_nightmare) notice /= 2;
543 /* Hack -- See if monster "notices" player */
544 if ((notice * notice * notice) <= csleep_noise)
546 /* Hack -- amount of "waking" */
547 /* Wake up faster near the player */
548 int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
550 /* Hack -- amount of "waking" is affected by speed of player */
551 d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
554 /* Monster wakes up "a little bit" */
557 if (!set_monster_csleep(m_idx, MON_CSLEEP(m_ptr) - d))
559 /* Notice the "not waking up" */
560 if (is_original_ap_and_seen(m_ptr))
562 /* Hack -- Count the ignores */
563 if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++;
570 /* Notice the "waking up" */
573 GAME_TEXT m_name[MAX_NLEN];
574 monster_desc(m_name, m_ptr, 0);
575 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
578 if (is_original_ap_and_seen(m_ptr))
580 /* Hack -- Count the wakings */
581 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
590 /* Reduce by one, note if expires */
591 if (set_monster_fast(m_idx, MON_FAST(m_ptr) - 1))
595 GAME_TEXT m_name[MAX_NLEN];
596 monster_desc(m_name, m_ptr, 0);
597 msg_format(_("%^sはもう加速されていない。", "%^s is no longer fast."), m_name);
603 /* Reduce by one, note if expires */
604 if (set_monster_slow(m_idx, MON_SLOW(m_ptr) - 1))
608 GAME_TEXT m_name[MAX_NLEN];
609 monster_desc(m_name, m_ptr, 0);
610 msg_format(_("%^sはもう減速されていない。", "%^s is no longer slow."), m_name);
617 int rlev = r_info[m_ptr->r_idx].level;
619 /* Recover from stun */
620 if (set_monster_stunned(m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
622 /* Message if visible */
625 GAME_TEXT m_name[MAX_NLEN];
626 monster_desc(m_name, m_ptr, 0);
627 msg_format(_("%^sは朦朧状態から立ち直った。", "%^s is no longer stunned."), m_name);
633 case MTIMED_CONFUSED:
634 /* Reduce the confusion */
635 if (set_monster_confused(m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
637 /* Message if visible */
640 GAME_TEXT m_name[MAX_NLEN];
641 monster_desc(m_name, m_ptr, 0);
642 msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name);
648 /* Reduce the fear */
649 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
654 GAME_TEXT m_name[MAX_NLEN];
658 /* Acquire the monster possessive */
659 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
661 monster_desc(m_name, m_ptr, 0);
663 msg_format("%^sは勇気を取り戻した。", m_name);
665 msg_format("%^s recovers %s courage.", m_name, m_poss);
671 case MTIMED_INVULNER:
672 /* Reduce by one, note if expires */
673 if (set_monster_invulner(m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
677 GAME_TEXT m_name[MAX_NLEN];
678 monster_desc(m_name, m_ptr, 0);
679 msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name);
688 * @brief 全モンスターの各種状態値を時間経過により更新するメインルーチン
689 * @param mtimed_idx 更新するモンスターの時限ステータスID
692 * Process the counters of monsters (once per 10 game turns)\n
693 * These functions are to process monsters' counters same as player's.
695 void process_monsters_mtimed(int mtimed_idx)
698 s16b *cur_mproc_list = mproc_list[mtimed_idx];
700 /* Hack -- calculate the "player noise" */
701 if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - p_ptr->skill_stl));
703 /* Process the monsters (backwards) */
704 for (i = mproc_max[mtimed_idx] - 1; i >= 0; i--)
706 /* Access the monster */
707 process_monsters_mtimed_aux(cur_mproc_list[i], mtimed_idx);
712 * @brief モンスターへの魔力消去処理
713 * @param m_idx 魔力消去を受けるモンスターの参照ID
716 void dispel_monster_status(MONSTER_IDX m_idx)
718 monster_type *m_ptr = &m_list[m_idx];
719 GAME_TEXT m_name[MAX_NLEN];
721 monster_desc(m_name, m_ptr, 0);
722 if (set_monster_invulner(m_idx, 0, TRUE))
724 if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name);
726 if (set_monster_fast(m_idx, 0))
728 if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name);
730 if (set_monster_slow(m_idx, 0))
732 if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name);
737 * @brief モンスターの時間停止処理
738 * @param num 時間停止を行った敵が行動できる回数
739 * @param who 時間停止処理の主体ID
740 * @param vs_player TRUEならば時間停止開始処理を行う
741 * @return 時間停止が行われている状態ならばTRUEを返す
743 bool process_the_world(int num, MONSTER_IDX who, bool vs_player)
745 monster_type *m_ptr = &m_list[hack_m_idx]; /* the world monster */
747 if (world_monster) return (FALSE);
751 GAME_TEXT m_name[MAX_NLEN];
752 monster_desc(m_name, m_ptr, 0);
755 msg_format(_("「『ザ・ワールド』!時は止まった!」", "%s yells 'The World! Time has stopped!'"), m_name);
757 msg_format(_("「時よ!」", "%s yells 'Time!'"), m_name);
758 else msg_print("hek!");
763 /* This monster cast spells */
764 world_monster = hack_m_idx;
766 if (vs_player) do_cmd_redraw();
770 if (!m_ptr->r_idx) break;
771 process_monster(world_monster);
775 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
778 p_ptr->redraw |= (PR_MAP);
779 p_ptr->update |= (PU_MONSTERS);
780 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
783 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)))
785 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
794 * @brief モンスターの経験値取得処理
795 * @param m_idx 経験値を得るモンスターの参照ID
796 * @param s_idx 撃破されたモンスター種族の参照ID
799 void monster_gain_exp(MONSTER_IDX m_idx, IDX s_idx)
807 if (m_idx <= 0 || s_idx <= 0) return;
809 m_ptr = &m_list[m_idx];
811 /* Paranoia -- Skip dead monsters */
812 if (!m_ptr->r_idx) return;
814 r_ptr = &r_info[m_ptr->r_idx];
815 s_ptr = &r_info[s_idx];
817 if (p_ptr->inside_battle) return;
819 if (!r_ptr->next_exp) return;
821 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
822 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
823 if (!dun_level) new_exp /= 5;
824 m_ptr->exp += new_exp;
825 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
827 if (m_ptr->exp >= r_ptr->next_exp)
829 GAME_TEXT m_name[MAX_NLEN];
830 int old_hp = m_ptr->hp;
831 int old_maxhp = m_ptr->max_maxhp;
832 int old_r_idx = m_ptr->r_idx;
833 byte old_sub_align = m_ptr->sub_align;
835 /* Hack -- Reduce the racial counter of previous monster */
836 real_r_ptr(m_ptr)->cur_num--;
838 monster_desc(m_name, m_ptr, 0);
839 m_ptr->r_idx = r_ptr->next_r_idx;
841 /* Count the monsters on the level */
842 real_r_ptr(m_ptr)->cur_num++;
844 m_ptr->ap_r_idx = m_ptr->r_idx;
845 r_ptr = &r_info[m_ptr->r_idx];
847 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
849 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
853 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
855 if (ironman_nightmare)
857 HIT_POINT hp = m_ptr->max_maxhp * 2L;
858 m_ptr->max_maxhp = MIN(30000, hp);
860 m_ptr->maxhp = m_ptr->max_maxhp;
861 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
863 /* dealt damage is 0 at initial*/
864 m_ptr->dealt_damage = 0;
866 /* Extract the monster base speed */
867 m_ptr->mspeed = get_mspeed(r_ptr);
869 /* Sub-alignment of a monster */
870 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
871 m_ptr->sub_align = old_sub_align;
874 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
875 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
876 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
881 if (is_pet(m_ptr) || m_ptr->ml)
883 if (!ignore_unview || player_can_see_bold(m_ptr->fy, m_ptr->fx))
887 monster_race *hallu_race;
891 hallu_race = &r_info[randint1(max_r_idx - 1)];
892 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
893 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name);
897 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name);
901 if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
903 /* Now you feel very close to this pet. */
904 m_ptr->parent_m_idx = 0;
906 update_monster(m_idx, FALSE);
907 lite_spot(m_ptr->fy, m_ptr->fx);
909 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;
913 * @brief モンスターのHPをダメージに応じて減算する /
914 * Decreases monsters hit points, handling monster death.
915 * @param dam 与えたダメージ量
916 * @param m_idx ダメージを与えたモンスターのID
917 * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
918 * @param note モンスターが倒された際の特別なメッセージ述語
922 * We return TRUE if the monster has been killed (and deleted).
923 * We announce monster death (using an optional "death message"
924 * if given, and a otherwise a generic killed/destroyed message).
925 * Only "physical attacks" can induce the "You have slain" message.
926 * Missile and Spell attacks will induce the "dies" message, or
927 * various "specialized" messages. Note that "You have destroyed"
928 * and "is destroyed" are synonyms for "You have slain" and "dies".
929 * Hack -- unseen monsters yield "You have killed it." message.
930 * Added fear (DGK) and check whether to print fear messages -CWS
931 * Made name, sex, and capitalization generic -BEN-
932 * As always, the "ghost" processing is a total hack.
933 * Hack -- we "delay" fear messages by passing around a "fear" flag.
934 * Consider decreasing monster experience over time, say,
935 * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
936 * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
937 * monster worth more than subsequent monsters. This would also need
938 * to induce changes in the monster recall code.
941 bool mon_take_hit(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
943 monster_type *m_ptr = &m_list[m_idx];
944 monster_race *r_ptr = &r_info[m_ptr->r_idx];
945 monster_type exp_mon;
947 /* Innocent until proven otherwise */
948 bool innocent = TRUE, thief = FALSE;
952 (void)COPY(&exp_mon, m_ptr, monster_type);
954 expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
956 get_exp_from_mon(expdam, &exp_mon);
958 /* Genocided by chaos patron */
959 if (!m_ptr->r_idx) m_idx = 0;
961 /* Redraw (later) if needed */
962 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
963 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
965 (void)set_monster_csleep(m_idx, 0);
967 /* Hack - Cancel any special player stealth magics. -LM- */
968 if (p_ptr->special_defense & NINJA_S_STEALTH)
970 set_superstealth(FALSE);
973 /* Genocided by chaos patron */
974 if (!m_idx) return TRUE;
977 m_ptr->dealt_damage += dam;
979 if (m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
983 msg_format(_("合計%d/%dのダメージを与えた。", "You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
989 GAME_TEXT m_name[MAX_NLEN];
991 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
993 /* You might have unmasked Tanuki first time */
994 r_ptr = &r_info[m_ptr->r_idx];
995 m_ptr->ap_r_idx = m_ptr->r_idx;
996 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
999 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1001 /* You might have unmasked Chameleon first time */
1002 r_ptr = real_r_ptr(m_ptr);
1003 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1006 if (!(m_ptr->smart & SM_CLONED))
1008 /* When the player kills a Unique, it stays dead */
1009 if (r_ptr->flags1 & RF1_UNIQUE)
1013 /* Mega-Hack -- Banor & Lupart */
1014 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1016 r_info[MON_BANORLUPART].max_num = 0;
1017 r_info[MON_BANORLUPART].r_pkills++;
1018 r_info[MON_BANORLUPART].r_akills++;
1019 if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1021 else if (m_ptr->r_idx == MON_BANORLUPART)
1023 r_info[MON_BANOR].max_num = 0;
1024 r_info[MON_BANOR].r_pkills++;
1025 r_info[MON_BANOR].r_akills++;
1026 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1027 r_info[MON_LUPART].max_num = 0;
1028 r_info[MON_LUPART].r_pkills++;
1029 r_info[MON_LUPART].r_akills++;
1030 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1034 /* When the player kills a Nazgul, it stays dead */
1035 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1038 /* Count all monsters killed */
1039 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1041 /* Recall even invisible uniques or winners */
1042 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1044 /* Count kills this life */
1045 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1046 else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1048 /* Count kills in all lives */
1049 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1050 else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1052 /* Hack -- Auto-recall */
1053 monster_race_track(m_ptr->ap_r_idx);
1056 /* Extract monster name */
1057 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1059 /* Don't kill Amberites */
1060 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1062 int curses = 1 + randint1(3);
1063 bool stop_ty = FALSE;
1066 msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
1067 curse_equipment(100, 50);
1071 stop_ty = activate_ty_curse(stop_ty, &count);
1075 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1077 char line_got[1024];
1078 if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
1080 msg_format("%^s %s", m_name, line_got);
1084 if (m_ptr->r_idx == MON_SERPENT)
1086 screen_dump = make_screen_dump();
1091 if (!(d_info[dungeon_type].flags1 & DF1_BEGINNER))
1093 if (!dun_level && !ambush_flag && !p_ptr->inside_arena)
1095 chg_virtue(V_VALOUR, -1);
1097 else if (r_ptr->level > dun_level)
1099 if (randint1(10) <= (r_ptr->level - dun_level))
1100 chg_virtue(V_VALOUR, 1);
1102 if (r_ptr->level > 60)
1104 chg_virtue(V_VALOUR, 1);
1106 if (r_ptr->level >= 2 * (p_ptr->lev + 1))
1107 chg_virtue(V_VALOUR, 2);
1110 if (r_ptr->flags1 & RF1_UNIQUE)
1112 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
1114 if (r_ptr->flags3 & RF3_GOOD)
1116 chg_virtue(V_UNLIFE, 2);
1117 chg_virtue(V_VITALITY, -2);
1120 if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
1123 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1125 chg_virtue(V_COMPASSION, -1);
1128 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100)))
1129 chg_virtue(V_UNLIFE, 1);
1131 if (r_ptr->d_char == 'A')
1133 if (r_ptr->flags1 & RF1_UNIQUE)
1134 chg_virtue(V_FAITH, -2);
1135 else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1137 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
1138 else chg_virtue(V_FAITH, 1);
1141 else if (r_ptr->flags3 & RF3_DEMON)
1143 if (r_ptr->flags1 & RF1_UNIQUE)
1144 chg_virtue(V_FAITH, 2);
1145 else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1146 chg_virtue(V_FAITH, 1);
1149 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1150 chg_virtue(V_VITALITY, 2);
1152 if (r_ptr->r_deaths)
1154 if (r_ptr->flags1 & RF1_UNIQUE)
1156 chg_virtue(V_HONOUR, 10);
1158 else if ((r_ptr->level) / 10 + (2 * dun_level) >= randint1(100))
1160 chg_virtue(V_HONOUR, 1);
1163 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1165 chg_virtue(V_VALOUR, -1);
1168 for (i = 0; i < 4; i++)
1170 if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1172 if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1173 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1175 thief = TRUE; /* Thief! */
1178 /* The new law says it is illegal to live in the dungeon */
1179 if (r_ptr->level != 0) innocent = FALSE;
1183 if (r_ptr->flags1 & RF1_UNIQUE)
1184 chg_virtue(V_JUSTICE, 3);
1185 else if (1 + ((r_ptr->level) / 10 + (2 * dun_level)) >= randint1(100))
1186 chg_virtue(V_JUSTICE, 1);
1190 chg_virtue(V_JUSTICE, -1);
1193 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)))
1195 if (one_in_(4)) chg_virtue(V_NATURE, -1);
1198 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1201 sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
1202 do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
1208 /* Death by Missile/Spell attack */
1211 msg_format("%^s%s", m_name, note);
1214 /* Death by physical attack -- invisible monster */
1215 else if (!m_ptr->ml)
1218 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1219 msg_format("せっかくだから%sを殺した。", m_name);
1221 msg_format("%sを殺した。", m_name);
1223 msg_format("You have killed %s.", m_name);
1228 /* Death by Physical attack -- non-living monster */
1229 else if (!monster_living(m_ptr->r_idx))
1231 bool explode = FALSE;
1233 for (i = 0; i < 4; i++)
1235 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1238 /* Special note at death */
1240 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
1244 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1245 msg_format("せっかくだから%sを倒した。", m_name);
1247 msg_format("%sを倒した。", m_name);
1249 msg_format("You have destroyed %s.", m_name);
1254 /* Death by Physical attack -- living monster */
1258 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1259 msg_format("せっかくだから%sを葬り去った。", m_name);
1261 msg_format("%sを葬り去った。", m_name);
1263 msg_format("You have slain %s.", m_name);
1267 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
1269 for (i = 0; i < MAX_KUBI; i++)
1271 if ((kubi_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
1273 msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1279 /* Generate treasure */
1280 monster_death(m_idx, TRUE);
1282 /* Mega hack : replace IKETA to BIKETAL */
1283 if ((m_ptr->r_idx == MON_IKETA) && !(p_ptr->inside_arena || p_ptr->inside_battle))
1285 POSITION dummy_y = m_ptr->fy;
1286 POSITION dummy_x = m_ptr->fx;
1287 BIT_FLAGS mode = 0L;
1288 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1289 delete_monster_idx(m_idx);
1290 if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1292 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha! *I* am Biketal!"));
1297 delete_monster_idx(m_idx);
1300 get_exp_from_mon((long)exp_mon.max_maxhp * 2, &exp_mon);
1305 /* Monster is dead */
1312 /* Mega-Hack -- Pain cancels fear */
1313 if (MON_MONFEAR(m_ptr) && (dam > 0))
1316 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1323 /* Sometimes a monster gets scared by damage */
1324 if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1326 /* Percentage of fully healthy */
1327 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1330 * Run (sometimes) if at 10% or less of max hit points,
1331 * or (usually) when hit for half its current hit points
1333 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1335 /* Hack -- note fear */
1338 /* Hack -- Add some timed fear */
1339 (void)set_monster_monfear(m_idx, (randint1(10) +
1340 (((dam >= m_ptr->hp) && (percentage > 7)) ?
1341 20 : ((11 - percentage) * 5))));