OSDN Git Service

[Refactor] 再定義したものへ置き換え
[hengbandforosx/hengbandosx.git] / src / effect / effect-monster.cpp
1 /*!
2  * @brief 魔法によるモンスターへの効果まとめ
3  * @date 2020/04/29
4  * @author Hourier
5  */
6
7 #include "effect/effect-monster.h"
8 #include "avatar/avatar.h"
9 #include "core/disturbance.h"
10 #include "core/player-redraw-types.h"
11 #include "core/stuff-handler.h"
12 #include "core/window-redrawer.h"
13 #include "effect/attribute-types.h"
14 #include "effect/effect-characteristics.h"
15 #include "effect/effect-monster-switcher.h"
16 #include "effect/effect-monster-util.h"
17 #include "floor/cave.h"
18 #include "floor/floor-object.h"
19 #include "game-option/play-record-options.h"
20 #include "grid/grid.h"
21 #include "io/write-diary.h"
22 #include "main/sound-definitions-table.h"
23 #include "main/sound-of-music.h"
24 #include "monster-floor/monster-death.h"
25 #include "monster-floor/monster-move.h"
26 #include "monster-floor/monster-remover.h"
27 #include "monster-race/monster-race.h"
28 #include "monster-race/race-flags-resistance.h"
29 #include "monster-race/race-flags1.h"
30 #include "monster-race/race-flags3.h"
31 #include "monster-race/race-flags7.h"
32 #include "monster-race/race-indice-types.h"
33 #include "monster-race/race-resistance-mask.h"
34 #include "monster/monster-damage.h"
35 #include "monster/monster-describer.h"
36 #include "monster/monster-description-types.h"
37 #include "monster/monster-info.h"
38 #include "monster/monster-status-setter.h"
39 #include "monster/monster-status.h"
40 #include "monster/monster-update.h"
41 #include "object-enchant/special-object-flags.h"
42 #include "object/object-kind-hook.h"
43 #include "spell-kind/blood-curse.h"
44 #include "spell-kind/spells-polymorph.h"
45 #include "spell-kind/spells-teleport.h"
46 #include "spells-effect-util.h"
47 #include "sv-definition/sv-other-types.h"
48 #include "system/floor-type-definition.h"
49 #include "system/grid-type-definition.h"
50 #include "system/monster-race-definition.h"
51 #include "system/monster-type-definition.h"
52 #include "system/object-type-definition.h"
53 #include "system/player-type-definition.h"
54 #include "util/bit-flags-calculator.h"
55 #include "view/display-messages.h"
56 #include <algorithm>
57
58 /*!
59  * @brief ビーム/ボルト/ボール系魔法によるモンスターへの効果があるかないかを判定する
60  * @param player_ptr プレイヤーへの参照ポインタ
61  * @param em_ptr モンスター効果構造体への参照ポインタ
62  * @return 効果が何もないならFALSE、何かあるならTRUE
63  */
64 static process_result is_affective(PlayerType *player_ptr, effect_monster_type *em_ptr)
65 {
66     if (!em_ptr->g_ptr->m_idx)
67         return PROCESS_FALSE;
68     if (em_ptr->who && (em_ptr->g_ptr->m_idx == em_ptr->who))
69         return PROCESS_FALSE;
70     if (sukekaku && ((em_ptr->m_ptr->r_idx == MON_SUKE) || (em_ptr->m_ptr->r_idx == MON_KAKU)))
71         return PROCESS_FALSE;
72     if (em_ptr->m_ptr->hp < 0)
73         return PROCESS_FALSE;
74     if (em_ptr->who || em_ptr->g_ptr->m_idx != player_ptr->riding)
75         return PROCESS_TRUE;
76
77     switch (em_ptr->attribute) {
78     case AttributeType::OLD_HEAL:
79     case AttributeType::OLD_SPEED:
80     case AttributeType::STAR_HEAL:
81         return PROCESS_TRUE;
82     case AttributeType::OLD_SLOW:
83     case AttributeType::OLD_SLEEP:
84     case AttributeType::OLD_CLONE:
85     case AttributeType::OLD_CONF:
86     case AttributeType::OLD_POLY:
87     case AttributeType::GENOCIDE:
88     case AttributeType::E_GENOCIDE:
89         return PROCESS_CONTINUE;
90     default:
91         break;
92     }
93
94     return PROCESS_FALSE;
95 }
96
97 /*!
98  * @brief 魔法の効果やモンスター種別(MAKE/FEMALE/なし)に応じて表示するメッセージを変更する
99  * @param player_ptr プレイヤーへの参照ポインタ
100  * @param em_ptr モンスター効果構造体への参照ポインタ
101  */
102 static void make_description_of_affecred_monster(PlayerType *player_ptr, effect_monster_type *em_ptr)
103 {
104     em_ptr->dam = (em_ptr->dam + em_ptr->r) / (em_ptr->r + 1);
105     monster_desc(player_ptr, em_ptr->m_name, em_ptr->m_ptr, 0);
106     monster_desc(player_ptr, em_ptr->m_poss, em_ptr->m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
107 }
108
109 /*!
110  * @brief モンスターへの効果属性による耐性及び効果を処理する( / Proccess affecting to monster by effect.
111  * @param player_ptr プレイヤーへの参照ポインタ
112  * @param em_ptr モンスター効果構造体への参照ポインタ
113  * @return 完全な耐性が発動したらCONTINUE、そうでないなら効果処理の結果
114  * @details
115  * 完全な耐性を持っていたら、一部属性を除いて影響は及ぼさない
116  * デバッグ属性、モンスター打撃、モンスター射撃であれば貫通する
117  */
118 static process_result exe_affect_monster_by_effect(PlayerType *player_ptr, effect_monster_type *em_ptr, std::optional<CapturedMonsterType *> cap_mon_ptr)
119 {
120     const std::vector<AttributeType> effect_arrtibute = {
121         AttributeType::OLD_CLONE,
122         AttributeType::STAR_HEAL,
123         AttributeType::OLD_HEAL,
124         AttributeType::OLD_SPEED,
125         AttributeType::CAPTURE,
126         AttributeType::PHOTO,
127     };
128     const auto check = [em_ptr](const AttributeType attribute) {
129         return em_ptr->attribute == attribute;
130     };
131
132     process_result result = is_affective(player_ptr, em_ptr);
133     if (result != PROCESS_TRUE) {
134         if (result == PROCESS_CONTINUE) {
135             em_ptr->note = _("には効果がなかった。", " is unaffected.");
136             em_ptr->dam = 0;
137         }
138         return result;
139     }
140
141     bool do_effect = em_ptr->r_ptr->resistance_flags.has_not(MonsterResistanceType::RESIST_ALL);
142     do_effect |= std::any_of(effect_arrtibute.cbegin(), effect_arrtibute.cend(), check);
143
144     if (do_effect)
145         return switch_effects_monster(player_ptr, em_ptr, cap_mon_ptr);
146
147     bool ignore_res_all = (em_ptr->attribute == AttributeType::DEBUG);
148     ignore_res_all |= (em_ptr->attribute == AttributeType::MONSTER_MELEE);
149     ignore_res_all |= (em_ptr->attribute == AttributeType::MONSTER_SHOOT);
150
151     if (em_ptr->r_ptr->resistance_flags.has(MonsterResistanceType::RESIST_ALL) && ignore_res_all)
152         return switch_effects_monster(player_ptr, em_ptr);
153
154     em_ptr->note = _("には完全な耐性がある!", " is immune.");
155     em_ptr->dam = 0;
156     if (is_original_ap_and_seen(player_ptr, em_ptr->m_ptr))
157         em_ptr->r_ptr->r_resistance_flags.set(MonsterResistanceType::RESIST_ALL);
158
159     if (em_ptr->attribute == AttributeType::LITE_WEAK || em_ptr->attribute == AttributeType::KILL_WALL)
160         em_ptr->skipped = true;
161
162     return PROCESS_CONTINUE;
163 }
164
165 /*!
166  * @brief ペットの死亡を処理する
167  * @param player_ptr プレイヤーへの参照ポインタ
168  * @param em_ptr モンスター効果構造体への参照ポインタ
169  */
170 static void effect_damage_killed_pet(PlayerType *player_ptr, effect_monster_type *em_ptr)
171 {
172     bool sad = is_pet(em_ptr->m_ptr) && !(em_ptr->m_ptr->ml);
173     if (em_ptr->known && em_ptr->note) {
174         monster_desc(player_ptr, em_ptr->m_name, em_ptr->m_ptr, MD_TRUE_NAME);
175         if (em_ptr->see_s_msg)
176             msg_format("%^s%s", em_ptr->m_name, em_ptr->note);
177         else
178             player_ptr->current_floor_ptr->monster_noise = true;
179     }
180
181     if (em_ptr->who > 0)
182         monster_gain_exp(player_ptr, em_ptr->who, em_ptr->m_ptr->r_idx);
183
184     monster_death(player_ptr, em_ptr->g_ptr->m_idx, false, em_ptr->attribute);
185     delete_monster_idx(player_ptr, em_ptr->g_ptr->m_idx);
186     if (sad)
187         msg_print(_("少し悲しい気分がした。", "You feel sad for a moment."));
188 }
189
190 /*!
191  * @brief モンスターの睡眠を処理する
192  * @param player_ptr プレイヤーへの参照ポインタ
193  * @param em_ptr モンスター効果構造体への参照ポインタ
194  */
195 static void effect_damage_makes_sleep(PlayerType *player_ptr, effect_monster_type *em_ptr)
196 {
197     if (em_ptr->note && em_ptr->seen_msg)
198         msg_format("%^s%s", em_ptr->m_name, em_ptr->note);
199     else if (em_ptr->see_s_msg)
200         message_pain(player_ptr, em_ptr->g_ptr->m_idx, em_ptr->dam);
201     else
202         player_ptr->current_floor_ptr->monster_noise = true;
203
204     if (em_ptr->do_sleep)
205         (void)set_monster_csleep(player_ptr, em_ptr->g_ptr->m_idx, em_ptr->do_sleep);
206 }
207
208 /*!
209  * @brief モンスターからモンスターへのダメージを処理する / Hurt the monster by damages another monster did.
210  * @param player_ptr プレイヤーへの参照ポインタ
211  * @param em_ptr モンスター効果構造体への参照ポインタ
212  * @return ダメージを処理しなかった(モンスターIDがプレイヤー自身)場合はFALSE、処理した(モンスターだった)場合TRUE
213  * @details
214  * モンスターIDがプレイヤー(0)の場合は処理しない。
215  */
216 static bool deal_effect_damage_from_monster(PlayerType *player_ptr, effect_monster_type *em_ptr)
217 {
218     if (em_ptr->who <= 0)
219         return false;
220
221     if (player_ptr->health_who == em_ptr->g_ptr->m_idx)
222         player_ptr->redraw |= (PR_HEALTH);
223     if (player_ptr->riding == em_ptr->g_ptr->m_idx)
224         player_ptr->redraw |= (PR_UHEALTH);
225
226     (void)set_monster_csleep(player_ptr, em_ptr->g_ptr->m_idx, 0);
227     em_ptr->m_ptr->hp -= em_ptr->dam;
228     if (em_ptr->m_ptr->hp < 0)
229         effect_damage_killed_pet(player_ptr, em_ptr);
230     else
231         effect_damage_makes_sleep(player_ptr, em_ptr);
232
233     return true;
234 }
235
236 /*!
237  * @brief 不潔な病人の治療処理
238  * @param player_ptr プレイヤーへの参照ポインタ
239  * @param em_ptr モンスター効果構造体への参照ポインタ
240  * @return 大賞モンスターが不潔な病人だった場合はTRUE、それ以外はFALSE
241  */
242 static bool heal_leaper(PlayerType *player_ptr, effect_monster_type *em_ptr)
243 {
244     if (!em_ptr->heal_leper)
245         return false;
246
247     if (em_ptr->seen_msg)
248         msg_print(_("不潔な病人は病気が治った!", "The Mangy looking leper is healed!"));
249
250     if (record_named_pet && is_pet(em_ptr->m_ptr) && em_ptr->m_ptr->nickname) {
251         char m2_name[MAX_NLEN];
252         monster_desc(player_ptr, m2_name, em_ptr->m_ptr, MD_INDEF_VISIBLE);
253         exe_write_diary(player_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_HEAL_LEPER, m2_name);
254     }
255
256     delete_monster_idx(player_ptr, em_ptr->g_ptr->m_idx);
257     return true;
258 }
259
260 /*!
261  * @brief プレイヤー起因の効果によるダメージを処理 / Deal damages from player and fear by them.
262  * @param player_ptr プレイヤーへの参照ポインタ
263  * @param em_ptr モンスター効果構造体への参照ポインタ
264  * @return モンスターが死んだらTRUE、生きていたらFALSE
265  * @details
266  * em_ptr->do_fearによる恐怖メッセージもここで表示。
267  */
268 static bool deal_effect_damage_from_player(PlayerType *player_ptr, effect_monster_type *em_ptr)
269 {
270     bool fear = false;
271     MonsterDamageProcessor mdp(player_ptr, em_ptr->g_ptr->m_idx, em_ptr->dam, &fear, em_ptr->attribute);
272     if (mdp.mon_take_hit(em_ptr->note_dies))
273         return true;
274
275     if (em_ptr->do_sleep)
276         anger_monster(player_ptr, em_ptr->m_ptr);
277
278     if (em_ptr->note && em_ptr->seen)
279         msg_format(_("%s%s", "%^s%s"), em_ptr->m_name, em_ptr->note);
280     else if (em_ptr->known && (em_ptr->dam || !em_ptr->do_fear))
281         message_pain(player_ptr, em_ptr->g_ptr->m_idx, em_ptr->dam);
282
283     if (((em_ptr->dam > 0) || em_ptr->get_angry) && !em_ptr->do_sleep)
284         anger_monster(player_ptr, em_ptr->m_ptr);
285
286     if ((fear || em_ptr->do_fear) && em_ptr->seen) {
287         sound(SOUND_FLEE);
288         msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), em_ptr->m_name);
289     }
290
291     return false;
292 }
293
294 /*!
295  * @brief モンスターに効果のダメージを与える / Deal effect damage to monster.
296  * @param player_ptr プレイヤーへの参照ポインタ
297  * @param em_ptr モンスター効果構造体への参照ポインタ
298  * @details
299  * 以下のいずれかの処理を行う。
300  * 1.モンスターによる効果ダメージの処理
301  * 2.不潔な病人を癒す処理
302  * 3.プレイヤーによる効果ダメージの処理
303  * 4.睡眠する処理
304  */
305 static void deal_effect_damage_to_monster(PlayerType *player_ptr, effect_monster_type *em_ptr)
306 {
307     if (em_ptr->attribute == AttributeType::DRAIN_MANA)
308         return;
309
310     // モンスターによる効果
311     if (deal_effect_damage_from_monster(player_ptr, em_ptr))
312         return;
313
314     //プレイヤーによる効果
315     if (heal_leaper(player_ptr, em_ptr))
316         return;
317     if (deal_effect_damage_from_player(player_ptr, em_ptr))
318         return;
319
320     if (em_ptr->do_sleep)
321         (void)set_monster_csleep(player_ptr, em_ptr->g_ptr->m_idx, em_ptr->do_sleep);
322 }
323
324 /*!
325  * @brief プレイヤーが眠っている敵に効果を及ぼした場合の徳の変化
326  * @param player_ptr プレイヤーへの参照ポインタ
327  * @param em_ptr モンスター効果構造体への参照ポインタ
328  */
329 static void effect_makes_change_virtues(PlayerType *player_ptr, effect_monster_type *em_ptr)
330 {
331     if ((em_ptr->who > 0) || !em_ptr->slept)
332         return;
333
334     if (em_ptr->r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5))
335         chg_virtue(player_ptr, V_COMPASSION, -1);
336     if (em_ptr->r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5))
337         chg_virtue(player_ptr, V_HONOUR, -1);
338 }
339
340 /*!
341  * @brief 魔法効果に対する強制処理(変身の強制解除、死なない処理)
342  * @param player_ptr プレイヤーへの参照ポインタ
343  * @param em_ptr モンスター効果構造体への参照ポインタ
344  */
345 static void affected_monster_prevents_bad_status(PlayerType *player_ptr, effect_monster_type *em_ptr)
346 {
347     if (em_ptr->r_ptr->kind_flags.has(MonsterKindType::UNIQUE) || any_bits(em_ptr->r_ptr->flags1, RF1_QUESTOR) || (player_ptr->riding && (em_ptr->g_ptr->m_idx == player_ptr->riding)))
348         em_ptr->do_polymorph = false;
349
350     if ((em_ptr->r_ptr->kind_flags.has(MonsterKindType::UNIQUE) || any_bits(em_ptr->r_ptr->flags1, RF1_QUESTOR) || (em_ptr->r_ptr->flags7 & RF7_NAZGUL)) && !player_ptr->phase_out && (em_ptr->who > 0) && (em_ptr->dam > em_ptr->m_ptr->hp))
351         em_ptr->dam = em_ptr->m_ptr->hp;
352 }
353
354 /*!
355  * @brief モンスターの朦朧値を蓄積させる
356  * @param player_ptr プレイヤーへの参照ポインタ
357  * @param em_ptr モンスター効果構造体への参照ポインタ
358  * @param stun_damage 朦朧値
359  */
360 static void effect_damage_piles_stun(PlayerType *player_ptr, effect_monster_type *em_ptr)
361 {
362     if ((em_ptr->do_stun == 0) || em_ptr->r_ptr->resistance_flags.has_any_of({ MonsterResistanceType::RESIST_SOUND, MonsterResistanceType::RESIST_FORCE }) || (em_ptr->r_ptr->flags3 & RF3_NO_STUN))
363         return;
364
365     if (em_ptr->seen)
366         em_ptr->obvious = true;
367
368     int turns = 0;
369     if (monster_stunned_remaining(em_ptr->m_ptr)) {
370         em_ptr->note = _("はひどくもうろうとした。", " is more dazed.");
371         turns = monster_stunned_remaining(em_ptr->m_ptr) + (em_ptr->do_stun / 2);
372     } else {
373         em_ptr->note = _("はもうろうとした。", " is dazed.");
374         turns = em_ptr->do_stun;
375     }
376
377     (void)set_monster_stunned(player_ptr, em_ptr->g_ptr->m_idx, turns);
378     em_ptr->get_angry = true;
379 }
380
381 /*!
382  * @brief モンスターの混乱値を蓄積させる
383  * @param player_ptr プレイヤーへの参照ポインタ
384  * @param em_ptr モンスター効果構造体への参照ポインタ
385  * @param stun_damage 混乱値
386  */
387 static void effect_damage_piles_confusion(PlayerType *player_ptr, effect_monster_type *em_ptr)
388 {
389     if ((em_ptr->do_conf == 0) || (em_ptr->r_ptr->flags3 & RF3_NO_CONF) || em_ptr->r_ptr->resistance_flags.has_any_of(RFR_EFF_RESIST_CHAOS_MASK))
390         return;
391
392     if (em_ptr->seen)
393         em_ptr->obvious = true;
394
395     int turns = 0;
396     if (monster_confused_remaining(em_ptr->m_ptr)) {
397         em_ptr->note = _("はさらに混乱したようだ。", " looks more confused.");
398         turns = monster_confused_remaining(em_ptr->m_ptr) + (em_ptr->do_conf / 2);
399     } else {
400         em_ptr->note = _("は混乱したようだ。", " looks confused.");
401         turns = em_ptr->do_conf;
402     }
403
404     (void)set_monster_confused(player_ptr, em_ptr->g_ptr->m_idx, turns);
405     em_ptr->get_angry = true;
406 }
407
408 /*!
409  * @brief モンスターの恐怖値を蓄積させる
410  * @param player_ptr プレイヤーへの参照ポインタ
411  * @param em_ptr モンスター効果構造体への参照ポインタ
412  * @param stun_damage 恐怖値
413  * @details
414  * 打撃ダメージによる恐怖もあるため、メッセージは後で表示。
415  */
416 static void effect_damage_piles_fear(PlayerType *player_ptr, effect_monster_type *em_ptr)
417 {
418     if (em_ptr->do_fear == 0 || any_bits(em_ptr->r_ptr->flags3, RF3_NO_FEAR))
419         return;
420
421     (void)set_monster_monfear(player_ptr, em_ptr->g_ptr->m_idx, monster_fear_remaining(em_ptr->m_ptr) + em_ptr->do_fear);
422     em_ptr->get_angry = true;
423 }
424
425 /*!
426  * @brief モンスターを衰弱させる
427  * @param em_ptr モンスター効果構造体への参照ポインタ
428  */
429 static void effect_damage_makes_weak(effect_monster_type *em_ptr)
430 {
431     if (em_ptr->do_time == 0)
432         return;
433
434     if (em_ptr->seen)
435         em_ptr->obvious = true;
436
437     if (em_ptr->do_time >= em_ptr->m_ptr->maxhp)
438         em_ptr->do_time = em_ptr->m_ptr->maxhp - 1;
439
440     if (em_ptr->do_time) {
441         em_ptr->note = _("は弱くなったようだ。", " seems weakened.");
442         em_ptr->m_ptr->maxhp -= em_ptr->do_time;
443         if ((em_ptr->m_ptr->hp - em_ptr->dam) > em_ptr->m_ptr->maxhp)
444             em_ptr->dam = em_ptr->m_ptr->hp - em_ptr->m_ptr->maxhp;
445     }
446
447     em_ptr->get_angry = true;
448 }
449
450 /*!
451  * @brief モンスターを変身させる
452  * @param player_ptr プレイヤーへの参照ポインタ
453  * @param em_ptr モンスター効果構造体への参照ポインタ
454  */
455 static void effect_damage_makes_polymorph(PlayerType *player_ptr, effect_monster_type *em_ptr)
456 {
457     if (!em_ptr->do_polymorph || (randint1(90) <= em_ptr->r_ptr->level))
458         return;
459
460     if (polymorph_monster(player_ptr, em_ptr->y, em_ptr->x)) {
461         if (em_ptr->seen)
462             em_ptr->obvious = true;
463
464         em_ptr->note = _("が変身した!", " changes!");
465         em_ptr->dam = 0;
466     }
467
468     em_ptr->m_ptr = &player_ptr->current_floor_ptr->m_list[em_ptr->g_ptr->m_idx];
469     em_ptr->r_ptr = &r_info[em_ptr->m_ptr->r_idx];
470 }
471
472 /*!
473  * @brief モンスターをテレポートさせる
474  * @param player_ptr プレイヤーへの参照ポインタ
475  * @param em_ptr モンスター効果構造体への参照ポインタ
476  */
477 static void effect_damage_makes_teleport(PlayerType *player_ptr, effect_monster_type *em_ptr)
478 {
479     if (em_ptr->do_dist == 0)
480         return;
481
482     if (em_ptr->seen)
483         em_ptr->obvious = true;
484
485     em_ptr->note = _("が消え去った!", " disappears!");
486
487     if (!em_ptr->who)
488         chg_virtue(player_ptr, V_VALOUR, -1);
489
490     teleport_flags tflag = i2enum<teleport_flags>((!em_ptr->who ? TELEPORT_DEC_VALOUR : TELEPORT_SPONTANEOUS) | TELEPORT_PASSIVE);
491     teleport_away(player_ptr, em_ptr->g_ptr->m_idx, em_ptr->do_dist, tflag);
492
493     em_ptr->y = em_ptr->m_ptr->fy;
494     em_ptr->x = em_ptr->m_ptr->fx;
495     em_ptr->g_ptr = &player_ptr->current_floor_ptr->grid_array[em_ptr->y][em_ptr->x];
496 }
497
498 /*!
499  * @brief モンスターへのダメージに応じたメッセージを表示させ、異常状態を与える
500  * @param player_ptr プレイヤーへの参照ポインタ
501  * @param em_ptr モンスター効果構造体への参照ポインタ
502  * @details
503  * 以下の判定と処理を行う。
504  * 1.全耐性または無敵でダメージが通らなかった場合
505  * 2.ダメージ量が現HPを上回る場合
506  * 3.通常時(デバフをかける)
507  */
508 static void effect_damage_gives_bad_status(PlayerType *player_ptr, effect_monster_type *em_ptr)
509 {
510     int tmp_damage = em_ptr->dam;
511     em_ptr->dam = mon_damage_mod(player_ptr, em_ptr->m_ptr, em_ptr->dam, (bool)(em_ptr->attribute == AttributeType::PSY_SPEAR));
512     if ((tmp_damage > 0) && (em_ptr->dam == 0) && em_ptr->seen)
513         em_ptr->note = _("はダメージを受けていない。", " is unharmed.");
514
515     if (em_ptr->dam > em_ptr->m_ptr->hp)
516         em_ptr->note = em_ptr->note_dies;
517     else {
518         effect_damage_piles_stun(player_ptr, em_ptr);
519         effect_damage_piles_confusion(player_ptr, em_ptr);
520         effect_damage_piles_fear(player_ptr, em_ptr);
521         effect_damage_makes_weak(em_ptr);
522         effect_damage_makes_polymorph(player_ptr, em_ptr);
523         effect_damage_makes_teleport(player_ptr, em_ptr);
524     }
525 }
526
527 /*!
528  * @brief 効果によるモンスターへのダメージと付随効果を処理する
529  * @param player_ptr プレイヤーへの参照ポインタ
530  * @param em_ptr モンスター効果構造体への参照ポインタ
531  * @details
532  * 以下の処理を行う。
533  * 1.奇襲による徳の変化
534  * 2.完全な耐性及び無敵によるダメージのカット
535  * 3.ダメージによる付随効果の処理(混乱/朦朧/恐怖/衰弱/変身/テレポート)
536  * 4.ダメージ処理及び恐怖メッセージ
537  * 5.悪魔領域血の呪いによる事後処理
538  */
539 static void exe_affect_monster_by_damage(PlayerType *player_ptr, effect_monster_type *em_ptr)
540 {
541     effect_makes_change_virtues(player_ptr, em_ptr);
542     affected_monster_prevents_bad_status(player_ptr, em_ptr);
543     effect_damage_gives_bad_status(player_ptr, em_ptr);
544     deal_effect_damage_to_monster(player_ptr, em_ptr);
545     if ((em_ptr->attribute == AttributeType::BLOOD_CURSE) && one_in_(4))
546         blood_curse_to_enemy(player_ptr, em_ptr->who);
547 }
548
549 /*!
550  * @brief モンスター闘技場にいる場合の画面更新処理
551  * @param player_ptr プレイヤーへの参照ポインタ
552  * @param em_ptr モンスター効果構造体への参照ポインタ
553  */
554 static void update_phase_out_stat(PlayerType *player_ptr, effect_monster_type *em_ptr)
555 {
556     if (!player_ptr->phase_out)
557         return;
558
559     player_ptr->health_who = em_ptr->g_ptr->m_idx;
560     player_ptr->redraw |= (PR_HEALTH);
561     handle_stuff(player_ptr);
562 }
563
564 /*!
565  * @brief 魔法効果がペットに及んだ時の処理
566  * @param player_ptr プレイヤーへの参照ポインタ
567  * @param em_ptr モンスター効果構造体への参照ポインタ
568  */
569 static void postprocess_by_effected_pet(PlayerType *player_ptr, effect_monster_type *em_ptr)
570 {
571     if ((em_ptr->dam <= 0) || is_pet(em_ptr->m_ptr) || is_friendly(em_ptr->m_ptr))
572         return;
573
574     if (em_ptr->who == 0) {
575         if (!(em_ptr->flag & PROJECT_NO_HANGEKI))
576             set_target(em_ptr->m_ptr, monster_target_y, monster_target_x);
577
578         return;
579     }
580
581     if ((em_ptr->who > 0) && is_pet(em_ptr->m_caster_ptr) && !player_bold(player_ptr, em_ptr->m_ptr->target_y, em_ptr->m_ptr->target_x))
582         set_target(em_ptr->m_ptr, em_ptr->m_caster_ptr->fy, em_ptr->m_caster_ptr->fx);
583 }
584
585 /*!
586  * @brief 魔法効果が騎乗モンスターに及んだ時の処理
587  * @param player_ptr プレイヤーへの参照ポインタ
588  * @param em_ptr モンスター効果構造体への参照ポインタ
589  */
590 static void postprocess_by_riding_pet_effected(PlayerType *player_ptr, effect_monster_type *em_ptr)
591 {
592     if (!player_ptr->riding || (player_ptr->riding != em_ptr->g_ptr->m_idx) || (em_ptr->dam <= 0))
593         return;
594
595     if (em_ptr->m_ptr->hp > (em_ptr->m_ptr->maxhp / 3))
596         em_ptr->dam = (em_ptr->dam + 1) / 2;
597
598     rakubadam_m = (em_ptr->dam > 200) ? 200 : em_ptr->dam;
599 }
600
601 /*!
602  * @brief 写真を撮った時の処理
603  * @param player_ptr プレイヤーへの参照ポインタ
604  * @param em_ptr モンスター効果構造体への参照ポインタ
605  * @details 写真のフラッシュは弱閃光属性
606  */
607 static void postprocess_by_taking_photo(PlayerType *player_ptr, effect_monster_type *em_ptr)
608 {
609     if (em_ptr->photo == 0)
610         return;
611
612     ObjectType *q_ptr;
613     ObjectType forge;
614     q_ptr = &forge;
615     q_ptr->prep(lookup_kind(ItemKindType::STATUE, SV_PHOTO));
616     q_ptr->pval = em_ptr->photo;
617     q_ptr->ident |= (IDENT_FULL_KNOWN);
618     (void)drop_near(player_ptr, q_ptr, -1, player_ptr->y, player_ptr->x);
619 }
620
621 /*!
622  * @brief モンスター効果の後処理 (ペット関係、記念撮影、グローバル変数更新)
623  * @param player_ptr プレイヤーへの参照ポインタ
624  * @param em_ptr モンスター効果構造体への参照ポインタ
625  */
626 static void exe_affect_monster_postprocess(PlayerType *player_ptr, effect_monster_type *em_ptr)
627 {
628     postprocess_by_effected_pet(player_ptr, em_ptr);
629     postprocess_by_riding_pet_effected(player_ptr, em_ptr);
630     postprocess_by_taking_photo(player_ptr, em_ptr);
631     project_m_n++;
632     project_m_x = em_ptr->x;
633     project_m_y = em_ptr->y;
634 }
635
636 /*!
637  * @brief 汎用的なビーム/ボルト/ボール系によるモンスターへの効果処理 / Handle a beam/bolt/ball causing damage to a monster.
638  * @param player_ptr プレイヤーへの参照ポインタ
639  * @param who 魔法を発動したモンスター(0ならばプレイヤー) / Index of "source" monster (zero for "player")
640  * @param r 効果半径(ビーム/ボルト = 0 / ボール = 1以上) / Radius of explosion (0 = beam/bolt, 1 to 9 = ball)
641  * @param y 目標y座標 / Target y location (or location to travel "towards")
642  * @param x 目標x座標 / Target x location (or location to travel "towards")
643  * @param dam 基本威力 / Base damage roll to apply to affected monsters (or player)
644  * @param attribute 効果属性 / Type of damage to apply to monsters (and objects)
645  * @param flag 効果フラグ
646  * @param see_s_msg TRUEならばメッセージを表示する
647  * @return 何か一つでも効力があればTRUEを返す / TRUE if any "effects" of the projection were observed, else FALSE
648  * @details
649  * 以下の処理を行う。
650  * 1.魔法効果による効果に対する耐性による軽減計算及び効果の発動
651  * 2.魔法効果によるダメージの処理とダメージによる効果の発動
652  * 3.ペット及び撮影による事後効果
653  */
654 bool affect_monster(
655     PlayerType *player_ptr, MONSTER_IDX who, POSITION r, POSITION y, POSITION x, int dam, AttributeType attribute, BIT_FLAGS flag, bool see_s_msg, std::optional<CapturedMonsterType *> cap_mon_ptr)
656 {
657     effect_monster_type tmp_effect;
658     effect_monster_type *em_ptr = initialize_effect_monster(player_ptr, &tmp_effect, who, r, y, x, dam, attribute, flag, see_s_msg);
659
660     make_description_of_affecred_monster(player_ptr, em_ptr);
661
662     if (player_ptr->riding && (em_ptr->g_ptr->m_idx == player_ptr->riding))
663         disturb(player_ptr, true, true);
664
665     process_result result = exe_affect_monster_by_effect(player_ptr, em_ptr, cap_mon_ptr);
666     if (result != PROCESS_CONTINUE)
667         return (bool)result;
668
669     if (em_ptr->skipped)
670         return false;
671
672     exe_affect_monster_by_damage(player_ptr, em_ptr);
673
674     update_phase_out_stat(player_ptr, em_ptr);
675     if (em_ptr->m_ptr->r_idx)
676         update_monster(player_ptr, em_ptr->g_ptr->m_idx, false);
677
678     lite_spot(player_ptr, em_ptr->y, em_ptr->x);
679     if ((player_ptr->monster_race_idx == em_ptr->m_ptr->r_idx) && (em_ptr->seen || !em_ptr->m_ptr->r_idx))
680         player_ptr->window_flags |= (PW_MONSTER);
681
682     exe_affect_monster_postprocess(player_ptr, em_ptr);
683     return em_ptr->obvious;
684 }