2 * @brief モンスター同士の打撃後処理 / Melee post-process.
5 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
6 * This software may be copied and distributed for educational, research,\n
7 * and not for profit purposes provided that this copyright and statement\n
8 * are included in all such copies. Other copyrights may also apply.\n
9 * 2014 Deskull rearranged comment for Doxygen.\n
13 #include "melee/melee-postprocess.h"
14 #include "core/disturbance.h"
15 #include "core/player-redraw-types.h"
16 #include "floor/cave.h"
17 #include "floor/geometry.h"
18 #include "grid/grid.h"
19 #include "main/sound-definitions-table.h"
20 #include "main/sound-of-music.h"
21 #include "monster-attack/monster-attack-types.h"
22 #include "monster-floor/monster-death.h"
23 #include "monster-floor/monster-move.h"
24 #include "monster-floor/monster-remover.h"
25 #include "monster-race/monster-race-hook.h"
26 #include "monster-race/monster-race.h"
27 #include "monster-race/race-flags-resistance.h"
28 #include "monster-race/race-flags1.h"
29 #include "monster-race/race-flags3.h"
30 #include "monster-race/race-flags7.h"
31 #include "monster/monster-describer.h"
32 #include "monster/monster-description-types.h"
33 #include "monster/monster-info.h"
34 #include "monster/monster-status-setter.h"
35 #include "monster/monster-status.h"
36 #include "pet/pet-fall-off.h"
37 #include "player/player-class.h"
38 #include "player/player-personality-types.h"
39 #include "player/player-race-types.h"
40 #include "system/floor-type-definition.h"
41 #include "system/monster-race-definition.h"
42 #include "system/monster-type-definition.h"
43 #include "system/player-type-definition.h"
44 #include "view/display-messages.h"
46 // Melee-post-process-type
47 typedef struct mam_pp_type {
51 GAME_TEXT m_name[160];
53 bool known; /* Can the player be aware of this attack? */
60 mam_pp_type *initialize_mam_pp_type(
61 player_type *player_ptr, mam_pp_type *mam_pp_ptr, MONSTER_IDX m_idx, HIT_POINT dam, bool *dead, bool *fear, concptr note, MONSTER_IDX who)
63 mam_pp_ptr->m_idx = m_idx;
64 mam_pp_ptr->m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
65 mam_pp_ptr->seen = is_seen(player_ptr, mam_pp_ptr->m_ptr);
66 mam_pp_ptr->dam = dam;
67 mam_pp_ptr->known = mam_pp_ptr->m_ptr->cdis <= MAX_SIGHT;
68 mam_pp_ptr->dead = dead;
69 mam_pp_ptr->fear = fear;
70 mam_pp_ptr->note = note;
71 mam_pp_ptr->who = who;
75 static void prepare_redraw(player_type *player_ptr, mam_pp_type *mam_pp_ptr)
77 if (!mam_pp_ptr->m_ptr->ml)
80 if (player_ptr->health_who == mam_pp_ptr->m_idx)
81 player_ptr->redraw |= (PR_HEALTH);
83 if (player_ptr->riding == mam_pp_ptr->m_idx)
84 player_ptr->redraw |= (PR_UHEALTH);
88 * @brief モンスターが無敵だった場合の処理
89 * @param mam_pp_ptr 標的モンスター構造体への参照ポインタ
90 * @return 無敵ノーダメならTRUE、無敵でないか無敵を貫通したらFALSE
92 static bool process_invulnerability(mam_pp_type *mam_pp_ptr)
94 if (monster_invulner_remaining(mam_pp_ptr->m_ptr) && randint0(PENETRATE_INVULNERABILITY))
98 msg_format(_("%^sはダメージを受けない。", "%^s is unharmed."), mam_pp_ptr->m_name);
105 * @param mam_pp_ptr 標的モンスター構造体への参照ポインタ
106 * @return ノーダメならTRUE、 そうでないならFALSE
108 static bool process_all_resistances(mam_pp_type *mam_pp_ptr)
110 monster_race *r_ptr = &r_info[mam_pp_ptr->m_ptr->r_idx];
111 if ((r_ptr->flagsr & RFR_RES_ALL) == 0)
114 if (mam_pp_ptr->dam > 0) {
115 mam_pp_ptr->dam /= 100;
116 if ((mam_pp_ptr->dam == 0) && one_in_(3))
120 if (mam_pp_ptr->dam != 0)
123 if (mam_pp_ptr->seen)
124 msg_format(_("%^sはダメージを受けない。", "%^s is unharmed."), mam_pp_ptr->m_name);
130 * @brief モンスター死亡時のメッセージ表示
131 * @param player_ptr プレーヤーへの参照ポインタ
132 * @param mam_pp_ptr 標的モンスター構造体への参照ポインタ
135 * 爆発して粉々になった等ならその旨を、残りは生命か無生命かで分岐
137 static void print_monster_dead_by_monster(player_type *player_ptr, mam_pp_type *mam_pp_ptr)
139 if (!mam_pp_ptr->known)
142 monster_desc(player_ptr, mam_pp_ptr->m_name, mam_pp_ptr->m_ptr, MD_TRUE_NAME);
143 if (!mam_pp_ptr->seen) {
144 player_ptr->current_floor_ptr->monster_noise = true;
148 if (mam_pp_ptr->note) {
149 msg_format(_("%^s%s", "%^s%s"), mam_pp_ptr->m_name, mam_pp_ptr->note);
153 if (!monster_living(mam_pp_ptr->m_ptr->r_idx)) {
154 msg_format(_("%^sは破壊された。", "%^s is destroyed."), mam_pp_ptr->m_name);
158 msg_format(_("%^sは殺された。", "%^s is killed."), mam_pp_ptr->m_name);
162 * @brief ダメージを受けたモンスターのHPが0未満になった際の処理
163 * @param player_ptr プレーヤーへの参照ポインタ
164 * @param mam_pp_ptr 標的モンスター構造体への参照ポインタ
165 * @return 生きていたらTRUE、それ以外 (ユニークは@以外の攻撃では死なない)はFALSE
167 static bool check_monster_hp(player_type *player_ptr, mam_pp_type *mam_pp_ptr)
169 monster_race *r_ptr = &r_info[mam_pp_ptr->m_ptr->r_idx];
170 if (mam_pp_ptr->m_ptr->hp < 0)
173 if (((r_ptr->flags1 & (RF1_UNIQUE | RF1_QUESTOR)) || (r_ptr->flags7 & RF7_NAZGUL)) && !player_ptr->phase_out) {
174 mam_pp_ptr->m_ptr->hp = 1;
178 sound_type kill_sound = monster_living(mam_pp_ptr->m_ptr->r_idx) ? SOUND_KILL : SOUND_N_KILL;
180 *(mam_pp_ptr->dead) = true;
181 print_monster_dead_by_monster(player_ptr, mam_pp_ptr);
182 monster_gain_exp(player_ptr, mam_pp_ptr->who, mam_pp_ptr->m_ptr->r_idx);
183 monster_death(player_ptr, mam_pp_ptr->m_idx, false);
184 delete_monster_idx(player_ptr, mam_pp_ptr->m_idx);
185 *(mam_pp_ptr->fear) = false;
190 * @brief 死亡等で恐慌状態をキャンセルする
191 * @param player_ptr プレーヤーへの参照ポインタ
192 * @param mam_pp_ptr 標的モンスター構造体への参照ポインタ
194 static void cancel_fear_by_pain(player_type *player_ptr, mam_pp_type *mam_pp_ptr)
196 if (!monster_fear_remaining(mam_pp_ptr->m_ptr) || (mam_pp_ptr->dam <= 0)
197 || !set_monster_monfear(player_ptr, mam_pp_ptr->m_idx, monster_fear_remaining(mam_pp_ptr->m_ptr) - randint1(mam_pp_ptr->dam / 4)))
200 *(mam_pp_ptr->fear) = false;
204 * @biref HP残量などに応じてモンスターを恐慌状態にする
205 * @param player_ptr プレーヤーへの参照ポインタ
206 * @param mam_pp_ptr 標的モンスター構造体への参照ポインタ
208 static void make_monster_fear(player_type *player_ptr, mam_pp_type *mam_pp_ptr)
210 monster_race *r_ptr = &r_info[mam_pp_ptr->m_ptr->r_idx];
211 if (monster_fear_remaining(mam_pp_ptr->m_ptr) || ((r_ptr->flags3 & RF3_NO_FEAR) == 0))
214 int percentage = (100L * mam_pp_ptr->m_ptr->hp) / mam_pp_ptr->m_ptr->maxhp;
215 bool can_make_fear = ((percentage <= 10) && (randint0(10) < percentage)) || ((mam_pp_ptr->dam >= mam_pp_ptr->m_ptr->hp) && (randint0(100) < 80));
219 *(mam_pp_ptr->fear) = true;
220 (void)set_monster_monfear(
221 player_ptr, mam_pp_ptr->m_idx, (randint1(10) + (((mam_pp_ptr->dam >= mam_pp_ptr->m_ptr->hp) && (percentage > 7)) ? 20 : ((11 - percentage) * 5))));
225 * @brief モンスター同士の乱闘による落馬処理
226 * @param player_ptr プレーヤーへの参照ポインタ
227 * @param mam_pp_ptr 標的モンスター構造体への参照ポインタ
229 static void fall_off_horse_by_melee(player_type *player_ptr, mam_pp_type *mam_pp_ptr)
231 if (!player_ptr->riding || (player_ptr->riding != mam_pp_ptr->m_idx) || (mam_pp_ptr->dam <= 0))
234 monster_desc(player_ptr, mam_pp_ptr->m_name, mam_pp_ptr->m_ptr, 0);
235 if (mam_pp_ptr->m_ptr->hp > mam_pp_ptr->m_ptr->maxhp / 3)
236 mam_pp_ptr->dam = (mam_pp_ptr->dam + 1) / 2;
238 if (process_fall_off_horse(player_ptr, (mam_pp_ptr->dam > 200) ? 200 : mam_pp_ptr->dam, false))
239 msg_format(_("%^sに振り落とされた!", "You have been thrown off from %s!"), mam_pp_ptr->m_name);
243 * @brief モンスターが敵モンスターに行う打撃処理 /
244 * Hack, based on mon_take_hit... perhaps all monster attacks on other monsters should use this?
245 * @param m_idx 目標となるモンスターの参照ID
247 * @param dead 目標となったモンスターの死亡状態を返す参照ポインタ
248 * @param fear 目標となったモンスターの恐慌状態を返す参照ポインタ
249 * @param note 目標モンスターが死亡した場合の特別メッセージ(NULLならば標準表示を行う)
250 * @param who 打撃を行ったモンスターの参照ID
251 * @todo 打撃が当たった時の後処理 (爆発持ちのモンスターを爆発させる等)なので、関数名を変更する必要あり
253 void mon_take_hit_mon(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam, bool *dead, bool *fear, concptr note, MONSTER_IDX who)
255 floor_type *floor_ptr = player_ptr->current_floor_ptr;
256 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
257 mam_pp_type tmp_mam_pp;
258 mam_pp_type *mam_pp_ptr = initialize_mam_pp_type(player_ptr, &tmp_mam_pp, m_idx, dam, dead, fear, note, who);
259 monster_desc(player_ptr, mam_pp_ptr->m_name, m_ptr, 0);
260 prepare_redraw(player_ptr, mam_pp_ptr);
261 (void)set_monster_csleep(player_ptr, m_idx, 0);
263 if (player_ptr->riding && (m_idx == player_ptr->riding))
264 disturb(player_ptr, true, true);
266 if (process_invulnerability(mam_pp_ptr) || process_all_resistances(mam_pp_ptr))
270 if (check_monster_hp(player_ptr, mam_pp_ptr))
274 cancel_fear_by_pain(player_ptr, mam_pp_ptr);
275 make_monster_fear(player_ptr, mam_pp_ptr);
276 if ((dam > 0) && !is_pet(m_ptr) && !is_friendly(m_ptr) && (mam_pp_ptr->who != m_idx)) {
277 if (is_pet(&floor_ptr->m_list[mam_pp_ptr->who]) && !player_bold(player_ptr, m_ptr->target_y, m_ptr->target_x)) {
278 set_target(m_ptr, floor_ptr->m_list[mam_pp_ptr->who].fy, floor_ptr->m_list[mam_pp_ptr->who].fx);
282 fall_off_horse_by_melee(player_ptr, mam_pp_ptr);