11 #include "monster-status.h"
12 #include "monster-spell.h"
13 #include "monster-process.h"
15 #include "spells-summon.h"
16 #include "monsterrace-hook.h"
17 #include "object-curse.h"
21 #include "player-effects.h"
22 #include "player-personality.h"
23 #include "view-mainwindow.h"
30 * @brief モンスターIDからPOWERFULフラグの有無を取得する /
31 * @param floor_ptr 現在フロアへの参照ポインタ
32 * @param m_idx モンスターID
33 * @return POWERFULフラグがあればTRUE、なければFALSEを返す。
35 bool monster_is_powerful(floor_type *floor_ptr, MONSTER_IDX m_idx)
37 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
38 monster_race *r_ptr = &r_info[m_ptr->r_idx];
39 bool powerful = r_ptr->flags2 & RF2_POWERFUL ? TRUE : FALSE;
44 * @brief モンスターIDからモンスターのレベルを取得する(ただし最低1を保証する) /
45 * @param m_idx モンスターID
48 DEPTH monster_level_idx(floor_type *floor_ptr, MONSTER_IDX m_idx)
50 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
51 monster_race *r_ptr = &r_info[m_ptr->r_idx];
52 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
57 * @brief モンスターに与えたダメージの修正処理 /
58 * Modify the physical damage done to the monster.
59 * @param target_ptr プレーヤーへの参照ポインタ
60 * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
62 * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
63 * @return 修正を行った結果のダメージ量
66 * (for example when it's invulnerable or shielded)
67 * ToDo: Accept a damage-type to calculate the modified damage from
68 * things like fire, frost, lightning, poison, ... attacks.
69 * "type" is not yet used and should be 0.
72 HIT_POINT mon_damage_mod(player_type *target_ptr, monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
74 monster_race *r_ptr = &r_info[m_ptr->r_idx];
76 if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
79 if ((dam == 0) && one_in_(3)) dam = 1;
82 if (MON_INVULNER(m_ptr))
86 if (!target_ptr->blind && is_seen(m_ptr))
88 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
91 else if (!one_in_(PENETRATE_INVULNERABILITY))
101 * @brief モンスターに与えたダメージを元に経験値を加算する /
102 * Calculate experience point to be get
103 * @param dam 与えたダメージ量
104 * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
108 * Even the 64 bit operation is not big enough to avoid overflaw
109 * unless we carefully choose orders of multiplication and division.
110 * Get the coefficient first, and multiply (potentially huge) base
111 * experience point of a monster later.
114 static void get_exp_from_mon(player_type *target_ptr, HIT_POINT dam, monster_type *m_ptr)
116 monster_race *r_ptr = &r_info[m_ptr->r_idx];
123 if (!monster_is_valid(m_ptr)) return;
124 if (is_pet(m_ptr) || target_ptr->phase_out) return;
127 * - Ratio of monster's level to player's level effects
128 * - Varying speed effects
129 * - Get a fraction in proportion of damage point
131 new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
134 div_l = (target_ptr->max_plv + 2) * SPEED_TO_ENERGY(r_ptr->speed);
136 /* Use (average maxhp * 2) as a denominator */
137 if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
138 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
140 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
142 /* Special penalty in the wilderness */
143 if (!target_ptr->current_floor_ptr->dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
144 s64b_mul(&div_h, &div_l, 0, 5);
146 /* Do division first to prevent overflaw */
147 s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
149 /* Special penalty for mutiply-monster */
150 if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
152 int monnum_penarty = r_ptr->r_akills / 400;
153 if (monnum_penarty > 8) monnum_penarty = 8;
155 while (monnum_penarty--)
158 s64b_RSHIFT(new_exp, new_exp_frac, 2);
162 /* Special penalty for rest_and_shoot exp scum */
163 if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
165 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
166 if (over_damage > 32) over_damage = 32;
168 while (over_damage--)
171 s64b_mul(&new_exp, &new_exp_frac, 0, 9);
172 s64b_div(&new_exp, &new_exp_frac, 0, 10);
176 /* Finally multiply base experience point of the monster */
177 s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
179 gain_exp_64(target_ptr, new_exp, new_exp_frac);
185 * @brief モンスターの時限ステータスを取得する
186 * @param floor_ptr 現在フロアへの参照ポインタ
187 * @return m_idx モンスターの参照ID
188 * @return mproc_type モンスターの時限ステータスID
191 int get_mproc_idx(floor_type *floor_ptr, MONSTER_IDX m_idx, int mproc_type)
193 s16b *cur_mproc_list = floor_ptr->mproc_list[mproc_type];
196 for (i = floor_ptr->mproc_max[mproc_type] - 1; i >= 0; i--)
198 if (cur_mproc_list[i] == m_idx) return i;
205 * @brief モンスターの時限ステータスリストを追加する
206 * @param floor_ptr 現在フロアへの参照ポインタ
207 * @return m_idx モンスターの参照ID
208 * @return mproc_type 追加したいモンスターの時限ステータスID
211 static void mproc_add(floor_type *floor_ptr, MONSTER_IDX m_idx, int mproc_type)
213 if (floor_ptr->mproc_max[mproc_type] < current_world_ptr->max_m_idx) floor_ptr->mproc_list[mproc_type][floor_ptr->mproc_max[mproc_type]++] = (s16b)m_idx;
218 * @brief モンスターの時限ステータスリストを削除
219 * @param floor_ptr 現在フロアへの参照ポインタ
220 * @return m_idx モンスターの参照ID
221 * @return mproc_type 削除したいモンスターの時限ステータスID
224 static void mproc_remove(floor_type *floor_ptr, MONSTER_IDX m_idx, int mproc_type)
226 int mproc_idx = get_mproc_idx(floor_ptr, m_idx, mproc_type);
227 if (mproc_idx >= 0) floor_ptr->mproc_list[mproc_type][mproc_idx] = floor_ptr->mproc_list[mproc_type][--floor_ptr->mproc_max[mproc_type]];
232 * @brief モンスターの時限ステータスリストを初期化する / Initialize monster process
233 * @param floor_ptr 現在フロアへの参照ポインタ
236 void mproc_init(floor_type *floor_ptr)
242 /* Reset "p_ptr->current_floor_ptr->mproc_max[]" */
243 for (cmi = 0; cmi < MAX_MTIMED; cmi++) floor_ptr->mproc_max[cmi] = 0;
245 /* Process the monsters (backwards) */
246 for (i = floor_ptr->m_max - 1; i >= 1; i--)
248 m_ptr = &floor_ptr->m_list[i];
250 /* Ignore "dead" monsters */
251 if (!monster_is_valid(m_ptr)) continue;
253 for (cmi = 0; cmi < MAX_MTIMED; cmi++)
255 if (m_ptr->mtimed[cmi]) mproc_add(floor_ptr, i, cmi);
262 * @brief モンスターの睡眠状態値をセットする。0で起きる。 /
263 * Set "m_ptr->mtimed[MTIMED_CSLEEP]", notice observable changes
264 * @param target_ptr プレーヤーへの参照ポインタ
265 * @param m_idx モンスター参照ID
267 * @return 別途更新処理が必要な場合TRUEを返す
269 bool set_monster_csleep(player_type *target_ptr, MONSTER_IDX m_idx, int v)
271 floor_type *floor_ptr = target_ptr->current_floor_ptr;
272 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
274 v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
278 if (!MON_CSLEEP(m_ptr))
280 mproc_add(floor_ptr, m_idx, MTIMED_CSLEEP);
287 if (MON_CSLEEP(m_ptr))
289 mproc_remove(floor_ptr, m_idx, MTIMED_CSLEEP);
295 m_ptr->mtimed[MTIMED_CSLEEP] = (s16b)v;
297 if (!notice) return FALSE;
301 /* Update health bar as needed */
302 if (target_ptr->health_who == m_idx) target_ptr->redraw |= (PR_HEALTH);
303 if (target_ptr->riding == m_idx) target_ptr->redraw |= (PR_UHEALTH);
306 if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) target_ptr->update |= (PU_MON_LITE);
313 * @brief モンスターの加速状態値をセット /
314 * Set "m_ptr->mtimed[MTIMED_FAST]", notice observable changes
315 * @param target_ptr プレーヤーへの参照ポインタ
316 * @param m_idx モンスター参照ID
318 * @return 別途更新処理が必要な場合TRUEを返す
320 bool set_monster_fast(player_type *target_ptr, MONSTER_IDX m_idx, int v)
322 floor_type *floor_ptr = target_ptr->current_floor_ptr;
323 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
325 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
329 if (!MON_FAST(m_ptr))
331 mproc_add(floor_ptr, m_idx, MTIMED_FAST);
340 mproc_remove(floor_ptr, m_idx, MTIMED_FAST);
346 m_ptr->mtimed[MTIMED_FAST] = (s16b)v;
348 if (!notice) return FALSE;
350 if ((target_ptr->riding == m_idx) && !p_ptr->leaving) target_ptr->update |= (PU_BONUS);
357 * Set "m_ptr->mtimed[MTIMED_SLOW]", notice observable changes
359 bool set_monster_slow(player_type *target_ptr, MONSTER_IDX m_idx, int v)
361 floor_type *floor_ptr = target_ptr->current_floor_ptr;
362 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
364 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
368 if (!MON_SLOW(m_ptr))
370 mproc_add(floor_ptr, m_idx, MTIMED_SLOW);
379 mproc_remove(floor_ptr, m_idx, MTIMED_SLOW);
385 m_ptr->mtimed[MTIMED_SLOW] = (s16b)v;
387 if (!notice) return FALSE;
389 if ((target_ptr->riding == m_idx) && !target_ptr->leaving) target_ptr->update |= (PU_BONUS);
396 * @brief モンスターの朦朧状態値をセット /
397 * Set "m_ptr->mtimed[MTIMED_STUNNED]", notice observable changes
398 * @param target_ptr プレーヤーへの参照ポインタ
399 * @param m_idx モンスター参照ID
401 * @return 別途更新処理が必要な場合TRUEを返す
403 bool set_monster_stunned(player_type *target_ptr, MONSTER_IDX m_idx, int v)
405 floor_type *floor_ptr = target_ptr->current_floor_ptr;
406 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
408 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
412 if (!MON_STUNNED(m_ptr))
414 mproc_add(floor_ptr, m_idx, MTIMED_STUNNED);
421 if (MON_STUNNED(m_ptr))
423 mproc_remove(floor_ptr, m_idx, MTIMED_STUNNED);
429 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)v;
436 * @brief モンスターの混乱状態値をセット /
437 * Set "m_ptr->mtimed[MTIMED_CONFUSED]", notice observable changes
438 * @param target_ptr プレーヤーへの参照ポインタ
439 * @param m_idx モンスター参照ID
441 * @return 別途更新処理が必要な場合TRUEを返す
443 bool set_monster_confused(player_type *target_ptr, MONSTER_IDX m_idx, int v)
445 floor_type *floor_ptr = target_ptr->current_floor_ptr;
446 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
448 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
452 if (!MON_CONFUSED(m_ptr))
454 mproc_add(floor_ptr, m_idx, MTIMED_CONFUSED);
461 if (MON_CONFUSED(m_ptr))
463 mproc_remove(floor_ptr, m_idx, MTIMED_CONFUSED);
469 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)v;
476 * @brief モンスターの恐慌状態値をセット /
477 * Set "m_ptr->mtimed[MTIMED_MONFEAR]", notice observable changes
478 * @param target_ptr プレーヤーへの参照ポインタ
479 * @param m_idx モンスター参照ID
481 * @return 別途更新処理が必要な場合TRUEを返す
483 bool set_monster_monfear(player_type *target_ptr, MONSTER_IDX m_idx, int v)
485 floor_type *floor_ptr = target_ptr->current_floor_ptr;
486 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
488 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
492 if (!MON_MONFEAR(m_ptr))
494 mproc_add(floor_ptr, m_idx, MTIMED_MONFEAR);
501 if (MON_MONFEAR(m_ptr))
503 mproc_remove(floor_ptr, m_idx, MTIMED_MONFEAR);
509 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)v;
511 if (!notice) return FALSE;
515 /* Update health bar as needed */
516 if (target_ptr->health_who == m_idx) target_ptr->redraw |= (PR_HEALTH);
517 if (target_ptr->riding == m_idx) target_ptr->redraw |= (PR_UHEALTH);
525 * @brief モンスターの無敵状態値をセット /
526 * Set "m_ptr->mtimed[MTIMED_INVULNER]", notice observable changes
527 * @param target_ptr プレーヤーへの参照ポインタ
528 * @param m_idx モンスター参照ID
530 * @param energy_need TRUEならば無敵解除時に行動ターン消費を行う
531 * @return 別途更新処理が必要な場合TRUEを返す
533 bool set_monster_invulner(player_type *target_ptr, MONSTER_IDX m_idx, int v, bool energy_need)
535 floor_type *floor_ptr = target_ptr->current_floor_ptr;
536 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
538 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
542 if (!MON_INVULNER(m_ptr))
544 mproc_add(floor_ptr, m_idx, MTIMED_INVULNER);
551 if (MON_INVULNER(m_ptr))
553 mproc_remove(floor_ptr, m_idx, MTIMED_INVULNER);
554 if (energy_need && !target_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
560 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)v;
562 if (!notice) return FALSE;
566 /* Update health bar as needed */
567 if (target_ptr->health_who == m_idx) target_ptr->redraw |= (PR_HEALTH);
568 if (target_ptr->riding == m_idx) target_ptr->redraw |= (PR_UHEALTH);
575 static u32b csleep_noise;
578 * @brief モンスターの各種状態値を時間経過により更新するサブルーチン
579 * @param floor_ptr 現在フロアへの参照ポインタ
580 * @param m_idx モンスター参照ID
581 * @param mtimed_idx 更新するモンスターの時限ステータスID
584 static void process_monsters_mtimed_aux(player_type *target_ptr, MONSTER_IDX m_idx, int mtimed_idx)
586 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
592 monster_race *r_ptr = &r_info[m_ptr->r_idx];
594 /* Assume does not wake up */
597 /* Hack -- Require proximity */
598 if (m_ptr->cdis < AAF_LIMIT)
600 /* Handle "sensing radius" */
601 if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
607 /* Handle "sight" and "aggravation" */
608 else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(p_ptr, m_ptr->fy, m_ptr->fx)))
617 u32b notice = randint0(1024);
619 /* Nightmare monsters are more alert */
620 if (ironman_nightmare) notice /= 2;
622 /* Hack -- See if monster "notices" player */
623 if ((notice * notice * notice) <= csleep_noise)
625 /* Hack -- amount of "waking" */
626 /* Wake up faster near the player */
627 int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
629 /* Hack -- amount of "waking" is affected by speed of player */
630 d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
633 /* Monster wakes up "a little bit" */
636 if (!set_monster_csleep(target_ptr, m_idx, MON_CSLEEP(m_ptr) - d))
638 /* Notice the "not waking up" */
639 if (is_original_ap_and_seen(m_ptr))
641 /* Hack -- Count the ignores */
642 if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++;
649 /* Notice the "waking up" */
652 GAME_TEXT m_name[MAX_NLEN];
653 monster_desc(m_name, m_ptr, 0);
654 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
657 if (is_original_ap_and_seen(m_ptr))
659 /* Hack -- Count the wakings */
660 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
669 /* Reduce by one, note if expires */
670 if (set_monster_fast(target_ptr, m_idx, MON_FAST(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 fast."), m_name);
682 /* Reduce by one, note if expires */
683 if (set_monster_slow(target_ptr, m_idx, MON_SLOW(m_ptr) - 1))
687 GAME_TEXT m_name[MAX_NLEN];
688 monster_desc(m_name, m_ptr, 0);
689 msg_format(_("%^sはもう減速されていない。", "%^s is no longer slow."), m_name);
696 int rlev = r_info[m_ptr->r_idx].level;
698 /* Recover from stun */
699 if (set_monster_stunned(target_ptr, m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
701 /* Message if visible */
704 GAME_TEXT m_name[MAX_NLEN];
705 monster_desc(m_name, m_ptr, 0);
706 msg_format(_("%^sは朦朧状態から立ち直った。", "%^s is no longer stunned."), m_name);
712 case MTIMED_CONFUSED:
713 /* Reduce the confusion */
714 if (set_monster_confused(target_ptr, m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
716 /* Message if visible */
719 GAME_TEXT m_name[MAX_NLEN];
720 monster_desc(m_name, m_ptr, 0);
721 msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name);
727 /* Reduce the fear */
728 if (set_monster_monfear(target_ptr, m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
733 GAME_TEXT m_name[MAX_NLEN];
737 /* Acquire the monster possessive */
738 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
740 monster_desc(m_name, m_ptr, 0);
742 msg_format("%^sは勇気を取り戻した。", m_name);
744 msg_format("%^s recovers %s courage.", m_name, m_poss);
750 case MTIMED_INVULNER:
751 /* Reduce by one, note if expires */
752 if (set_monster_invulner(target_ptr, m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
756 GAME_TEXT m_name[MAX_NLEN];
757 monster_desc(m_name, m_ptr, 0);
758 msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name);
767 * @brief 全モンスターの各種状態値を時間経過により更新するメインルーチン
768 * @param mtimed_idx 更新するモンスターの時限ステータスID
769 * @param target_ptr プレーヤーへの参照ポインタ
772 * Process the counters of monsters (once per 10 game turns)\n
773 * These functions are to process monsters' counters same as player's.
775 void process_monsters_mtimed(player_type *target_ptr, int mtimed_idx)
778 floor_type *floor_ptr = target_ptr->current_floor_ptr;
779 s16b *cur_mproc_list = floor_ptr->mproc_list[mtimed_idx];
781 /* Hack -- calculate the "player noise" */
782 if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - p_ptr->skill_stl));
784 /* Process the monsters (backwards) */
785 for (i = floor_ptr->mproc_max[mtimed_idx] - 1; i >= 0; i--)
787 process_monsters_mtimed_aux(target_ptr, cur_mproc_list[i], mtimed_idx);
793 * @brief モンスターへの魔力消去処理
794 * @param target_ptr プレーヤーへの参照ポインタ
795 * @param m_idx 魔力消去を受けるモンスターの参照ID
798 void dispel_monster_status(player_type *target_ptr, MONSTER_IDX m_idx)
800 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
801 GAME_TEXT m_name[MAX_NLEN];
803 monster_desc(m_name, m_ptr, 0);
804 if (set_monster_invulner(target_ptr, m_idx, 0, TRUE))
806 if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name);
808 if (set_monster_fast(target_ptr, m_idx, 0))
810 if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name);
812 if (set_monster_slow(target_ptr, m_idx, 0))
814 if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name);
819 * @brief モンスターの時間停止処理
820 * @param target_ptr プレーヤーへの参照ポインタ
821 * @param num 時間停止を行った敵が行動できる回数
822 * @param who 時間停止処理の主体ID
823 * @param vs_player TRUEならば時間停止開始処理を行う
824 * @return 時間停止が行われている状態ならばTRUEを返す
826 bool set_monster_timewalk(player_type *target_ptr, int num, MONSTER_IDX who, bool vs_player)
828 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[hack_m_idx]; /* the world monster */
830 if (current_world_ptr->timewalk_m_idx) return FALSE;
834 GAME_TEXT m_name[MAX_NLEN];
835 monster_desc(m_name, m_ptr, 0);
838 msg_format(_("「『ザ・ワールド』!時は止まった!」", "%s yells 'The World! Time has stopped!'"), m_name);
840 msg_format(_("「時よ!」", "%s yells 'Time!'"), m_name);
841 else msg_print("hek!");
846 /* This monster cast spells */
847 current_world_ptr->timewalk_m_idx = hack_m_idx;
849 if (vs_player) do_cmd_redraw(target_ptr);
853 if (!monster_is_valid(m_ptr)) break;
854 process_monster(target_ptr, current_world_ptr->timewalk_m_idx);
856 handle_stuff(target_ptr);
858 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
861 target_ptr->redraw |= (PR_MAP);
862 target_ptr->update |= (PU_MONSTERS);
863 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
865 current_world_ptr->timewalk_m_idx = 0;
866 if (vs_player || (player_has_los_bold(target_ptr, m_ptr->fy, m_ptr->fx) && projectable(target_ptr, target_ptr->y, target_ptr->x, m_ptr->fy, m_ptr->fx)))
868 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
872 handle_stuff(target_ptr);
877 * @brief モンスターの経験値取得処理
878 * @param m_idx 経験値を得るモンスターの参照ID
879 * @param s_idx 撃破されたモンスター種族の参照ID
882 void monster_gain_exp(MONSTER_IDX m_idx, MONRACE_IDX s_idx)
888 if (m_idx <= 0 || s_idx <= 0) return;
890 m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
892 if (!monster_is_valid(m_ptr)) return;
894 r_ptr = &r_info[m_ptr->r_idx];
895 s_ptr = &r_info[s_idx];
897 if (p_ptr->phase_out) return;
899 if (!r_ptr->next_exp) return;
901 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
902 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
903 if (!p_ptr->current_floor_ptr->dun_level) new_exp /= 5;
904 m_ptr->exp += new_exp;
905 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
907 if (m_ptr->exp >= r_ptr->next_exp)
909 GAME_TEXT m_name[MAX_NLEN];
910 int old_hp = m_ptr->hp;
911 int old_maxhp = m_ptr->max_maxhp;
912 int old_r_idx = m_ptr->r_idx;
913 byte old_sub_align = m_ptr->sub_align;
915 /* Hack -- Reduce the racial counter of previous monster */
916 real_r_ptr(m_ptr)->cur_num--;
918 monster_desc(m_name, m_ptr, 0);
919 m_ptr->r_idx = r_ptr->next_r_idx;
921 /* Count the monsters on the level */
922 real_r_ptr(m_ptr)->cur_num++;
924 m_ptr->ap_r_idx = m_ptr->r_idx;
925 r_ptr = &r_info[m_ptr->r_idx];
927 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
929 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
933 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
935 if (ironman_nightmare)
937 HIT_POINT hp = m_ptr->max_maxhp * 2L;
938 m_ptr->max_maxhp = MIN(30000, hp);
940 m_ptr->maxhp = m_ptr->max_maxhp;
941 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
943 /* dealt damage is 0 at initial*/
944 m_ptr->dealt_damage = 0;
946 /* Extract the monster base speed */
947 m_ptr->mspeed = get_mspeed(r_ptr);
949 /* Sub-alignment of a monster */
950 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
951 m_ptr->sub_align = old_sub_align;
954 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
955 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
956 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
961 if (is_pet(m_ptr) || m_ptr->ml)
963 if (!ignore_unview || player_can_see_bold(p_ptr, m_ptr->fy, m_ptr->fx))
967 monster_race *hallu_race;
971 hallu_race = &r_info[randint1(max_r_idx - 1)];
972 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
973 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name);
977 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name);
981 if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
983 /* Now you feel very close to this pet. */
984 m_ptr->parent_m_idx = 0;
986 update_monster(p_ptr, m_idx, FALSE);
987 lite_spot(m_ptr->fy, m_ptr->fx);
989 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;
993 * @brief モンスターのHPをダメージに応じて減算する /
994 * Decreases monsters hit points, handling monster death.
995 * @param dam 与えたダメージ量
996 * @param m_idx ダメージを与えたモンスターのID
997 * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
998 * @param note モンスターが倒された際の特別なメッセージ述語
1002 * We return TRUE if the monster has been killed (and deleted).
1003 * We announce monster death (using an optional "death message"
1004 * if given, and a otherwise a generic killed/destroyed message).
1005 * Only "physical attacks" can induce the "You have slain" message.
1006 * Missile and Spell attacks will induce the "dies" message, or
1007 * various "specialized" messages. Note that "You have destroyed"
1008 * and "is destroyed" are synonyms for "You have slain" and "dies".
1009 * Hack -- unseen monsters yield "You have killed it." message.
1010 * Added fear (DGK) and check whether to print fear messages -CWS
1011 * Made name, sex, and capitalization generic -BEN-
1012 * As always, the "ghost" processing is a total hack.
1013 * Hack -- we "delay" fear messages by passing around a "fear" flag.
1014 * Consider decreasing monster experience over time, say,
1015 * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
1016 * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
1017 * monster worth more than subsequent monsters. This would also need
1018 * to induce changes in the monster recall code.
1021 bool mon_take_hit(player_type *target_ptr, MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
1023 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1024 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1025 monster_type exp_mon;
1027 /* Innocent until proven otherwise */
1028 bool innocent = TRUE, thief = FALSE;
1032 (void)COPY(&exp_mon, m_ptr, monster_type);
1034 expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
1036 get_exp_from_mon(target_ptr, expdam, &exp_mon);
1038 /* Genocided by chaos patron */
1039 if (!monster_is_valid(m_ptr)) m_idx = 0;
1041 /* Redraw (later) if needed */
1042 if (target_ptr->health_who == m_idx) target_ptr->redraw |= (PR_HEALTH);
1043 if (target_ptr->riding == m_idx) target_ptr->redraw |= (PR_UHEALTH);
1045 (void)set_monster_csleep(target_ptr, m_idx, 0);
1047 /* Hack - Cancel any special player stealth magics. -LM- */
1048 if (target_ptr->special_defense & NINJA_S_STEALTH)
1050 set_superstealth(target_ptr, FALSE);
1053 /* Genocided by chaos patron */
1054 if (!m_idx) return TRUE;
1057 m_ptr->dealt_damage += dam;
1059 if (m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
1061 if (current_world_ptr->wizard)
1063 msg_format(_("合計%d/%dのダメージを与えた。", "You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
1066 /* It is dead now */
1069 GAME_TEXT m_name[MAX_NLEN];
1071 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1073 /* You might have unmasked Tanuki first time */
1074 r_ptr = &r_info[m_ptr->r_idx];
1075 m_ptr->ap_r_idx = m_ptr->r_idx;
1076 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1079 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1081 /* You might have unmasked Chameleon first time */
1082 r_ptr = real_r_ptr(m_ptr);
1083 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1086 if (!(m_ptr->smart & SM_CLONED))
1088 /* When the player kills a Unique, it stays dead */
1089 if (r_ptr->flags1 & RF1_UNIQUE)
1093 /* Mega-Hack -- Banor & Lupart */
1094 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1096 r_info[MON_BANORLUPART].max_num = 0;
1097 r_info[MON_BANORLUPART].r_pkills++;
1098 r_info[MON_BANORLUPART].r_akills++;
1099 if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1101 else if (m_ptr->r_idx == MON_BANORLUPART)
1103 r_info[MON_BANOR].max_num = 0;
1104 r_info[MON_BANOR].r_pkills++;
1105 r_info[MON_BANOR].r_akills++;
1106 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1107 r_info[MON_LUPART].max_num = 0;
1108 r_info[MON_LUPART].r_pkills++;
1109 r_info[MON_LUPART].r_akills++;
1110 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1114 /* When the player kills a Nazgul, it stays dead */
1115 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1118 /* Count all monsters killed */
1119 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1121 /* Recall even invisible uniques or winners */
1122 if ((m_ptr->ml && !target_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1124 /* Count kills this life */
1125 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1126 else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1128 /* Count kills in all lives */
1129 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1130 else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1132 /* Hack -- Auto-recall */
1133 monster_race_track(target_ptr, m_ptr->ap_r_idx);
1136 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1138 /* Don't kill Amberites */
1139 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1141 int curses = 1 + randint1(3);
1142 bool stop_ty = FALSE;
1145 msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
1146 curse_equipment(100, 50);
1150 stop_ty = activate_ty_curse(target_ptr, stop_ty, &count);
1154 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1156 char line_got[1024];
1157 if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
1159 msg_format("%^s %s", m_name, line_got);
1163 if (m_ptr->r_idx == MON_SERPENT)
1165 screen_dump = make_screen_dump(target_ptr);
1170 if (!(d_info[target_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1172 if (!target_ptr->current_floor_ptr->dun_level && !target_ptr->ambush_flag && !target_ptr->current_floor_ptr->inside_arena)
1174 chg_virtue(target_ptr, V_VALOUR, -1);
1176 else if (r_ptr->level > target_ptr->current_floor_ptr->dun_level)
1178 if (randint1(10) <= (r_ptr->level - target_ptr->current_floor_ptr->dun_level))
1179 chg_virtue(target_ptr, V_VALOUR, 1);
1181 if (r_ptr->level > 60)
1183 chg_virtue(target_ptr, V_VALOUR, 1);
1185 if (r_ptr->level >= 2 * (target_ptr->lev + 1))
1186 chg_virtue(target_ptr, V_VALOUR, 2);
1189 if (r_ptr->flags1 & RF1_UNIQUE)
1191 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(target_ptr, V_HARMONY, 2);
1193 if (r_ptr->flags3 & RF3_GOOD)
1195 chg_virtue(target_ptr, V_UNLIFE, 2);
1196 chg_virtue(target_ptr, V_VITALITY, -2);
1199 if (one_in_(3)) chg_virtue(target_ptr, V_INDIVIDUALISM, -1);
1202 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1204 chg_virtue(target_ptr, V_COMPASSION, -1);
1207 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * target_ptr->current_floor_ptr->dun_level) >= randint1(100)))
1208 chg_virtue(target_ptr, V_UNLIFE, 1);
1210 if (r_ptr->d_char == 'A')
1212 if (r_ptr->flags1 & RF1_UNIQUE)
1213 chg_virtue(target_ptr, V_FAITH, -2);
1214 else if ((r_ptr->level) / 10 + (3 * target_ptr->current_floor_ptr->dun_level) >= randint1(100))
1216 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(target_ptr, V_FAITH, -1);
1217 else chg_virtue(target_ptr, V_FAITH, 1);
1220 else if (r_ptr->flags3 & RF3_DEMON)
1222 if (r_ptr->flags1 & RF1_UNIQUE)
1223 chg_virtue(target_ptr, V_FAITH, 2);
1224 else if ((r_ptr->level) / 10 + (3 * target_ptr->current_floor_ptr->dun_level) >= randint1(100))
1225 chg_virtue(target_ptr, V_FAITH, 1);
1228 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1229 chg_virtue(target_ptr, V_VITALITY, 2);
1231 if (r_ptr->r_deaths)
1233 if (r_ptr->flags1 & RF1_UNIQUE)
1235 chg_virtue(target_ptr, V_HONOUR, 10);
1237 else if ((r_ptr->level) / 10 + (2 * target_ptr->current_floor_ptr->dun_level) >= randint1(100))
1239 chg_virtue(target_ptr, V_HONOUR, 1);
1242 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1244 chg_virtue(target_ptr, V_VALOUR, -1);
1247 for (i = 0; i < 4; i++)
1249 if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1251 if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1252 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1254 thief = TRUE; /* Thief! */
1257 /* The new law says it is illegal to live in the dungeon */
1258 if (r_ptr->level != 0) innocent = FALSE;
1262 if (r_ptr->flags1 & RF1_UNIQUE)
1263 chg_virtue(target_ptr, V_JUSTICE, 3);
1264 else if (1 + ((r_ptr->level) / 10 + (2 * target_ptr->current_floor_ptr->dun_level)) >= randint1(100))
1265 chg_virtue(target_ptr, V_JUSTICE, 1);
1269 chg_virtue(target_ptr, V_JUSTICE, -1);
1272 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)))
1274 if (one_in_(4)) chg_virtue(target_ptr, V_NATURE, -1);
1277 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1280 sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
1281 exe_write_diary(target_ptr, NIKKI_UNIQUE, 0, note_buf);
1287 /* Death by Missile/Spell attack */
1290 msg_format("%^s%s", m_name, note);
1293 /* Death by physical attack -- invisible monster */
1294 else if (!m_ptr->ml)
1297 if ((target_ptr->pseikaku == SEIKAKU_COMBAT) || (target_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1298 msg_format("せっかくだから%sを殺した。", m_name);
1300 msg_format("%sを殺した。", m_name);
1302 msg_format("You have killed %s.", m_name);
1307 /* Death by Physical attack -- non-living monster */
1308 else if (!monster_living(m_ptr->r_idx))
1310 bool explode = FALSE;
1312 for (i = 0; i < 4; i++)
1314 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1317 /* Special note at death */
1319 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
1323 if ((target_ptr->pseikaku == SEIKAKU_COMBAT) || (target_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1324 msg_format("せっかくだから%sを倒した。", m_name);
1326 msg_format("%sを倒した。", m_name);
1328 msg_format("You have destroyed %s.", m_name);
1333 /* Death by Physical attack -- living monster */
1337 if ((target_ptr->pseikaku == SEIKAKU_COMBAT) || (target_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1338 msg_format("せっかくだから%sを葬り去った。", m_name);
1340 msg_format("%sを葬り去った。", m_name);
1342 msg_format("You have slain %s.", m_name);
1346 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
1348 for (i = 0; i < MAX_BOUNTY; i++)
1350 if ((current_world_ptr->bounty_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
1352 msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1358 /* Generate treasure */
1359 monster_death(m_idx, TRUE);
1361 /* Mega hack : replace IKETA to BIKETAL */
1362 if ((m_ptr->r_idx == MON_IKETA) && !(target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out))
1364 POSITION dummy_y = m_ptr->fy;
1365 POSITION dummy_x = m_ptr->fx;
1366 BIT_FLAGS mode = 0L;
1367 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1368 delete_monster_idx(m_idx);
1369 if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1371 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha! *I* am Biketal!"));
1376 delete_monster_idx(m_idx);
1379 get_exp_from_mon(target_ptr, (long)exp_mon.max_maxhp * 2, &exp_mon);
1384 /* Monster is dead */
1391 /* Mega-Hack -- Pain cancels fear */
1392 if (MON_MONFEAR(m_ptr) && (dam > 0))
1395 if (set_monster_monfear(target_ptr, m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1402 /* Sometimes a monster gets scared by damage */
1403 if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1405 /* Percentage of fully healthy */
1406 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1409 * Run (sometimes) if at 10% or less of max hit points,
1410 * or (usually) when hit for half its current hit points
1412 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1414 /* Hack -- note fear */
1417 /* Hack -- Add some timed fear */
1418 (void)set_monster_monfear(target_ptr, m_idx, (randint1(10) +
1419 (((dam >= m_ptr->hp) && (percentage > 7)) ?
1420 20 : ((11 - percentage) * 5))));
1430 bool monster_is_valid(monster_type *m_ptr)
1432 return (m_ptr->r_idx != 0);