OSDN Git Service

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