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;
45 * @brief モンスターIDからモンスターのレベルを取得する(ただし最低1を保証する) /
46 * @param m_idx モンスターID
49 DEPTH monster_level_idx(floor_type *floor_ptr, MONSTER_IDX m_idx)
51 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
52 monster_race *r_ptr = &r_info[m_ptr->r_idx];
53 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
59 * @brief モンスターに与えたダメージの修正処理 /
60 * Modify the physical damage done to the monster.
61 * @param target_ptr プレーヤーへの参照ポインタ
62 * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
64 * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
65 * @return 修正を行った結果のダメージ量
68 * (for example when it's invulnerable or shielded)
69 * ToDo: Accept a damage-type to calculate the modified damage from
70 * things like fire, frost, lightning, poison, ... attacks.
71 * "type" is not yet used and should be 0.
74 HIT_POINT mon_damage_mod(player_type *target_ptr, monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
76 monster_race *r_ptr = &r_info[m_ptr->r_idx];
78 if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
81 if ((dam == 0) && one_in_(3)) dam = 1;
84 if (MON_INVULNER(m_ptr))
88 if (!target_ptr->blind && is_seen(m_ptr))
90 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
93 else if (!one_in_(PENETRATE_INVULNERABILITY))
104 * @brief モンスターに与えたダメージを元に経験値を加算する /
105 * Calculate experience point to be get
106 * @param dam 与えたダメージ量
107 * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
111 * Even the 64 bit operation is not big enough to avoid overflaw
112 * unless we carefully choose orders of multiplication and division.
113 * Get the coefficient first, and multiply (potentially huge) base
114 * experience point of a monster later.
117 static void get_exp_from_mon(player_type *target_ptr, HIT_POINT dam, monster_type *m_ptr)
119 monster_race *r_ptr = &r_info[m_ptr->r_idx];
121 if (!monster_is_valid(m_ptr)) return;
122 if (is_pet(m_ptr) || target_ptr->phase_out) return;
125 * todo 変数宣言と代入を同時に実行するとコンパイル警告が出る
134 * - Ratio of monster's level to player's level effects
135 * - Varying speed effects
136 * - Get a fraction in proportion of damage point
138 new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
141 div_l = (target_ptr->max_plv + 2) * SPEED_TO_ENERGY(r_ptr->speed);
143 /* Use (average maxhp * 2) as a denominator */
144 if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
145 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
147 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
149 /* Special penalty in the wilderness */
150 if (!target_ptr->current_floor_ptr->dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
151 s64b_mul(&div_h, &div_l, 0, 5);
153 /* Do division first to prevent overflaw */
154 s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
156 /* Special penalty for mutiply-monster */
157 if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
159 int monnum_penarty = r_ptr->r_akills / 400;
160 if (monnum_penarty > 8) monnum_penarty = 8;
162 while (monnum_penarty--)
165 s64b_RSHIFT(new_exp, new_exp_frac, 2);
169 /* Special penalty for rest_and_shoot exp scum */
170 if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
172 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
173 if (over_damage > 32) over_damage = 32;
175 while (over_damage--)
178 s64b_mul(&new_exp, &new_exp_frac, 0, 9);
179 s64b_div(&new_exp, &new_exp_frac, 0, 10);
183 s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
184 gain_exp_64(target_ptr, new_exp, new_exp_frac);
189 * @brief モンスターの時限ステータスを取得する
190 * @param floor_ptr 現在フロアへの参照ポインタ
191 * @return m_idx モンスターの参照ID
192 * @return mproc_type モンスターの時限ステータスID
195 int get_mproc_idx(floor_type *floor_ptr, MONSTER_IDX m_idx, int mproc_type)
197 s16b *cur_mproc_list = floor_ptr->mproc_list[mproc_type];
198 for (int i = floor_ptr->mproc_max[mproc_type] - 1; i >= 0; i--)
200 if (cur_mproc_list[i] == m_idx) return i;
208 * @brief モンスターの時限ステータスリストを追加する
209 * @param floor_ptr 現在フロアへの参照ポインタ
210 * @return m_idx モンスターの参照ID
211 * @return mproc_type 追加したいモンスターの時限ステータスID
214 static void mproc_add(floor_type *floor_ptr, MONSTER_IDX m_idx, int mproc_type)
216 if (floor_ptr->mproc_max[mproc_type] < current_world_ptr->max_m_idx)
218 floor_ptr->mproc_list[mproc_type][floor_ptr->mproc_max[mproc_type]++] = (s16b)m_idx;
224 * @brief モンスターの時限ステータスリストを削除
225 * @param floor_ptr 現在フロアへの参照ポインタ
226 * @return m_idx モンスターの参照ID
227 * @return mproc_type 削除したいモンスターの時限ステータスID
230 static void mproc_remove(floor_type *floor_ptr, MONSTER_IDX m_idx, int mproc_type)
232 int mproc_idx = get_mproc_idx(floor_ptr, m_idx, mproc_type);
235 floor_ptr->mproc_list[mproc_type][mproc_idx] = floor_ptr->mproc_list[mproc_type][--floor_ptr->mproc_max[mproc_type]];
241 * @brief モンスターの時限ステータスリストを初期化する / Initialize monster process
242 * @param floor_ptr 現在フロアへの参照ポインタ
245 void mproc_init(floor_type *floor_ptr)
247 /* Reset "target_ptr->current_floor_ptr->mproc_max[]" */
248 for (int i = 0; i < MAX_MTIMED; i++)
250 floor_ptr->mproc_max[i] = 0;
253 /* Process the monsters (backwards) */
254 for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
257 m_ptr = &floor_ptr->m_list[i];
259 /* Ignore "dead" monsters */
260 if (!monster_is_valid(m_ptr)) continue;
262 for (int cmi = 0; cmi < MAX_MTIMED; cmi++)
264 if (m_ptr->mtimed[cmi]) mproc_add(floor_ptr, i, cmi);
271 * @brief モンスターの睡眠状態値をセットする。0で起きる。 /
272 * Set "m_ptr->mtimed[MTIMED_CSLEEP]", notice observable changes
273 * @param target_ptr プレーヤーへの参照ポインタ
274 * @param m_idx モンスター参照ID
276 * @return 別途更新処理が必要な場合TRUEを返す
278 bool set_monster_csleep(player_type *target_ptr, MONSTER_IDX m_idx, int v)
280 floor_type *floor_ptr = target_ptr->current_floor_ptr;
281 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
283 v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
287 if (!MON_CSLEEP(m_ptr))
289 mproc_add(floor_ptr, m_idx, MTIMED_CSLEEP);
296 if (MON_CSLEEP(m_ptr))
298 mproc_remove(floor_ptr, m_idx, MTIMED_CSLEEP);
304 m_ptr->mtimed[MTIMED_CSLEEP] = (s16b)v;
306 if (!notice) return FALSE;
310 /* Update health bar as needed */
311 if (target_ptr->health_who == m_idx) target_ptr->redraw |= (PR_HEALTH);
312 if (target_ptr->riding == m_idx) target_ptr->redraw |= (PR_UHEALTH);
315 if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) target_ptr->update |= (PU_MON_LITE);
322 * @brief モンスターの加速状態値をセット /
323 * Set "m_ptr->mtimed[MTIMED_FAST]", notice observable changes
324 * @param target_ptr プレーヤーへの参照ポインタ
325 * @param m_idx モンスター参照ID
327 * @return 別途更新処理が必要な場合TRUEを返す
329 bool set_monster_fast(player_type *target_ptr, MONSTER_IDX m_idx, int v)
331 floor_type *floor_ptr = target_ptr->current_floor_ptr;
332 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
334 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
338 if (!MON_FAST(m_ptr))
340 mproc_add(floor_ptr, m_idx, MTIMED_FAST);
349 mproc_remove(floor_ptr, m_idx, MTIMED_FAST);
355 m_ptr->mtimed[MTIMED_FAST] = (s16b)v;
357 if (!notice) return FALSE;
359 if ((target_ptr->riding == m_idx) && !target_ptr->leaving) target_ptr->update |= (PU_BONUS);
366 * Set "m_ptr->mtimed[MTIMED_SLOW]", notice observable changes
368 bool set_monster_slow(player_type *target_ptr, MONSTER_IDX m_idx, int v)
370 floor_type *floor_ptr = target_ptr->current_floor_ptr;
371 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
373 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
377 if (!MON_SLOW(m_ptr))
379 mproc_add(floor_ptr, m_idx, MTIMED_SLOW);
388 mproc_remove(floor_ptr, m_idx, MTIMED_SLOW);
394 m_ptr->mtimed[MTIMED_SLOW] = (s16b)v;
396 if (!notice) return FALSE;
398 if ((target_ptr->riding == m_idx) && !target_ptr->leaving) target_ptr->update |= (PU_BONUS);
405 * @brief モンスターの朦朧状態値をセット /
406 * Set "m_ptr->mtimed[MTIMED_STUNNED]", notice observable changes
407 * @param target_ptr プレーヤーへの参照ポインタ
408 * @param m_idx モンスター参照ID
410 * @return 別途更新処理が必要な場合TRUEを返す
412 bool set_monster_stunned(player_type *target_ptr, MONSTER_IDX m_idx, int v)
414 floor_type *floor_ptr = target_ptr->current_floor_ptr;
415 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
417 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
421 if (!MON_STUNNED(m_ptr))
423 mproc_add(floor_ptr, m_idx, MTIMED_STUNNED);
430 if (MON_STUNNED(m_ptr))
432 mproc_remove(floor_ptr, m_idx, MTIMED_STUNNED);
438 m_ptr->mtimed[MTIMED_STUNNED] = (s16b)v;
445 * @brief モンスターの混乱状態値をセット /
446 * Set "m_ptr->mtimed[MTIMED_CONFUSED]", notice observable changes
447 * @param target_ptr プレーヤーへの参照ポインタ
448 * @param m_idx モンスター参照ID
450 * @return 別途更新処理が必要な場合TRUEを返す
452 bool set_monster_confused(player_type *target_ptr, MONSTER_IDX m_idx, int v)
454 floor_type *floor_ptr = target_ptr->current_floor_ptr;
455 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
457 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
461 if (!MON_CONFUSED(m_ptr))
463 mproc_add(floor_ptr, m_idx, MTIMED_CONFUSED);
470 if (MON_CONFUSED(m_ptr))
472 mproc_remove(floor_ptr, m_idx, MTIMED_CONFUSED);
478 m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)v;
485 * @brief モンスターの恐慌状態値をセット /
486 * Set "m_ptr->mtimed[MTIMED_MONFEAR]", notice observable changes
487 * @param target_ptr プレーヤーへの参照ポインタ
488 * @param m_idx モンスター参照ID
490 * @return 別途更新処理が必要な場合TRUEを返す
492 bool set_monster_monfear(player_type *target_ptr, MONSTER_IDX m_idx, int v)
494 floor_type *floor_ptr = target_ptr->current_floor_ptr;
495 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
497 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
501 if (!MON_MONFEAR(m_ptr))
503 mproc_add(floor_ptr, m_idx, MTIMED_MONFEAR);
510 if (MON_MONFEAR(m_ptr))
512 mproc_remove(floor_ptr, m_idx, MTIMED_MONFEAR);
518 m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)v;
520 if (!notice) return FALSE;
524 /* Update health bar as needed */
525 if (target_ptr->health_who == m_idx) target_ptr->redraw |= (PR_HEALTH);
526 if (target_ptr->riding == m_idx) target_ptr->redraw |= (PR_UHEALTH);
534 * @brief モンスターの無敵状態値をセット /
535 * Set "m_ptr->mtimed[MTIMED_INVULNER]", notice observable changes
536 * @param target_ptr プレーヤーへの参照ポインタ
537 * @param m_idx モンスター参照ID
539 * @param energy_need TRUEならば無敵解除時に行動ターン消費を行う
540 * @return 別途更新処理が必要な場合TRUEを返す
542 bool set_monster_invulner(player_type *target_ptr, MONSTER_IDX m_idx, int v, bool energy_need)
544 floor_type *floor_ptr = target_ptr->current_floor_ptr;
545 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
547 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
551 if (!MON_INVULNER(m_ptr))
553 mproc_add(floor_ptr, m_idx, MTIMED_INVULNER);
560 if (MON_INVULNER(m_ptr))
562 mproc_remove(floor_ptr, m_idx, MTIMED_INVULNER);
563 if (energy_need && !target_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
569 m_ptr->mtimed[MTIMED_INVULNER] = (s16b)v;
571 if (!notice) return FALSE;
575 /* Update health bar as needed */
576 if (target_ptr->health_who == m_idx) target_ptr->redraw |= (PR_HEALTH);
577 if (target_ptr->riding == m_idx) target_ptr->redraw |= (PR_UHEALTH);
584 static u32b csleep_noise;
587 * @brief モンスターの各種状態値を時間経過により更新するサブルーチン
588 * @param floor_ptr 現在フロアへの参照ポインタ
589 * @param m_idx モンスター参照ID
590 * @param mtimed_idx 更新するモンスターの時限ステータスID
593 static void process_monsters_mtimed_aux(player_type *target_ptr, MONSTER_IDX m_idx, int mtimed_idx)
595 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
601 monster_race *r_ptr = &r_info[m_ptr->r_idx];
603 /* Assume does not wake up */
606 /* Hack -- Require proximity */
607 if (m_ptr->cdis < AAF_LIMIT)
609 /* Handle "sensing radius" */
610 if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
616 /* Handle "sight" and "aggravation" */
617 else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(target_ptr, m_ptr->fy, m_ptr->fx)))
626 u32b notice = randint0(1024);
628 /* Nightmare monsters are more alert */
629 if (ironman_nightmare) notice /= 2;
631 /* Hack -- See if monster "notices" player */
632 if ((notice * notice * notice) > csleep_noise) break;
634 /* Hack -- amount of "waking" */
635 /* Wake up faster near the player */
636 int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
638 /* Hack -- amount of "waking" is affected by speed of player */
639 d = (d * SPEED_TO_ENERGY(target_ptr->pspeed)) / 10;
642 /* Monster wakes up "a little bit" */
645 if (!set_monster_csleep(target_ptr, m_idx, MON_CSLEEP(m_ptr) - d))
647 /* Notice the "not waking up" */
648 if (is_original_ap_and_seen(target_ptr, m_ptr))
650 /* Hack -- Count the ignores */
651 if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++;
657 /* Notice the "waking up" */
660 GAME_TEXT m_name[MAX_NLEN];
661 monster_desc(target_ptr, m_name, m_ptr, 0);
662 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
665 if (is_original_ap_and_seen(target_ptr, m_ptr))
667 /* Hack -- Count the wakings */
668 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
675 /* Reduce by one, note if expires */
676 if (set_monster_fast(target_ptr, m_idx, MON_FAST(m_ptr) - 1))
680 GAME_TEXT m_name[MAX_NLEN];
681 monster_desc(target_ptr, m_name, m_ptr, 0);
682 msg_format(_("%^sはもう加速されていない。", "%^s is no longer fast."), m_name);
689 /* Reduce by one, note if expires */
690 if (set_monster_slow(target_ptr, m_idx, MON_SLOW(m_ptr) - 1))
694 GAME_TEXT m_name[MAX_NLEN];
695 monster_desc(target_ptr, m_name, m_ptr, 0);
696 msg_format(_("%^sはもう減速されていない。", "%^s is no longer slow."), m_name);
704 int rlev = r_info[m_ptr->r_idx].level;
706 /* Recover from stun */
707 if (set_monster_stunned(target_ptr, m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
709 /* Message if visible */
712 GAME_TEXT m_name[MAX_NLEN];
713 monster_desc(target_ptr, m_name, m_ptr, 0);
714 msg_format(_("%^sは朦朧状態から立ち直った。", "%^s is no longer stunned."), m_name);
721 case MTIMED_CONFUSED:
723 /* Reduce the confusion */
724 if (!set_monster_confused(target_ptr, m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
726 /* Message if visible */
729 GAME_TEXT m_name[MAX_NLEN];
730 monster_desc(target_ptr, m_name, m_ptr, 0);
731 msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name);
739 /* Reduce the fear */
740 if (!set_monster_monfear(target_ptr, m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
746 GAME_TEXT m_name[MAX_NLEN];
752 /* Acquire the monster possessive */
753 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
755 monster_desc(target_ptr, m_name, m_ptr, 0);
757 msg_format("%^sは勇気を取り戻した。", m_name);
759 msg_format("%^s recovers %s courage.", m_name, m_poss);
766 case MTIMED_INVULNER:
768 /* Reduce by one, note if expires */
769 if (!set_monster_invulner(target_ptr, m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
774 GAME_TEXT m_name[MAX_NLEN];
775 monster_desc(target_ptr, m_name, m_ptr, 0);
776 msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name);
786 * @brief 全モンスターの各種状態値を時間経過により更新するメインルーチン
787 * @param mtimed_idx 更新するモンスターの時限ステータスID
788 * @param target_ptr プレーヤーへの参照ポインタ
791 * Process the counters of monsters (once per 10 game turns)\n
792 * These functions are to process monsters' counters same as player's.
794 void process_monsters_mtimed(player_type *target_ptr, int mtimed_idx)
796 floor_type *floor_ptr = target_ptr->current_floor_ptr;
797 s16b *cur_mproc_list = floor_ptr->mproc_list[mtimed_idx];
799 /* Hack -- calculate the "player noise" */
800 if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - target_ptr->skill_stl));
802 /* Process the monsters (backwards) */
803 for (int i = floor_ptr->mproc_max[mtimed_idx] - 1; i >= 0; i--)
805 process_monsters_mtimed_aux(target_ptr, cur_mproc_list[i], mtimed_idx);
811 * @brief モンスターへの魔力消去処理
812 * @param target_ptr プレーヤーへの参照ポインタ
813 * @param m_idx 魔力消去を受けるモンスターの参照ID
816 void dispel_monster_status(player_type *target_ptr, MONSTER_IDX m_idx)
818 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
819 GAME_TEXT m_name[MAX_NLEN];
821 monster_desc(target_ptr, m_name, m_ptr, 0);
822 if (set_monster_invulner(target_ptr, m_idx, 0, TRUE))
824 if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name);
827 if (set_monster_fast(target_ptr, m_idx, 0))
829 if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name);
832 if (set_monster_slow(target_ptr, m_idx, 0))
834 if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name);
840 * @brief モンスターの時間停止処理
841 * @param target_ptr プレーヤーへの参照ポインタ
842 * @param num 時間停止を行った敵が行動できる回数
843 * @param who 時間停止処理の主体ID
844 * @param vs_player TRUEならば時間停止開始処理を行う
845 * @return 時間停止が行われている状態ならばTRUEを返す
847 bool set_monster_timewalk(player_type *target_ptr, int num, MONSTER_IDX who, bool vs_player)
849 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[hack_m_idx]; /* the world monster */
851 if (current_world_ptr->timewalk_m_idx) return FALSE;
855 GAME_TEXT m_name[MAX_NLEN];
856 monster_desc(target_ptr, m_name, m_ptr, 0);
859 msg_format(_("「『ザ・ワールド』!時は止まった!」", "%s yells 'The World! Time has stopped!'"), m_name);
861 msg_format(_("「時よ!」", "%s yells 'Time!'"), m_name);
862 else msg_print("hek!");
867 /* This monster cast spells */
868 current_world_ptr->timewalk_m_idx = hack_m_idx;
870 if (vs_player) do_cmd_redraw(target_ptr);
874 if (!monster_is_valid(m_ptr)) break;
875 process_monster(target_ptr, current_world_ptr->timewalk_m_idx);
877 handle_stuff(target_ptr);
879 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
882 target_ptr->redraw |= (PR_MAP);
883 target_ptr->update |= (PU_MONSTERS);
884 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
886 current_world_ptr->timewalk_m_idx = 0;
887 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)))
889 msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
893 handle_stuff(target_ptr);
898 * @brief モンスターの経験値取得処理
899 * @param target_ptr プレーヤーへの参照ポインタ
900 * @param m_idx 経験値を得るモンスターの参照ID
901 * @param s_idx 撃破されたモンスター種族の参照ID
904 void monster_gain_exp(player_type *target_ptr, MONSTER_IDX m_idx, MONRACE_IDX s_idx)
909 if (m_idx <= 0 || s_idx <= 0) return;
911 floor_type *floor_ptr = target_ptr->current_floor_ptr;
912 m_ptr = &floor_ptr->m_list[m_idx];
914 if (!monster_is_valid(m_ptr)) return;
916 r_ptr = &r_info[m_ptr->r_idx];
917 s_ptr = &r_info[s_idx];
919 if (target_ptr->phase_out) return;
921 if (!r_ptr->next_exp) return;
923 int new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
924 if (m_idx == target_ptr->riding) new_exp = (new_exp + 1) / 2;
925 if (!floor_ptr->dun_level) new_exp /= 5;
926 m_ptr->exp += new_exp;
927 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
929 if (m_ptr->exp < r_ptr->next_exp)
931 if (m_idx == target_ptr->riding) target_ptr->update |= PU_BONUS;
935 GAME_TEXT m_name[MAX_NLEN];
936 int old_hp = m_ptr->hp;
937 int old_maxhp = m_ptr->max_maxhp;
938 int old_r_idx = m_ptr->r_idx;
939 byte old_sub_align = m_ptr->sub_align;
941 /* Hack -- Reduce the racial counter of previous monster */
942 real_r_ptr(m_ptr)->cur_num--;
944 monster_desc(target_ptr, m_name, m_ptr, 0);
945 m_ptr->r_idx = r_ptr->next_r_idx;
947 /* Count the monsters on the level */
948 real_r_ptr(m_ptr)->cur_num++;
950 m_ptr->ap_r_idx = m_ptr->r_idx;
951 r_ptr = &r_info[m_ptr->r_idx];
953 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
955 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
959 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
961 if (ironman_nightmare)
963 HIT_POINT hp = m_ptr->max_maxhp * 2L;
964 m_ptr->max_maxhp = MIN(30000, hp);
967 m_ptr->maxhp = m_ptr->max_maxhp;
968 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
970 /* dealt damage is 0 at initial*/
971 m_ptr->dealt_damage = 0;
973 /* Extract the monster base speed */
974 m_ptr->mspeed = get_mspeed(target_ptr, r_ptr);
976 /* Sub-alignment of a monster */
977 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
978 m_ptr->sub_align = old_sub_align;
981 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
982 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
983 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
988 if (is_pet(m_ptr) || m_ptr->ml)
990 if (!ignore_unview || player_can_see_bold(target_ptr, m_ptr->fy, m_ptr->fx))
992 if (target_ptr->image)
994 monster_race *hallu_race;
998 hallu_race = &r_info[randint1(max_r_idx - 1)];
999 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
1000 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name);
1004 msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name);
1008 if (!target_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
1010 /* Now you feel very close to this pet. */
1011 m_ptr->parent_m_idx = 0;
1014 update_monster(target_ptr, m_idx, FALSE);
1015 lite_spot(target_ptr, m_ptr->fy, m_ptr->fx);
1017 if (m_idx == target_ptr->riding) target_ptr->update |= PU_BONUS;
1021 * @brief モンスターのHPをダメージに応じて減算する /
1022 * Decreases monsters hit points, handling monster death.
1023 * @param dam 与えたダメージ量
1024 * @param m_idx ダメージを与えたモンスターのID
1025 * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
1026 * @param note モンスターが倒された際の特別なメッセージ述語
1030 * We return TRUE if the monster has been killed (and deleted).
1031 * We announce monster death (using an optional "death message"
1032 * if given, and a otherwise a generic killed/destroyed message).
1033 * Only "physical attacks" can induce the "You have slain" message.
1034 * Missile and Spell attacks will induce the "dies" message, or
1035 * various "specialized" messages. Note that "You have destroyed"
1036 * and "is destroyed" are synonyms for "You have slain" and "dies".
1037 * Hack -- unseen monsters yield "You have killed it." message.
1038 * Added fear (DGK) and check whether to print fear messages -CWS
1039 * Made name, sex, and capitalization generic -BEN-
1040 * As always, the "ghost" processing is a total hack.
1041 * Hack -- we "delay" fear messages by passing around a "fear" flag.
1042 * Consider decreasing monster experience over time, say,
1043 * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
1044 * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
1045 * monster worth more than subsequent monsters. This would also need
1046 * to induce changes in the monster recall code.
1049 bool mon_take_hit(player_type *target_ptr, MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
1051 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1052 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1053 monster_type exp_mon;
1055 /* Innocent until proven otherwise */
1056 bool innocent = TRUE, thief = FALSE;
1060 (void)COPY(&exp_mon, m_ptr, monster_type);
1062 expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
1064 get_exp_from_mon(target_ptr, expdam, &exp_mon);
1066 /* Genocided by chaos patron */
1067 if (!monster_is_valid(m_ptr)) m_idx = 0;
1069 /* Redraw (later) if needed */
1070 if (target_ptr->health_who == m_idx) target_ptr->redraw |= (PR_HEALTH);
1071 if (target_ptr->riding == m_idx) target_ptr->redraw |= (PR_UHEALTH);
1073 (void)set_monster_csleep(target_ptr, m_idx, 0);
1075 /* Hack - Cancel any special player stealth magics. -LM- */
1076 if (target_ptr->special_defense & NINJA_S_STEALTH)
1078 set_superstealth(target_ptr, FALSE);
1081 /* Genocided by chaos patron */
1082 if (!m_idx) return TRUE;
1085 m_ptr->dealt_damage += dam;
1087 if (m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
1089 if (current_world_ptr->wizard)
1091 msg_format(_("合計%d/%dのダメージを与えた。", "You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
1094 /* It is dead now */
1097 GAME_TEXT m_name[MAX_NLEN];
1099 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1101 /* You might have unmasked Tanuki first time */
1102 r_ptr = &r_info[m_ptr->r_idx];
1103 m_ptr->ap_r_idx = m_ptr->r_idx;
1104 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1107 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1109 /* You might have unmasked Chameleon first time */
1110 r_ptr = real_r_ptr(m_ptr);
1111 if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1114 if (!(m_ptr->smart & SM_CLONED))
1116 /* When the player kills a Unique, it stays dead */
1117 if (r_ptr->flags1 & RF1_UNIQUE)
1121 /* Mega-Hack -- Banor & Lupart */
1122 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1124 r_info[MON_BANORLUPART].max_num = 0;
1125 r_info[MON_BANORLUPART].r_pkills++;
1126 r_info[MON_BANORLUPART].r_akills++;
1127 if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1129 else if (m_ptr->r_idx == MON_BANORLUPART)
1131 r_info[MON_BANOR].max_num = 0;
1132 r_info[MON_BANOR].r_pkills++;
1133 r_info[MON_BANOR].r_akills++;
1134 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1135 r_info[MON_LUPART].max_num = 0;
1136 r_info[MON_LUPART].r_pkills++;
1137 r_info[MON_LUPART].r_akills++;
1138 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1142 /* When the player kills a Nazgul, it stays dead */
1143 else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1146 /* Count all monsters killed */
1147 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1149 /* Recall even invisible uniques or winners */
1150 if ((m_ptr->ml && !target_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1152 /* Count kills this life */
1153 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1154 else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1156 /* Count kills in all lives */
1157 if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1158 else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1160 /* Hack -- Auto-recall */
1161 monster_race_track(target_ptr, m_ptr->ap_r_idx);
1164 monster_desc(target_ptr, m_name, m_ptr, MD_TRUE_NAME);
1166 /* Don't kill Amberites */
1167 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1169 int curses = 1 + randint1(3);
1170 bool stop_ty = FALSE;
1173 msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
1174 curse_equipment(target_ptr, 100, 50);
1178 stop_ty = activate_ty_curse(target_ptr, stop_ty, &count);
1182 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1184 char line_got[1024];
1185 if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
1187 msg_format("%^s %s", m_name, line_got);
1191 if (m_ptr->r_idx == MON_SERPENT)
1193 screen_dump = make_screen_dump(target_ptr);
1198 if (!(d_info[target_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1200 if (!target_ptr->current_floor_ptr->dun_level && !target_ptr->ambush_flag && !target_ptr->current_floor_ptr->inside_arena)
1202 chg_virtue(target_ptr, V_VALOUR, -1);
1204 else if (r_ptr->level > target_ptr->current_floor_ptr->dun_level)
1206 if (randint1(10) <= (r_ptr->level - target_ptr->current_floor_ptr->dun_level))
1207 chg_virtue(target_ptr, V_VALOUR, 1);
1209 if (r_ptr->level > 60)
1211 chg_virtue(target_ptr, V_VALOUR, 1);
1213 if (r_ptr->level >= 2 * (target_ptr->lev + 1))
1214 chg_virtue(target_ptr, V_VALOUR, 2);
1217 if (r_ptr->flags1 & RF1_UNIQUE)
1219 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(target_ptr, V_HARMONY, 2);
1221 if (r_ptr->flags3 & RF3_GOOD)
1223 chg_virtue(target_ptr, V_UNLIFE, 2);
1224 chg_virtue(target_ptr, V_VITALITY, -2);
1227 if (one_in_(3)) chg_virtue(target_ptr, V_INDIVIDUALISM, -1);
1230 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1232 chg_virtue(target_ptr, V_COMPASSION, -1);
1235 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * target_ptr->current_floor_ptr->dun_level) >= randint1(100)))
1236 chg_virtue(target_ptr, V_UNLIFE, 1);
1238 if (r_ptr->d_char == 'A')
1240 if (r_ptr->flags1 & RF1_UNIQUE)
1241 chg_virtue(target_ptr, V_FAITH, -2);
1242 else if ((r_ptr->level) / 10 + (3 * target_ptr->current_floor_ptr->dun_level) >= randint1(100))
1244 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(target_ptr, V_FAITH, -1);
1245 else chg_virtue(target_ptr, V_FAITH, 1);
1248 else if (r_ptr->flags3 & RF3_DEMON)
1250 if (r_ptr->flags1 & RF1_UNIQUE)
1251 chg_virtue(target_ptr, V_FAITH, 2);
1252 else if ((r_ptr->level) / 10 + (3 * target_ptr->current_floor_ptr->dun_level) >= randint1(100))
1253 chg_virtue(target_ptr, V_FAITH, 1);
1256 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1257 chg_virtue(target_ptr, V_VITALITY, 2);
1259 if (r_ptr->r_deaths)
1261 if (r_ptr->flags1 & RF1_UNIQUE)
1263 chg_virtue(target_ptr, V_HONOUR, 10);
1265 else if ((r_ptr->level) / 10 + (2 * target_ptr->current_floor_ptr->dun_level) >= randint1(100))
1267 chg_virtue(target_ptr, V_HONOUR, 1);
1270 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1272 chg_virtue(target_ptr, V_VALOUR, -1);
1275 for (i = 0; i < 4; i++)
1277 if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1279 if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1280 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1282 thief = TRUE; /* Thief! */
1285 /* The new law says it is illegal to live in the dungeon */
1286 if (r_ptr->level != 0) innocent = FALSE;
1290 if (r_ptr->flags1 & RF1_UNIQUE)
1291 chg_virtue(target_ptr, V_JUSTICE, 3);
1292 else if (1 + ((r_ptr->level) / 10 + (2 * target_ptr->current_floor_ptr->dun_level)) >= randint1(100))
1293 chg_virtue(target_ptr, V_JUSTICE, 1);
1297 chg_virtue(target_ptr, V_JUSTICE, -1);
1300 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)))
1302 if (one_in_(4)) chg_virtue(target_ptr, V_NATURE, -1);
1305 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1308 sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
1309 exe_write_diary(target_ptr, DIARY_UNIQUE, 0, note_buf);
1315 /* Death by Missile/Spell attack */
1318 msg_format("%^s%s", m_name, note);
1321 /* Death by physical attack -- invisible monster */
1322 else if (!m_ptr->ml)
1325 if ((target_ptr->pseikaku == SEIKAKU_COMBAT) || (target_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1326 msg_format("せっかくだから%sを殺した。", m_name);
1328 msg_format("%sを殺した。", m_name);
1330 msg_format("You have killed %s.", m_name);
1335 /* Death by Physical attack -- non-living monster */
1336 else if (!monster_living(m_ptr->r_idx))
1338 bool explode = FALSE;
1340 for (i = 0; i < 4; i++)
1342 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1345 /* Special note at death */
1347 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
1351 if ((target_ptr->pseikaku == SEIKAKU_COMBAT) || (target_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1352 msg_format("せっかくだから%sを倒した。", m_name);
1354 msg_format("%sを倒した。", m_name);
1356 msg_format("You have destroyed %s.", m_name);
1361 /* Death by Physical attack -- living monster */
1365 if ((target_ptr->pseikaku == SEIKAKU_COMBAT) || (target_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
1366 msg_format("せっかくだから%sを葬り去った。", m_name);
1368 msg_format("%sを葬り去った。", m_name);
1370 msg_format("You have slain %s.", m_name);
1374 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
1376 for (i = 0; i < MAX_BOUNTY; i++)
1378 if ((current_world_ptr->bounty_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
1380 msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
1386 /* Generate treasure */
1387 monster_death(target_ptr, m_idx, TRUE);
1389 /* Mega hack : replace IKETA to BIKETAL */
1390 if ((m_ptr->r_idx == MON_IKETA) && !(target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out))
1392 POSITION dummy_y = m_ptr->fy;
1393 POSITION dummy_x = m_ptr->fx;
1394 BIT_FLAGS mode = 0L;
1395 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1396 delete_monster_idx(target_ptr, m_idx);
1397 if (summon_named_creature(target_ptr, 0, dummy_y, dummy_x, MON_BIKETAL, mode))
1399 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha! *I* am Biketal!"));
1404 delete_monster_idx(target_ptr, m_idx);
1407 get_exp_from_mon(target_ptr, (long)exp_mon.max_maxhp * 2, &exp_mon);
1412 /* Monster is dead */
1418 /* Mega-Hack -- Pain cancels fear */
1419 if (MON_MONFEAR(m_ptr) && (dam > 0))
1422 if (set_monster_monfear(target_ptr, m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1429 /* Sometimes a monster gets scared by damage */
1430 if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1432 /* Percentage of fully healthy */
1433 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1436 * Run (sometimes) if at 10% or less of max hit points,
1437 * or (usually) when hit for half its current hit points
1439 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1441 /* Hack -- note fear */
1444 /* Hack -- Add some timed fear */
1445 (void)set_monster_monfear(target_ptr, m_idx, (randint1(10) +
1446 (((dam >= m_ptr->hp) && (percentage > 7)) ?
1447 20 : ((11 - percentage) * 5))));
1457 bool monster_is_valid(monster_type *m_ptr)
1459 return (m_ptr->r_idx != 0);