OSDN Git Service

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