OSDN Git Service

[Refactor] #3286 Removed player-redraw-types.h
[hengbandforosx/hengbandosx.git] / src / player / player-damage.cpp
1 #include "player/player-damage.h"
2 #include "autopick/autopick-pref-processor.h"
3 #include "avatar/avatar.h"
4 #include "blue-magic/blue-magic-checker.h"
5 #include "cmd-io/cmd-process-screen.h"
6 #include "core/asking-player.h"
7 #include "core/disturbance.h"
8 #include "core/stuff-handler.h"
9 #include "core/window-redrawer.h"
10 #include "dungeon/quest.h"
11 #include "flavor/flavor-describer.h"
12 #include "flavor/object-flavor-types.h"
13 #include "floor/wild.h"
14 #include "game-option/birth-options.h"
15 #include "game-option/cheat-options.h"
16 #include "game-option/game-play-options.h"
17 #include "game-option/input-options.h"
18 #include "game-option/play-record-options.h"
19 #include "game-option/special-options.h"
20 #include "inventory/inventory-damage.h"
21 #include "inventory/inventory-slot-types.h"
22 #include "io/files-util.h"
23 #include "io/input-key-acceptor.h"
24 #include "io/report.h"
25 #include "io/write-diary.h"
26 #include "main/music-definitions-table.h"
27 #include "main/sound-definitions-table.h"
28 #include "main/sound-of-music.h"
29 #include "market/arena-info-table.h"
30 #include "mind/mind-mirror-master.h"
31 #include "monster-race/monster-race.h"
32 #include "monster-race/race-flags2.h"
33 #include "monster-race/race-flags3.h"
34 #include "monster/monster-describer.h"
35 #include "monster/monster-description-types.h"
36 #include "monster/monster-info.h"
37 #include "mutation/mutation-flag-types.h"
38 #include "object-enchant/tr-types.h"
39 #include "object-hook/hook-armor.h"
40 #include "object/item-tester-hooker.h"
41 #include "object/object-broken.h"
42 #include "object/object-flags.h"
43 #include "player-base/player-class.h"
44 #include "player-base/player-race.h"
45 #include "player-info/class-info.h"
46 #include "player-info/race-types.h"
47 #include "player-info/samurai-data-type.h"
48 #include "player/player-personality-types.h"
49 #include "player/player-status-flags.h"
50 #include "player/player-status-resist.h"
51 #include "player/player-status.h"
52 #include "player/race-info-table.h"
53 #include "player/special-defense-types.h"
54 #include "racial/racial-android.h"
55 #include "save/save.h"
56 #include "status/base-status.h"
57 #include "status/element-resistance.h"
58 #include "system/building-type-definition.h"
59 #include "system/dungeon-info.h"
60 #include "system/floor-type-definition.h"
61 #include "system/item-entity.h"
62 #include "system/monster-entity.h"
63 #include "system/monster-race-info.h"
64 #include "system/player-type-definition.h"
65 #include "system/redrawing-flags-updater.h"
66 #include "term/screen-processor.h"
67 #include "term/term-color-types.h"
68 #include "timed-effect/player-hallucination.h"
69 #include "timed-effect/player-paralysis.h"
70 #include "timed-effect/timed-effects.h"
71 #include "util/bit-flags-calculator.h"
72 #include "util/string-processor.h"
73 #include "view/display-messages.h"
74 #include "world/world.h"
75 #include <sstream>
76 #include <string>
77
78 using dam_func = int (*)(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura);
79
80 /*!
81  * @brief 酸攻撃による装備のAC劣化処理 /
82  * Acid has hit the player, attempt to affect some armor.
83  * @param 酸を浴びたキャラクタへの参照ポインタ
84  * @return 装備による軽減があったならTRUEを返す
85  * @details
86  * 免疫があったらそもそもこの関数は実行されない (確実に錆びない).
87  * Note that the "base armor" of an object never changes.
88  * If any armor is damaged (or resists), the player takes less damage.
89  */
90 static bool acid_minus_ac(PlayerType *player_ptr)
91 {
92     constexpr static auto candidates = {
93         INVEN_MAIN_HAND,
94         INVEN_SUB_HAND,
95         INVEN_BODY,
96         INVEN_OUTER,
97         INVEN_ARMS,
98         INVEN_HEAD,
99         INVEN_FEET,
100     };
101
102     const auto slot = rand_choice(candidates);
103     auto *o_ptr = &player_ptr->inventory_list[slot];
104
105     if ((o_ptr == nullptr) || !o_ptr->is_valid() || !o_ptr->is_protector()) {
106         return false;
107     }
108
109     const auto item_name = describe_flavor(player_ptr, o_ptr, OD_OMIT_PREFIX | OD_NAME_ONLY);
110     auto flags = object_flags(o_ptr);
111     if (o_ptr->ac + o_ptr->to_a <= 0) {
112         msg_format(_("%sは既にボロボロだ!", "Your %s is already fully corroded!"), item_name.data());
113         return false;
114     }
115
116     if (flags.has(TR_IGNORE_ACID)) {
117         msg_format(_("しかし%sには効果がなかった!", "Your %s is unaffected!"), item_name.data());
118         return true;
119     }
120
121     msg_format(_("%sが酸で腐食した!", "Your %s is corroded!"), item_name.data());
122     o_ptr->to_a--;
123     auto &rfu = RedrawingFlagsUpdater::get_instance();
124     rfu.set_flag(StatusRedrawingFlag::BONUS);
125     player_ptr->window_flags |= PW_EQUIPMENT | PW_PLAYER;
126     calc_android_exp(player_ptr);
127     return true;
128 }
129
130 /*!
131  * @brief 酸属性によるプレイヤー損害処理 /
132  * Hurt the player with Acid
133  * @param player_ptr 酸を浴びたキャラクタへの参照ポインタ
134  * @param dam 基本ダメージ量
135  * @param kb_str ダメージ原因記述
136  * @param monspell 原因となったモンスター特殊攻撃ID
137  * @param aura オーラよるダメージが原因ならばTRUE
138  * @return 修正HPダメージ量
139  * @details 酸オーラは存在しないが関数ポインタのために引数だけは用意している
140  */
141 int acid_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
142 {
143     int inv = (dam < 30) ? 1 : (dam < 60) ? 2
144                                           : 3;
145     bool double_resist = is_oppose_acid(player_ptr);
146     dam = dam * calc_acid_damage_rate(player_ptr) / 100;
147     if (dam <= 0) {
148         return 0;
149     }
150
151     if (aura || !check_multishadow(player_ptr)) {
152         if ((!(double_resist || has_resist_acid(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
153             (void)do_dec_stat(player_ptr, A_CHR);
154         }
155
156         if (acid_minus_ac(player_ptr)) {
157             dam = (dam + 1) / 2;
158         }
159     }
160
161     int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
162     if (!aura && !(double_resist && has_resist_acid(player_ptr))) {
163         inventory_damage(player_ptr, BreakerAcid(), inv);
164     }
165
166     return get_damage;
167 }
168
169 /*!
170  * @brief 電撃属性によるプレイヤー損害処理 /
171  * Hurt the player with electricity
172  * @param player_ptr 電撃を浴びたキャラクタへの参照ポインタ
173  * @param dam 基本ダメージ量
174  * @param kb_str ダメージ原因記述
175  * @param monspell 原因となったモンスター特殊攻撃ID
176  * @param aura オーラよるダメージが原因ならばTRUE
177  * @return 修正HPダメージ量
178  */
179 int elec_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
180 {
181     int inv = (dam < 30) ? 1 : (dam < 60) ? 2
182                                           : 3;
183     bool double_resist = is_oppose_elec(player_ptr);
184
185     dam = dam * calc_elec_damage_rate(player_ptr) / 100;
186
187     if (dam <= 0) {
188         return 0;
189     }
190
191     if (aura || !check_multishadow(player_ptr)) {
192         if ((!(double_resist || has_resist_elec(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
193             (void)do_dec_stat(player_ptr, A_DEX);
194         }
195     }
196
197     int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
198     if (!aura && !(double_resist && has_resist_elec(player_ptr))) {
199         inventory_damage(player_ptr, BreakerElec(), inv);
200     }
201
202     return get_damage;
203 }
204
205 /*!
206  * @brief 火炎属性によるプレイヤー損害処理 /
207  * Hurt the player with Fire
208  * @param player_ptr 火炎を浴びたキャラクタへの参照ポインタ
209  * @param dam 基本ダメージ量
210  * @param kb_str ダメージ原因記述
211  * @param monspell 原因となったモンスター特殊攻撃ID
212  * @param aura オーラよるダメージが原因ならばTRUE
213  * @return 修正HPダメージ量
214  */
215 int fire_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
216 {
217     int inv = (dam < 30) ? 1 : (dam < 60) ? 2
218                                           : 3;
219     bool double_resist = is_oppose_fire(player_ptr);
220
221     /* Totally immune */
222     if (has_immune_fire(player_ptr) || (dam <= 0)) {
223         return 0;
224     }
225
226     dam = dam * calc_fire_damage_rate(player_ptr) / 100;
227     if (aura || !check_multishadow(player_ptr)) {
228         if ((!(double_resist || has_resist_fire(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
229             (void)do_dec_stat(player_ptr, A_STR);
230         }
231     }
232
233     int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
234     if (!aura && !(double_resist && has_resist_fire(player_ptr))) {
235         inventory_damage(player_ptr, BreakerFire(), inv);
236     }
237
238     return get_damage;
239 }
240
241 /*!
242  * @brief 冷気属性によるプレイヤー損害処理 /
243  * Hurt the player with Cold
244  * @param player_ptr 冷気を浴びたキャラクタへの参照ポインタ
245  * @param dam 基本ダメージ量
246  * @param kb_str ダメージ原因記述
247  * @param monspell 原因となったモンスター特殊攻撃ID
248  * @param aura オーラよるダメージが原因ならばTRUE
249  * @return 修正HPダメージ量
250  */
251 int cold_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
252 {
253     int inv = (dam < 30) ? 1 : (dam < 60) ? 2
254                                           : 3;
255     bool double_resist = is_oppose_cold(player_ptr);
256     if (has_immune_cold(player_ptr) || (dam <= 0)) {
257         return 0;
258     }
259
260     dam = dam * calc_cold_damage_rate(player_ptr) / 100;
261     if (aura || !check_multishadow(player_ptr)) {
262         if ((!(double_resist || has_resist_cold(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
263             (void)do_dec_stat(player_ptr, A_STR);
264         }
265     }
266
267     int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
268     if (!aura && !(double_resist && has_resist_cold(player_ptr))) {
269         inventory_damage(player_ptr, BreakerCold(), inv);
270     }
271
272     return get_damage;
273 }
274
275 /*
276  * Decreases players hit points and sets death flag if necessary
277  *
278  * Invulnerability needs to be changed into a "shield"
279  *
280  * Hack -- this function allows the user to save (or quit)
281  * the game when he dies, since the "You die." message is shown before
282  * setting the player to "dead".
283  */
284 int take_hit(PlayerType *player_ptr, int damage_type, int damage, std::string_view hit_from)
285 {
286     int old_chp = player_ptr->chp;
287     int warning = (player_ptr->mhp * hitpoint_warn / 10);
288     if (player_ptr->is_dead) {
289         return 0;
290     }
291
292     if (player_ptr->sutemi) {
293         damage *= 2;
294     }
295     if (PlayerClass(player_ptr).samurai_stance_is(SamuraiStanceType::IAI)) {
296         damage += (damage + 4) / 5;
297     }
298
299     if (damage_type != DAMAGE_USELIFE) {
300         disturb(player_ptr, true, true);
301         if (auto_more) {
302             player_ptr->now_damaged = true;
303         }
304     }
305
306     if ((damage_type != DAMAGE_USELIFE) && (damage_type != DAMAGE_LOSELIFE)) {
307         if (is_invuln(player_ptr) && (damage < 9000)) {
308             if (damage_type == DAMAGE_FORCE) {
309                 msg_print(_("バリアが切り裂かれた!", "The attack cuts your shield of invulnerability open!"));
310             } else if (one_in_(PENETRATE_INVULNERABILITY)) {
311                 msg_print(_("無敵のバリアを破って攻撃された!", "The attack penetrates your shield of invulnerability!"));
312             } else {
313                 return 0;
314             }
315         }
316
317         if (check_multishadow(player_ptr)) {
318             if (damage_type == DAMAGE_FORCE) {
319                 msg_print(_("幻影もろとも体が切り裂かれた!", "The attack hits Shadow together with you!"));
320             } else if (damage_type == DAMAGE_ATTACK) {
321                 msg_print(_("攻撃は幻影に命中し、あなたには届かなかった。", "The attack hits Shadow, but you are unharmed!"));
322                 return 0;
323             }
324         }
325
326         if (player_ptr->wraith_form) {
327             if (damage_type == DAMAGE_FORCE) {
328                 msg_print(_("半物質の体が切り裂かれた!", "The attack cuts through your ethereal body!"));
329             } else {
330                 damage /= 2;
331                 if ((damage == 0) && one_in_(2)) {
332                     damage = 1;
333                 }
334             }
335         }
336
337         if (PlayerClass(player_ptr).samurai_stance_is(SamuraiStanceType::MUSOU)) {
338             damage /= 2;
339             if ((damage == 0) && one_in_(2)) {
340                 damage = 1;
341             }
342         }
343     }
344
345     player_ptr->chp -= damage;
346     if (player_ptr->chp < -9999) {
347         player_ptr->chp = -9999;
348     }
349     if (damage_type == DAMAGE_GENO && player_ptr->chp < 0) {
350         damage += player_ptr->chp;
351         player_ptr->chp = 0;
352     }
353
354     auto &rfu = RedrawingFlagsUpdater::get_instance();
355     rfu.set_flag(MainWindowRedrawingFlag::HP);
356     player_ptr->window_flags |= PW_PLAYER;
357
358     if (damage_type != DAMAGE_GENO && player_ptr->chp == 0) {
359         chg_virtue(player_ptr, Virtue::SACRIFICE, 1);
360         chg_virtue(player_ptr, Virtue::CHANCE, 2);
361     }
362
363     if (player_ptr->chp < 0 && !cheat_immortal) {
364         bool android = PlayerRace(player_ptr).equals(PlayerRaceType::ANDROID);
365
366         /* 死んだ時に強制終了して死を回避できなくしてみた by Habu */
367         if (!cheat_save && !save_player(player_ptr, SaveType::CLOSE_GAME)) {
368             msg_print(_("セーブ失敗!", "death save failed!"));
369         }
370
371         sound(SOUND_DEATH);
372         chg_virtue(player_ptr, Virtue::SACRIFICE, 10);
373         handle_stuff(player_ptr);
374         player_ptr->leaving = true;
375         if (!cheat_immortal) {
376             player_ptr->is_dead = true;
377         }
378
379         const auto &floor_ref = *player_ptr->current_floor_ptr;
380         if (floor_ref.inside_arena) {
381             concptr m_name = monraces_info[arena_info[player_ptr->arena_number].r_idx].name.data();
382             msg_format(_("あなたは%sの前に敗れ去った。", "You are beaten by %s."), m_name);
383             msg_print(nullptr);
384             if (record_arena) {
385                 exe_write_diary(player_ptr, DIARY_ARENA, -1 - player_ptr->arena_number, m_name);
386             }
387         } else {
388             const auto q_idx = quest_number(player_ptr, floor_ref.dun_level);
389             const auto seppuku = hit_from == "Seppuku";
390             const auto winning_seppuku = w_ptr->total_winner && seppuku;
391
392             play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_GAMEOVER);
393
394 #ifdef WORLD_SCORE
395             screen_dump = make_screen_dump(player_ptr);
396 #endif
397             if (seppuku) {
398                 player_ptr->died_from = hit_from;
399                 if (!winning_seppuku) {
400                     player_ptr->died_from = _("切腹", "Seppuku");
401                 }
402             } else {
403                 auto effects = player_ptr->effects();
404                 auto is_hallucinated = effects->hallucination()->is_hallucinated();
405                 auto paralysis_state = "";
406                 if (effects->paralysis()->is_paralyzed()) {
407                     paralysis_state = player_ptr->free_act ? _("彫像状態で", " while being the statue") : _("麻痺状態で", " while paralyzed");
408                 }
409
410                 auto hallucintion_state = is_hallucinated ? _("幻覚に歪んだ", "hallucinatingly distorted ") : "";
411 #ifdef JP
412                 player_ptr->died_from = format("%s%s%s", paralysis_state, hallucintion_state, hit_from.data());
413 #else
414                 player_ptr->died_from = format("%s%s%s", hallucintion_state, hit_from.data(), paralysis_state);
415 #endif
416             }
417
418             w_ptr->total_winner = false;
419             if (winning_seppuku) {
420                 add_retired_class(player_ptr->pclass);
421                 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, _("勝利の後切腹した。", "committed seppuku after the winning."));
422             } else {
423                 std::string place;
424
425                 if (floor_ref.inside_arena) {
426                     place = _("アリーナ", "in the Arena");
427                 } else if (!floor_ref.is_in_dungeon()) {
428                     place = _("地上", "on the surface");
429                 } else if (inside_quest(q_idx) && (QuestType::is_fixed(q_idx) && !((q_idx == QuestId::OBERON) || (q_idx == QuestId::SERPENT)))) {
430                     place = _("クエスト", "in a quest");
431                 } else {
432                     place = format(_("%d階", "on level %d"), static_cast<int>(floor_ref.dun_level));
433                 }
434
435 #ifdef JP
436                 std::string note = format("%sで%sに殺された。", place.data(), player_ptr->died_from.data());
437 #else
438                 std::string note = format("killed by %s %s.", player_ptr->died_from.data(), place.data());
439 #endif
440                 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, note.data());
441             }
442
443             exe_write_diary(player_ptr, DIARY_GAMESTART, 1, _("-------- ゲームオーバー --------", "--------   Game  Over   --------"));
444             exe_write_diary(player_ptr, DIARY_DESCRIPTION, 1, "\n\n\n\n");
445             flush();
446             if (get_check_strict(player_ptr, _("画面を保存しますか?", "Dump the screen? "), CHECK_NO_HISTORY)) {
447                 do_cmd_save_screen(player_ptr);
448             }
449
450             flush();
451             if (player_ptr->last_message) {
452                 string_free(player_ptr->last_message);
453             }
454
455             player_ptr->last_message = nullptr;
456             if (!last_words) {
457 #ifdef JP
458                 msg_format("あなたは%sました。", android ? "壊れ" : "死に");
459 #else
460                 msg_print(android ? "You are broken." : "You die.");
461 #endif
462
463                 msg_print(nullptr);
464             } else {
465                 std::optional<std::string> opt_death_message;
466                 if (winning_seppuku) {
467                     opt_death_message = get_random_line(_("seppuku_j.txt", "seppuku.txt"), 0);
468                 } else {
469                     opt_death_message = get_random_line(_("death_j.txt", "death.txt"), 0);
470                 }
471
472                 auto &death_message = opt_death_message.value();
473                 constexpr auto max_last_words = 1024;
474                 char player_last_words[max_last_words]{};
475                 angband_strcpy(player_last_words, death_message.data(), max_last_words);
476                 do {
477 #ifdef JP
478                     while (!get_string(winning_seppuku ? "辞世の句: " : "断末魔の叫び: ", player_last_words, max_last_words)) {
479                         ;
480                     }
481 #else
482                     while (!get_string("Last words: ", player_last_words, max_last_words)) {
483                         ;
484                     }
485 #endif
486                 } while (winning_seppuku && !get_check_strict(player_ptr, _("よろしいですか?", "Are you sure? "), CHECK_NO_HISTORY));
487
488                 death_message = player_last_words;
489                 if (death_message.empty()) {
490 #ifdef JP
491                     death_message = format("あなたは%sました。", android ? "壊れ" : "死に");
492 #else
493                     death_message = android ? "You are broken." : "You die.";
494 #endif
495                 } else {
496                     player_ptr->last_message = string_make(death_message.data());
497                 }
498
499 #ifdef JP
500                 if (winning_seppuku) {
501                     int i, len;
502                     int w = game_term->wid;
503                     int h = game_term->hgt;
504                     int msg_pos_x[9] = { 5, 7, 9, 12, 14, 17, 19, 21, 23 };
505                     int msg_pos_y[9] = { 3, 4, 5, 4, 5, 4, 5, 6, 4 };
506                     term_clear();
507
508                     /* 桜散る */
509                     for (i = 0; i < 40; i++) {
510                         term_putstr(randint0(w / 2) * 2, randint0(h), 2, TERM_VIOLET, "υ");
511                     }
512
513                     auto str = death_message.data();
514                     if (strncmp(str, "「", 2) == 0) {
515                         str += 2;
516                     }
517
518                     auto *str2 = angband_strstr(str, "」");
519                     if (str2 != nullptr) {
520                         *str2 = '\0';
521                     }
522
523                     i = 0;
524                     while (i < 9) {
525                         str2 = angband_strstr(str, " ");
526                         if (str2 == nullptr) {
527                             len = strlen(str);
528                         } else {
529                             len = str2 - str;
530                         }
531
532                         if (len != 0) {
533                             term_putstr_v(w * 3 / 4 - 2 - msg_pos_x[i] * 2, msg_pos_y[i], len, TERM_WHITE, str);
534                             if (str2 == nullptr) {
535                                 break;
536                             }
537                             i++;
538                         }
539                         str = str2 + 1;
540                         if (*str == 0) {
541                             break;
542                         }
543                     }
544
545                     term_putstr(w - 1, h - 1, 1, TERM_WHITE, " ");
546                     flush();
547 #ifdef WORLD_SCORE
548                     screen_dump = make_screen_dump(player_ptr);
549 #endif
550                     (void)inkey();
551                 } else
552 #endif
553                     msg_print(death_message);
554             }
555         }
556
557         return damage;
558     }
559
560     handle_stuff(player_ptr);
561     if (player_ptr->chp < warning) {
562         if (old_chp > warning) {
563             bell();
564         }
565
566         sound(SOUND_WARN);
567         if (record_danger && (old_chp > warning)) {
568             if (player_ptr->effects()->hallucination()->is_hallucinated() && damage_type == DAMAGE_ATTACK) {
569                 hit_from = _("何か", "something");
570             }
571
572             std::stringstream ss;
573             ss << _(hit_from, "was in a critical situation because of ");
574             ss << _("によってピンチに陥った。", hit_from);
575             ss << _("", ".");
576             exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, ss.str().data());
577         }
578
579         if (auto_more) {
580             player_ptr->now_damaged = true;
581         }
582
583         msg_print(_("*** 警告:低ヒット・ポイント! ***", "*** LOW HITPOINT WARNING! ***"));
584         msg_print(nullptr);
585         flush();
586     }
587
588     if (player_ptr->wild_mode && !player_ptr->leaving && (player_ptr->chp < std::max(warning, player_ptr->mhp / 5))) {
589         change_wild_mode(player_ptr, false);
590     }
591
592     return damage;
593 }
594
595 /*!
596  * @brief 属性に応じた敵オーラによるプレイヤーのダメージ処理
597  * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
598  * @param immune ダメージを回避できる免疫フラグ
599  * @param flags_offset オーラフラグ配列の参照オフセット
600  * @param r_flags_offset モンスターの耐性配列の参照オフセット
601  * @param aura_flag オーラフラグ配列
602  * @param dam_func ダメージ処理を行う関数の参照ポインタ
603  * @param message オーラダメージを受けた際のメッセージ
604  */
605 static void process_aura_damage(MonsterEntity *m_ptr, PlayerType *player_ptr, bool immune, MonsterAuraType aura_flag, dam_func dam_func, concptr message)
606 {
607     auto *r_ptr = &monraces_info[m_ptr->r_idx];
608     if (r_ptr->aura_flags.has_not(aura_flag) || immune) {
609         return;
610     }
611
612     int aura_damage = damroll(1 + (r_ptr->level / 26), 1 + (r_ptr->level / 17));
613     msg_print(message);
614     (*dam_func)(player_ptr, aura_damage, monster_desc(player_ptr, m_ptr, MD_WRONGDOER_NAME).data(), true);
615     if (is_original_ap_and_seen(player_ptr, m_ptr)) {
616         r_ptr->r_aura_flags.set(aura_flag);
617     }
618
619     handle_stuff(player_ptr);
620 }
621
622 /*!
623  * @brief 敵オーラによるプレイヤーのダメージ処理
624  * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
625  * @param player_ptr プレイヤーへの参照ポインタ
626  */
627 void touch_zap_player(MonsterEntity *m_ptr, PlayerType *player_ptr)
628 {
629     constexpr auto fire_mes = _("突然とても熱くなった!", "You are suddenly very hot!");
630     constexpr auto cold_mes = _("突然とても寒くなった!", "You are suddenly very cold!");
631     constexpr auto elec_mes = _("電撃をくらった!", "You get zapped!");
632     process_aura_damage(m_ptr, player_ptr, has_immune_fire(player_ptr) != 0, MonsterAuraType::FIRE, fire_dam, fire_mes);
633     process_aura_damage(m_ptr, player_ptr, has_immune_cold(player_ptr) != 0, MonsterAuraType::COLD, cold_dam, cold_mes);
634     process_aura_damage(m_ptr, player_ptr, has_immune_elec(player_ptr) != 0, MonsterAuraType::ELEC, elec_dam, elec_mes);
635 }