OSDN Git Service

[Refactor] #3496 optional 型の値取得処理 value() を撤廃した その7
[hengbandforosx/hengbandosx.git] / src / combat / shoot.cpp
1 #include "combat/shoot.h"
2 #include "artifact/fixed-art-types.h"
3 #include "avatar/avatar.h"
4 #include "combat/attack-criticality.h"
5 #include "core/stuff-handler.h"
6 #include "effect/attribute-types.h"
7 #include "effect/effect-characteristics.h"
8 #include "effect/effect-processor.h"
9 #include "effect/spells-effect-util.h"
10 #include "flavor/flavor-describer.h"
11 #include "flavor/object-flavor-types.h"
12 #include "floor/cave.h"
13 #include "floor/floor-object.h"
14 #include "floor/geometry.h"
15 #include "game-option/cheat-types.h"
16 #include "game-option/special-options.h"
17 #include "grid/feature-flag-types.h"
18 #include "grid/feature.h"
19 #include "grid/grid.h"
20 #include "inventory/inventory-object.h"
21 #include "inventory/inventory-slot-types.h"
22 #include "io/cursor.h"
23 #include "io/screen-util.h"
24 #include "main/sound-definitions-table.h"
25 #include "main/sound-of-music.h"
26 #include "mind/mind-sniper.h"
27 #include "mind/snipe-types.h"
28 #include "monster-floor/monster-death.h"
29 #include "monster-floor/monster-move.h"
30 #include "monster-race/monster-race.h"
31 #include "monster-race/race-flags-resistance.h"
32 #include "monster-race/race-flags1.h"
33 #include "monster-race/race-flags2.h"
34 #include "monster-race/race-flags3.h"
35 #include "monster-race/race-flags7.h"
36 #include "monster-race/race-indice-types.h"
37 #include "monster-race/race-resistance-mask.h"
38 #include "monster/monster-damage.h"
39 #include "monster/monster-describer.h"
40 #include "monster/monster-info.h"
41 #include "monster/monster-pain-describer.h"
42 #include "monster/monster-status-setter.h"
43 #include "monster/monster-status.h"
44 #include "monster/monster-update.h"
45 #include "object/object-broken.h"
46 #include "object/object-info.h"
47 #include "object/object-mark-types.h"
48 #include "player-base/player-class.h"
49 #include "player-info/class-info.h"
50 #include "player-info/sniper-data-type.h"
51 #include "player-status/player-energy.h"
52 #include "player/player-personality-types.h"
53 #include "player/player-skill.h"
54 #include "player/player-status-table.h"
55 #include "sv-definition/sv-bow-types.h"
56 #include "system/artifact-type-definition.h"
57 #include "system/baseitem-info.h"
58 #include "system/floor-type-definition.h"
59 #include "system/grid-type-definition.h"
60 #include "system/item-entity.h"
61 #include "system/monster-entity.h"
62 #include "system/monster-race-info.h"
63 #include "system/player-type-definition.h"
64 #include "system/redrawing-flags-updater.h"
65 #include "target/projection-path-calculator.h"
66 #include "target/target-checker.h"
67 #include "target/target-getter.h"
68 #include "timed-effect/player-hallucination.h"
69 #include "timed-effect/timed-effects.h"
70 #include "util/bit-flags-calculator.h"
71 #include "view/display-messages.h"
72 #include "wizard/wizard-messages.h"
73 #include "world/world-object.h"
74
75 /*!
76  * @brief 矢弾の属性を定義する
77  * @param bow_ptr 弓のオブジェクト構造体参照ポインタ
78  * @param arrow_ptr 矢弾のオブジェクト構造体参照ポインタ
79  * @return スナイパーの射撃属性、弓矢の属性を考慮する。デフォルトはGF_PLAYER_SHOOT。
80  */
81 AttributeFlags shot_attribute(PlayerType *player_ptr, ItemEntity *bow_ptr, ItemEntity *arrow_ptr, SPELL_IDX snipe_type)
82 {
83     AttributeFlags attribute_flags{};
84     attribute_flags.set(AttributeType::PLAYER_SHOOT);
85
86     const auto arrow_flags = arrow_ptr->get_flags();
87     const auto bow_flags = bow_ptr->get_flags();
88     const auto flags = bow_flags | arrow_flags;
89
90     static const struct snipe_convert_table_t {
91         SPELL_IDX snipe_type;
92         AttributeType attribute;
93     } snipe_convert_table[] = {
94         { SP_LITE, AttributeType::LITE },
95         { SP_FIRE, AttributeType::FIRE },
96         { SP_COLD, AttributeType::COLD },
97         { SP_ELEC, AttributeType::ELEC },
98         { SP_KILL_WALL, AttributeType::KILL_WALL },
99         { SP_EVILNESS, AttributeType::HELL_FIRE },
100         { SP_HOLYNESS, AttributeType::HOLY_FIRE },
101         { SP_FINAL, AttributeType::MANA },
102     };
103
104     static const struct brand_convert_table_t {
105         tr_type brand_type;
106         AttributeType attribute;
107     } brand_convert_table[] = {
108         { TR_BRAND_ACID, AttributeType::ACID },
109         { TR_BRAND_FIRE, AttributeType::FIRE },
110         { TR_BRAND_ELEC, AttributeType::ELEC },
111         { TR_BRAND_COLD, AttributeType::COLD },
112         { TR_BRAND_POIS, AttributeType::POIS },
113         { TR_SLAY_GOOD, AttributeType::HELL_FIRE },
114         { TR_KILL_GOOD, AttributeType::HELL_FIRE },
115         { TR_SLAY_EVIL, AttributeType::HOLY_FIRE },
116         { TR_KILL_EVIL, AttributeType::HOLY_FIRE },
117     };
118
119     for (size_t i = 0; i < sizeof(snipe_convert_table) / sizeof(snipe_convert_table[0]); ++i) {
120         const struct snipe_convert_table_t *p = &snipe_convert_table[i];
121
122         if (snipe_type == p->snipe_type) {
123             attribute_flags.set(p->attribute);
124         }
125     }
126
127     for (size_t i = 0; i < sizeof(brand_convert_table) / sizeof(brand_convert_table[0]); ++i) {
128         const struct brand_convert_table_t *p = &brand_convert_table[i];
129
130         if (flags.has(p->brand_type)) {
131             attribute_flags.set(p->attribute);
132         }
133     }
134
135     if ((flags.has(TR_FORCE_WEAPON)) && (player_ptr->csp > (player_ptr->msp / 30))) {
136         attribute_flags.set(AttributeType::MANA);
137     }
138
139     return attribute_flags;
140 }
141
142 /*!
143  * @brief 矢弾を射撃した際のスレイ倍率をかけた結果を返す /
144  * Determines the odds of an object breaking when thrown at a monster
145  * @param bow_ptr 弓のオブジェクト構造体参照ポインタ
146  * @param arrow_ptr 矢弾のオブジェクト構造体参照ポインタ
147  * @param tdam 計算途中のダメージ量
148  * @param monster_ptr 目標モンスターの構造体参照ポインタ
149  * @return スレイ倍率をかけたダメージ量
150  */
151 static MULTIPLY calc_shot_damage_with_slay(
152     PlayerType *player_ptr, ItemEntity *bow_ptr, ItemEntity *arrow_ptr, int tdam, MonsterEntity *monster_ptr, SPELL_IDX snipe_type)
153 {
154     MULTIPLY mult = 10;
155
156     auto &monrace = monster_ptr->get_monrace();
157
158     const auto arrow_flags = arrow_ptr->get_flags();
159     const auto bow_flags = bow_ptr->get_flags();
160     const auto flags = bow_flags | arrow_flags;
161
162     /* Some "weapons" and "ammo" do extra damage */
163     switch (arrow_ptr->bi_key.tval()) {
164     case ItemKindType::SHOT:
165     case ItemKindType::ARROW:
166     case ItemKindType::BOLT: {
167         if ((flags.has(TR_SLAY_ANIMAL)) && monrace.kind_flags.has(MonsterKindType::ANIMAL)) {
168             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
169                 monrace.r_kind_flags.set(MonsterKindType::ANIMAL);
170             }
171             if (mult < 17) {
172                 mult = 17;
173             }
174         }
175
176         if ((flags.has(TR_KILL_ANIMAL)) && monrace.kind_flags.has(MonsterKindType::ANIMAL)) {
177             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
178                 monrace.r_kind_flags.set(MonsterKindType::ANIMAL);
179             }
180             if (mult < 27) {
181                 mult = 27;
182             }
183         }
184
185         if ((flags.has(TR_SLAY_EVIL)) && monrace.kind_flags.has(MonsterKindType::EVIL)) {
186             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
187                 monrace.r_kind_flags.set(MonsterKindType::EVIL);
188             }
189             if (mult < 15) {
190                 mult = 15;
191             }
192         }
193
194         if ((flags.has(TR_KILL_EVIL)) && monrace.kind_flags.has(MonsterKindType::EVIL)) {
195             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
196                 monrace.r_kind_flags.set(MonsterKindType::EVIL);
197             }
198             if (mult < 25) {
199                 mult = 25;
200             }
201         }
202
203         if ((flags.has(TR_SLAY_GOOD)) && monrace.kind_flags.has(MonsterKindType::GOOD)) {
204             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
205                 monrace.r_kind_flags.set(MonsterKindType::GOOD);
206             }
207             if (mult < 15) {
208                 mult = 15;
209             }
210         }
211
212         if ((flags.has(TR_KILL_GOOD)) && monrace.kind_flags.has(MonsterKindType::GOOD)) {
213             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
214                 monrace.r_kind_flags.set(MonsterKindType::GOOD);
215             }
216             if (mult < 25) {
217                 mult = 25;
218             }
219         }
220
221         if ((flags.has(TR_SLAY_HUMAN)) && monrace.kind_flags.has(MonsterKindType::HUMAN)) {
222             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
223                 monrace.r_kind_flags.set(MonsterKindType::HUMAN);
224             }
225             if (mult < 17) {
226                 mult = 17;
227             }
228         }
229
230         if ((flags.has(TR_KILL_HUMAN)) && monrace.kind_flags.has(MonsterKindType::HUMAN)) {
231             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
232                 monrace.r_kind_flags.set(MonsterKindType::HUMAN);
233             }
234             if (mult < 27) {
235                 mult = 27;
236             }
237         }
238
239         if ((flags.has(TR_SLAY_UNDEAD)) && monrace.kind_flags.has(MonsterKindType::UNDEAD)) {
240             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
241                 monrace.r_kind_flags.set(MonsterKindType::UNDEAD);
242             }
243             if (mult < 20) {
244                 mult = 20;
245             }
246         }
247
248         if ((flags.has(TR_KILL_UNDEAD)) && monrace.kind_flags.has(MonsterKindType::UNDEAD)) {
249             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
250                 monrace.r_kind_flags.set(MonsterKindType::UNDEAD);
251             }
252             if (mult < 30) {
253                 mult = 30;
254             }
255         }
256
257         if ((flags.has(TR_SLAY_DEMON)) && monrace.kind_flags.has(MonsterKindType::DEMON)) {
258             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
259                 monrace.r_kind_flags.set(MonsterKindType::DEMON);
260             }
261             if (mult < 20) {
262                 mult = 20;
263             }
264         }
265
266         if ((flags.has(TR_KILL_DEMON)) && monrace.kind_flags.has(MonsterKindType::DEMON)) {
267             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
268                 monrace.r_kind_flags.set(MonsterKindType::DEMON);
269             }
270             if (mult < 30) {
271                 mult = 30;
272             }
273         }
274
275         if ((flags.has(TR_SLAY_ORC)) && monrace.kind_flags.has(MonsterKindType::ORC)) {
276             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
277                 monrace.r_kind_flags.set(MonsterKindType::ORC);
278             }
279             if (mult < 20) {
280                 mult = 20;
281             }
282         }
283
284         if ((flags.has(TR_KILL_ORC)) && monrace.kind_flags.has(MonsterKindType::ORC)) {
285             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
286                 monrace.r_kind_flags.set(MonsterKindType::ORC);
287             }
288             if (mult < 30) {
289                 mult = 30;
290             }
291         }
292
293         if ((flags.has(TR_SLAY_TROLL)) && monrace.kind_flags.has(MonsterKindType::TROLL)) {
294             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
295                 monrace.r_kind_flags.set(MonsterKindType::TROLL);
296             }
297
298             if (mult < 20) {
299                 mult = 20;
300             }
301         }
302
303         if ((flags.has(TR_KILL_TROLL)) && monrace.kind_flags.has(MonsterKindType::TROLL)) {
304             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
305                 monrace.r_kind_flags.set(MonsterKindType::TROLL);
306             }
307             if (mult < 30) {
308                 mult = 30;
309             }
310         }
311
312         if ((flags.has(TR_SLAY_GIANT)) && monrace.kind_flags.has(MonsterKindType::GIANT)) {
313             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
314                 monrace.r_kind_flags.set(MonsterKindType::GIANT);
315             }
316             if (mult < 20) {
317                 mult = 20;
318             }
319         }
320
321         if ((flags.has(TR_KILL_GIANT)) && monrace.kind_flags.has(MonsterKindType::GIANT)) {
322             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
323                 monrace.r_kind_flags.set(MonsterKindType::GIANT);
324             }
325             if (mult < 30) {
326                 mult = 30;
327             }
328         }
329
330         if ((flags.has(TR_SLAY_DRAGON)) && monrace.kind_flags.has(MonsterKindType::DRAGON)) {
331             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
332                 monrace.r_kind_flags.set(MonsterKindType::DRAGON);
333             }
334             if (mult < 20) {
335                 mult = 20;
336             }
337         }
338
339         if ((flags.has(TR_KILL_DRAGON)) && monrace.kind_flags.has(MonsterKindType::DRAGON)) {
340             if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
341                 monrace.r_kind_flags.set(MonsterKindType::DRAGON);
342             }
343             if (mult < 30) {
344                 mult = 30;
345             }
346
347             auto can_eliminate_smaug = arrow_ptr->is_specific_artifact(FixedArtifactId::BARD_ARROW);
348             can_eliminate_smaug &= player_ptr->inventory_list[INVEN_BOW].is_specific_artifact(FixedArtifactId::BARD);
349             can_eliminate_smaug &= monster_ptr->r_idx == MonsterRaceId::SMAUG;
350             if (can_eliminate_smaug) {
351                 mult *= 5;
352             }
353         }
354
355         if (flags.has(TR_BRAND_ACID)) {
356             /* Notice immunity */
357             if (monrace.resistance_flags.has_any_of(RFR_EFF_IM_ACID_MASK)) {
358                 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
359                     monrace.r_resistance_flags.set(monrace.resistance_flags & RFR_EFF_IM_ACID_MASK);
360                 }
361             } else {
362                 if (mult < 17) {
363                     mult = 17;
364                 }
365             }
366         }
367
368         if (flags.has(TR_BRAND_ELEC)) {
369             /* Notice immunity */
370             if (monrace.resistance_flags.has_any_of(RFR_EFF_IM_ELEC_MASK)) {
371                 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
372                     monrace.r_resistance_flags.set(monrace.resistance_flags & RFR_EFF_IM_ELEC_MASK);
373                 }
374             } else {
375                 if (mult < 17) {
376                     mult = 17;
377                 }
378             }
379         }
380
381         if (flags.has(TR_BRAND_FIRE)) {
382             /* Notice immunity */
383             if (monrace.resistance_flags.has_any_of(RFR_EFF_IM_FIRE_MASK)) {
384                 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
385                     monrace.r_resistance_flags.set(monrace.resistance_flags & RFR_EFF_IM_FIRE_MASK);
386                 }
387             }
388             /* Otherwise, take the damage */
389             else {
390                 if (monrace.resistance_flags.has(MonsterResistanceType::HURT_FIRE)) {
391                     if (mult < 25) {
392                         mult = 25;
393                     }
394                     if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
395                         monrace.r_resistance_flags.set(MonsterResistanceType::HURT_FIRE);
396                     }
397                 } else if (mult < 17) {
398                     mult = 17;
399                 }
400             }
401         }
402
403         if (flags.has(TR_BRAND_COLD)) {
404             /* Notice immunity */
405             if (monrace.resistance_flags.has_any_of(RFR_EFF_IM_COLD_MASK)) {
406                 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
407                     monrace.r_resistance_flags.set(monrace.resistance_flags & RFR_EFF_IM_COLD_MASK);
408                 }
409             }
410             /* Otherwise, take the damage */
411             else {
412                 if (monrace.resistance_flags.has(MonsterResistanceType::HURT_COLD)) {
413                     if (mult < 25) {
414                         mult = 25;
415                     }
416                     if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
417                         monrace.r_resistance_flags.set(MonsterResistanceType::HURT_COLD);
418                     }
419                 } else if (mult < 17) {
420                     mult = 17;
421                 }
422             }
423         }
424
425         if (flags.has(TR_BRAND_POIS)) {
426             /* Notice immunity */
427             if (monrace.resistance_flags.has_any_of(RFR_EFF_IM_POISON_MASK)) {
428                 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
429                     monrace.r_resistance_flags.set(monrace.resistance_flags & RFR_EFF_IM_POISON_MASK);
430                 }
431             }
432             /* Otherwise, take the damage */
433             else {
434                 if (mult < 17) {
435                     mult = 17;
436                 }
437             }
438         }
439
440         if ((flags.has(TR_FORCE_WEAPON)) && (player_ptr->csp > (player_ptr->msp / 30))) {
441             player_ptr->csp -= (1 + (player_ptr->msp / 30));
442             RedrawingFlagsUpdater::get_instance().set_flag(MainWindowRedrawingFlag::MP);
443             mult = mult * 5 / 2;
444         }
445         break;
446     }
447
448     default:
449         break;
450     }
451
452     /* Sniper */
453     if (snipe_type) {
454         mult = calc_snipe_damage_with_slay(player_ptr, mult, monster_ptr, snipe_type);
455     }
456
457     /* Return the total damage */
458     return tdam * mult / 10;
459 }
460
461 /*!
462  * @brief 射撃処理実行
463  * @param i_idx 射撃するオブジェクトの所持ID
464  * @param bow_ptr 射撃武器のオブジェクト参照ポインタ
465  */
466 void exe_fire(PlayerType *player_ptr, INVENTORY_IDX i_idx, ItemEntity *j_ptr, SPELL_IDX snipe_type)
467 {
468     POSITION y, x, ny, nx, ty, tx, prev_y, prev_x;
469     ItemEntity forge;
470     ItemEntity *q_ptr;
471     ItemEntity *o_ptr;
472
473     AttributeFlags attribute_flags{};
474     attribute_flags.set(AttributeType::PLAYER_SHOOT);
475
476     auto hit_body = false;
477     auto stick_to = false;
478
479     /* Access the item (if in the pack) */
480     auto *floor_ptr = player_ptr->current_floor_ptr;
481     if (i_idx >= 0) {
482         o_ptr = &player_ptr->inventory_list[i_idx];
483     } else {
484         o_ptr = &floor_ptr->o_list[0 - i_idx];
485     }
486
487     /* Sniper - Cannot shot a single arrow twice */
488     if ((snipe_type == SP_DOUBLE) && (o_ptr->number < 2)) {
489         snipe_type = SP_NONE;
490     }
491
492     const auto item_name = describe_flavor(player_ptr, o_ptr, OD_OMIT_PREFIX);
493
494     /* Use the proper number of shots */
495     auto thits = player_ptr->num_fire;
496
497     /* Use a base distance */
498     auto tdis = 10;
499
500     /* Base damage from thrown object plus launcher bonus */
501     auto tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
502
503     /* Actually "fire" the object */
504     const auto tval = j_ptr->bi_key.tval();
505     const auto median_skill_exp = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2;
506     const auto bonus = (player_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
507     const auto &weapon_exps = player_ptr->weapon_exp[tval];
508     constexpr auto bow_magnification = 200;
509     constexpr auto xbow_magnification = 400;
510     int chance;
511     if (tval == ItemKindType::NONE) {
512         chance = (player_ptr->skill_thb + ((weapon_exps[0] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ);
513     } else {
514         const auto sval = *j_ptr->bi_key.sval();
515         if (j_ptr->is_cross_bow()) {
516             chance = (player_ptr->skill_thb + (weapon_exps[sval] / xbow_magnification + bonus) * BTH_PLUS_ADJ);
517         } else {
518             chance = (player_ptr->skill_thb + ((weapon_exps[sval] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ);
519         }
520     }
521
522     PlayerEnergy(player_ptr).set_player_turn_energy(j_ptr->get_bow_energy());
523     auto tmul = j_ptr->get_arrow_magnification();
524
525     /* Get extra "power" from "extra might" */
526     if (player_ptr->xtra_might) {
527         tmul++;
528     }
529
530     tmul = tmul * (100 + (int)(adj_str_td[player_ptr->stat_index[A_STR]]) - 128);
531
532     /* Boost the damage */
533     tdam_base *= tmul;
534     tdam_base /= 100;
535
536     auto sniper_data = PlayerClass(player_ptr).get_specific_data<SniperData>();
537     auto sniper_concent = sniper_data ? sniper_data->concent : 0;
538
539     /* Base range */
540     tdis = 13 + tmul / 80;
541     if (j_ptr->is_cross_bow()) {
542         tdis -= (5 - (sniper_concent + 1) / 2);
543     }
544
545     project_length = tdis + 1;
546
547     /* Get a direction (or cancel) */
548     DIRECTION dir;
549     if (!get_aim_dir(player_ptr, &dir)) {
550         PlayerEnergy(player_ptr).reset_player_turn();
551
552         if (snipe_type == SP_AWAY) {
553             snipe_type = SP_NONE;
554         }
555
556         /* need not to reset project_length (already did)*/
557
558         return;
559     }
560
561     if (snipe_type != SP_NONE) {
562         sound(SOUND_ZAP);
563     }
564
565     /* Predict the "target" location */
566     tx = player_ptr->x + 99 * ddx[dir];
567     ty = player_ptr->y + 99 * ddy[dir];
568
569     /* Check for "target request" */
570     if ((dir == 5) && target_okay(player_ptr)) {
571         tx = target_col;
572         ty = target_row;
573     }
574
575     /* Get projection path length */
576     projection_path path_g(player_ptr, project_length, player_ptr->y, player_ptr->x, ty, tx, PROJECT_PATH | PROJECT_THRU);
577     tdis = path_g.path_num() - 1;
578
579     project_length = 0; /* reset to default */
580
581     /* Don't shoot at my feet */
582     if (tx == player_ptr->x && ty == player_ptr->y) {
583         PlayerEnergy(player_ptr).reset_player_turn();
584
585         /* project_length is already reset to 0 */
586
587         return;
588     }
589
590     /* Take a (partial) turn */
591     PlayerEnergy(player_ptr).div_player_turn_energy(thits);
592     player_ptr->is_fired = true;
593
594     /* Sniper - Difficult to shot twice at 1 turn */
595     if (snipe_type == SP_DOUBLE) {
596         sniper_concent = (sniper_concent + 1) / 2;
597     }
598
599     /* Sniper - Repeat shooting when double shots */
600     for (auto i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++) {
601         /* Start at the player */
602         y = player_ptr->y;
603         x = player_ptr->x;
604         q_ptr = &forge;
605         q_ptr->copy_from(o_ptr);
606
607         /* Single object */
608         q_ptr->number = 1;
609
610         vary_item(player_ptr, i_idx, -1);
611
612         sound(SOUND_SHOOT);
613         handle_stuff(player_ptr);
614
615         prev_y = y;
616         prev_x = x;
617
618         /* The shot does not hit yet */
619         hit_body = false;
620
621         /* Travel until stopped */
622         for (auto cur_dis = 0; cur_dis <= tdis;) {
623             Grid *g_ptr;
624
625             /* Hack -- Stop at the target */
626             if ((y == ty) && (x == tx)) {
627                 break;
628             }
629
630             /* Calculate the new location (see "project()") */
631             ny = y;
632             nx = x;
633             mmove2(&ny, &nx, player_ptr->y, player_ptr->x, ty, tx);
634
635             /* Shatter Arrow */
636             if (snipe_type == SP_KILL_WALL) {
637                 g_ptr = &floor_ptr->grid_array[ny][nx];
638
639                 if (g_ptr->cave_has_flag(TerrainCharacteristics::HURT_ROCK) && !g_ptr->m_idx) {
640                     if (any_bits(g_ptr->info, (CAVE_MARK))) {
641                         msg_print(_("岩が砕け散った。", "Wall rocks were shattered."));
642                     }
643                     /* Forget the wall */
644                     reset_bits(g_ptr->info, (CAVE_MARK));
645                     static constexpr auto flags = {
646                         StatusRecalculatingFlag::VIEW,
647                         StatusRecalculatingFlag::LITE,
648                         StatusRecalculatingFlag::FLOW,
649                         StatusRecalculatingFlag::MONSTER_LITE,
650                     };
651                     RedrawingFlagsUpdater::get_instance().set_flags(flags);
652
653                     /* Destroy the wall */
654                     cave_alter_feat(player_ptr, ny, nx, TerrainCharacteristics::HURT_ROCK);
655
656                     hit_body = true;
657                     break;
658                 }
659             }
660
661             /* Stopped by walls/doors */
662             if (!cave_has_flag_bold(floor_ptr, ny, nx, TerrainCharacteristics::PROJECT) && !floor_ptr->grid_array[ny][nx].m_idx) {
663                 break;
664             }
665
666             /* Advance the distance */
667             cur_dis++;
668
669             /* Sniper */
670             if (snipe_type == SP_LITE) {
671                 set_bits(floor_ptr->grid_array[ny][nx].info, CAVE_GLOW);
672                 note_spot(player_ptr, ny, nx);
673                 lite_spot(player_ptr, ny, nx);
674             }
675
676             /* The player can see the (on screen) missile */
677             if (panel_contains(ny, nx) && player_can_see_bold(player_ptr, ny, nx)) {
678                 const auto a = q_ptr->get_color();
679                 const auto c = q_ptr->get_symbol();
680
681                 /* Draw, Hilite, Fresh, Pause, Erase */
682                 if (delay_factor > 0) {
683                     print_rel(player_ptr, c, a, ny, nx);
684                     move_cursor_relative(ny, nx);
685                     term_fresh();
686                     term_xtra(TERM_XTRA_DELAY, delay_factor);
687                     lite_spot(player_ptr, ny, nx);
688                     term_fresh();
689                 }
690             }
691
692             /* The player cannot see the missile */
693             else {
694                 /* Pause anyway, for consistancy **/
695                 if (delay_factor > 0) {
696                     term_xtra(TERM_XTRA_DELAY, delay_factor);
697                 }
698             }
699
700             /* Sniper */
701             if (snipe_type == SP_KILL_TRAP) {
702                 constexpr auto flags = PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM;
703                 project(player_ptr, 0, 0, ny, nx, 0, AttributeType::KILL_TRAP, flags);
704             }
705
706             /* Sniper */
707             if (snipe_type == SP_EVILNESS) {
708                 reset_bits(floor_ptr->grid_array[ny][nx].info, (CAVE_GLOW | CAVE_MARK));
709                 note_spot(player_ptr, ny, nx);
710                 lite_spot(player_ptr, ny, nx);
711             }
712
713             prev_y = y;
714             prev_x = x;
715
716             /* Save the new location */
717             x = nx;
718             y = ny;
719
720             /* Monster here, Try to hit it */
721             if (floor_ptr->grid_array[y][x].m_idx) {
722                 sound(SOUND_SHOOT_HIT);
723                 Grid *c_mon_ptr = &floor_ptr->grid_array[y][x];
724
725                 auto *m_ptr = &floor_ptr->m_list[c_mon_ptr->m_idx];
726                 auto *r_ptr = &m_ptr->get_monrace();
727
728                 /* Check the visibility */
729                 auto visible = m_ptr->ml;
730
731                 /* Note the collision */
732                 hit_body = true;
733
734                 if (m_ptr->is_asleep()) {
735                     if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5)) {
736                         chg_virtue(player_ptr, Virtue::COMPASSION, -1);
737                     }
738                     if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5)) {
739                         chg_virtue(player_ptr, Virtue::HONOUR, -1);
740                     }
741                 }
742
743                 if ((r_ptr->level + 10) > player_ptr->lev) {
744                     PlayerSkill(player_ptr).gain_range_weapon_exp(j_ptr);
745                 }
746
747                 if (player_ptr->riding) {
748                     PlayerSkill(player_ptr).gain_riding_skill_exp_on_range_attack();
749                 }
750
751                 /* Did we hit it (penalize range) */
752                 if (test_hit_fire(player_ptr, chance - cur_dis, m_ptr, m_ptr->ml, item_name.data())) {
753                     bool fear = false;
754                     auto tdam = tdam_base; //!< @note 実際に与えるダメージ
755                     auto base_dam = tdam; //!< @note 補正前の与えるダメージ(無傷、全ての耐性など)
756
757                     /* Get extra damage from concentration */
758                     tdam = boost_concentration_damage(player_ptr, tdam);
759
760                     /* Handle unseen monster */
761                     if (!visible) {
762                         /* Invisible monster */
763                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), item_name.data());
764                     }
765
766                     /* Handle visible monster */
767                     else {
768                         /* Get "the monster" or "it" */
769                         const auto m_name = monster_desc(player_ptr, m_ptr, 0);
770
771                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), item_name.data(), m_name.data());
772
773                         if (m_ptr->ml) {
774                             if (!player_ptr->effects()->hallucination()->is_hallucinated()) {
775                                 monster_race_track(player_ptr, m_ptr->ap_r_idx);
776                             }
777
778                             health_track(player_ptr, c_mon_ptr->m_idx);
779                         }
780                     }
781
782                     if (snipe_type == SP_NEEDLE) {
783                         const auto is_unique = r_ptr->kind_flags.has(MonsterKindType::UNIQUE);
784                         const auto fatality = randint1(r_ptr->level / (3 + sniper_concent)) + (8 - sniper_concent);
785                         if ((randint1(fatality) == 1) && !is_unique && none_bits(r_ptr->flags7, RF7_UNIQUE2)) {
786                             /* Get "the monster" or "it" */
787                             const auto m_name = monster_desc(player_ptr, m_ptr, 0);
788
789                             tdam = m_ptr->hp + 1;
790                             base_dam = tdam;
791                             msg_format(_("%sの急所に突き刺さった!", "Your shot hit a fatal spot of %s!"), m_name.data());
792                         } else {
793                             tdam = 1;
794                             base_dam = tdam;
795                         }
796                     } else {
797
798                         attribute_flags = shot_attribute(player_ptr, j_ptr, q_ptr, snipe_type);
799                         /* Apply special damage */
800                         tdam = calc_shot_damage_with_slay(player_ptr, j_ptr, q_ptr, tdam, m_ptr, snipe_type);
801                         tdam = critical_shot(player_ptr, q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
802
803                         /* No negative damage */
804                         if (tdam < 0) {
805                             tdam = 0;
806                         }
807
808                         /* Modify the damage */
809                         base_dam = tdam;
810                         tdam = mon_damage_mod(player_ptr, m_ptr, tdam, false);
811                     }
812
813                     msg_format_wizard(player_ptr, CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"), tdam,
814                         m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
815
816                     /* Sniper */
817                     if (snipe_type == SP_EXPLODE) {
818                         uint16_t flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
819
820                         sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
821                         project(player_ptr, 0, ((sniper_concent + 1) / 2 + 1), ny, nx, base_dam, AttributeType::MISSILE, flg);
822                         break;
823                     }
824
825                     /* Sniper */
826                     if (snipe_type == SP_HOLYNESS) {
827                         set_bits(floor_ptr->grid_array[ny][nx].info, CAVE_GLOW);
828                         note_spot(player_ptr, ny, nx);
829                         lite_spot(player_ptr, ny, nx);
830                     }
831
832                     /* Hit the monster, check for death */
833                     MonsterDamageProcessor mdp(player_ptr, c_mon_ptr->m_idx, tdam, &fear, attribute_flags);
834                     if (mdp.mon_take_hit(m_ptr->get_died_message())) {
835                         /* Dead monster */
836                     }
837
838                     /* No death */
839                     else {
840                         /* STICK TO */
841                         if (q_ptr->is_fixed_artifact() && (sniper_concent == 0)) {
842                             const auto m_name = monster_desc(player_ptr, m_ptr, 0);
843
844                             stick_to = true;
845                             msg_format(_("%sは%sに突き刺さった!", "%s^ is stuck in %s!"), item_name.data(), m_name.data());
846                         }
847
848                         if (const auto pain_message = MonsterPainDescriber(player_ptr, c_mon_ptr->m_idx).describe(tdam);
849                             !pain_message.empty()) {
850                             msg_print(pain_message);
851                         }
852
853                         /* Anger the monster */
854                         if (tdam > 0) {
855                             anger_monster(player_ptr, m_ptr);
856                         }
857
858                         if (fear && m_ptr->ml) {
859                             const auto m_name = monster_desc(player_ptr, m_ptr, 0);
860                             sound(SOUND_FLEE);
861                             msg_format(_("%s^は恐怖して逃げ出した!", "%s^ flees in terror!"), m_name.data());
862                         }
863
864                         set_target(m_ptr, player_ptr->y, player_ptr->x);
865
866                         /* Sniper */
867                         if (snipe_type == SP_RUSH) {
868                             int n = randint1(5) + 3;
869                             MONSTER_IDX m_idx = c_mon_ptr->m_idx;
870
871                             for (; cur_dis <= tdis;) {
872                                 POSITION ox = nx;
873                                 POSITION oy = ny;
874
875                                 if (!n) {
876                                     break;
877                                 }
878
879                                 /* Calculate the new location (see "project()") */
880                                 mmove2(&ny, &nx, player_ptr->y, player_ptr->x, ty, tx);
881
882                                 /* Stopped by wilderness boundary */
883                                 if (!in_bounds2(floor_ptr, ny, nx)) {
884                                     break;
885                                 }
886
887                                 /* Stopped by walls/doors */
888                                 if (!player_can_enter(player_ptr, floor_ptr->grid_array[ny][nx].feat, 0)) {
889                                     break;
890                                 }
891
892                                 /* Stopped by monsters */
893                                 if (!is_cave_empty_bold(player_ptr, ny, nx)) {
894                                     break;
895                                 }
896
897                                 floor_ptr->grid_array[ny][nx].m_idx = m_idx;
898                                 floor_ptr->grid_array[oy][ox].m_idx = 0;
899
900                                 m_ptr->fx = nx;
901                                 m_ptr->fy = ny;
902
903                                 update_monster(player_ptr, m_idx, true);
904
905                                 if (delay_factor > 0) {
906                                     lite_spot(player_ptr, ny, nx);
907                                     lite_spot(player_ptr, oy, ox);
908                                     term_fresh();
909                                     term_xtra(TERM_XTRA_DELAY, delay_factor);
910                                 }
911
912                                 x = nx;
913                                 y = ny;
914                                 cur_dis++;
915                                 n--;
916                             }
917                         }
918                     }
919                 }
920
921                 /* Sniper */
922                 if (snipe_type == SP_PIERCE && sniper_concent > 0) {
923                     sniper_concent--;
924                     continue;
925                 }
926
927                 /* Stop looking */
928                 break;
929             }
930         }
931
932         /* Chance of breakage (during attacks) */
933         auto j = (hit_body ? breakage_chance(player_ptr, q_ptr, PlayerClass(player_ptr).equals(PlayerClassType::ARCHER), snipe_type) : 0);
934
935         if (stick_to) {
936             MONSTER_IDX m_idx = floor_ptr->grid_array[y][x].m_idx;
937             auto *m_ptr = &floor_ptr->m_list[m_idx];
938             OBJECT_IDX o_idx = o_pop(floor_ptr);
939
940             if (!o_idx) {
941                 msg_format(_("%sはどこかへ行った。", "The %s went somewhere."), item_name.data());
942                 if (q_ptr->is_fixed_artifact()) {
943                     ArtifactsInfo::get_instance().get_artifact(j_ptr->fixed_artifact_idx).is_generated = false;
944                 }
945                 return;
946             }
947
948             o_ptr = &floor_ptr->o_list[o_idx];
949             o_ptr->copy_from(q_ptr);
950
951             /* Forget mark */
952             o_ptr->marked.reset(OmType::TOUCHED);
953
954             /* Forget location */
955             o_ptr->iy = o_ptr->ix = 0;
956
957             /* Memorize monster */
958             o_ptr->held_m_idx = m_idx;
959
960             /* Carry object */
961             m_ptr->hold_o_idx_list.add(floor_ptr, o_idx);
962         } else if (cave_has_flag_bold(floor_ptr, y, x, TerrainCharacteristics::PROJECT)) {
963             /* Drop (or break) near that location */
964             (void)drop_near(player_ptr, q_ptr, j, y, x);
965         } else {
966             /* Drop (or break) near that location */
967             (void)drop_near(player_ptr, q_ptr, j, prev_y, prev_x);
968         }
969
970         /* Sniper - Repeat shooting when double shots */
971     }
972
973     /* Sniper - Loose his/her concentration after any shot */
974     reset_concentration(player_ptr, false);
975 }
976
977 /*!
978  * @brief プレイヤーからモンスターへの射撃命中判定
979  * @param chance 基本命中値
980  * @param monster_ptr モンスターの構造体参照ポインタ
981  * @param vis 目標を視界に捕らえているならばTRUEを指定
982  * @param item_name 石川五右衛門専用メッセージ:無効化した矢弾の名前
983  * @return 命中と判定された場合TRUEを返す
984  * @note 最低命中率5%、最大命中率95%
985  */
986 bool test_hit_fire(PlayerType *player_ptr, int chance, MonsterEntity *m_ptr, int vis, std::string_view item_name)
987 {
988     int k;
989     ARMOUR_CLASS ac;
990     auto *r_ptr = &m_ptr->get_monrace();
991
992     /* Percentile dice */
993     k = randint1(100);
994
995     auto sniper_data = PlayerClass(player_ptr).get_specific_data<SniperData>();
996     auto sniper_concent = sniper_data ? sniper_data->concent : 0;
997
998     /* Snipers with high-concentration reduce instant miss percentage.*/
999     k += sniper_concent;
1000
1001     /* Hack -- Instant miss or hit */
1002     if (k <= 5) {
1003         return false;
1004     }
1005     if (k > 95) {
1006         return true;
1007     }
1008
1009     if (player_ptr->ppersonality == PERSONALITY_LAZY) {
1010         if (one_in_(20)) {
1011             return false;
1012         }
1013     }
1014
1015     /* Never hit */
1016     if (chance <= 0) {
1017         return false;
1018     }
1019
1020     ac = r_ptr->ac;
1021     ac = ac * (8 - sniper_concent) / 8;
1022
1023     if (m_ptr->r_idx == MonsterRaceId::GOEMON && !m_ptr->is_asleep()) {
1024         ac *= 3;
1025     }
1026
1027     /* Invisible monsters are harder to hit */
1028     if (!vis) {
1029         chance = (chance + 1) / 2;
1030     }
1031
1032     /* Power competes against armor */
1033     if (randint0(chance) < (ac * 3 / 4)) {
1034         if (m_ptr->r_idx == MonsterRaceId::GOEMON && !m_ptr->is_asleep()) {
1035             const auto m_name = monster_desc(player_ptr, m_ptr, 0);
1036             msg_format(_("%sは%sを斬り捨てた!", "%s cuts down %s!"), m_name.data(), item_name.data());
1037         }
1038         return false;
1039     }
1040
1041     /* Assume hit */
1042     return true;
1043 }
1044
1045 /*!
1046  * @brief プレイヤーからモンスターへの射撃クリティカル判定
1047  * @param weight 矢弾の重量
1048  * @param plus_ammo 矢弾の命中修正
1049  * @param plus_bow 弓の命中修正
1050  * @param dam 現在算出中のダメージ値
1051  * @return クリティカル修正が入ったダメージ値
1052  */
1053 int critical_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam)
1054 {
1055     const auto &item = player_ptr->inventory_list[INVEN_BOW];
1056     const auto bonus = player_ptr->to_h_b + plus_ammo;
1057     const auto tval = item.bi_key.tval();
1058     const auto median_skill_exp = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2;
1059     const auto &weapon_exps = player_ptr->weapon_exp[tval];
1060     constexpr auto bow_magnification = 200;
1061     constexpr auto xbow_magnification = 400;
1062     int power;
1063     if (tval == ItemKindType::NONE) {
1064         power = player_ptr->skill_thb + ((weapon_exps[0] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ;
1065     } else {
1066         const auto sval = *item.bi_key.sval();
1067         const auto weapon_exp = weapon_exps[sval];
1068         if (player_ptr->tval_ammo == ItemKindType::BOLT) {
1069             power = (player_ptr->skill_thb + (weapon_exp / xbow_magnification + bonus) * BTH_PLUS_ADJ);
1070         } else {
1071             power = player_ptr->skill_thb + ((weapon_exp - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ;
1072         }
1073     }
1074
1075     PlayerClass pc(player_ptr);
1076     const auto sniper_data = pc.get_specific_data<SniperData>();
1077     const auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1078
1079     /* Snipers can shot more critically with crossbows */
1080     power += ((power * sniper_concent) / 5);
1081     if (pc.equals(PlayerClassType::SNIPER) && (player_ptr->tval_ammo == ItemKindType::BOLT)) {
1082         power *= 2;
1083     }
1084
1085     /* Good bow makes more critical */
1086     power += plus_bow * 8 * (sniper_concent + 5);
1087     if (randint1(10000) > power) {
1088         return dam;
1089     }
1090
1091     const auto k = weight * randint1(500);
1092     if (k < 900) {
1093         msg_print(_("手ごたえがあった!", "It was a good hit!"));
1094         dam += (dam / 2);
1095     } else if (k < 1350) {
1096         msg_print(_("かなりの手ごたえがあった!", "It was a great hit!"));
1097         dam *= 2;
1098     } else {
1099         msg_print(_("会心の一撃だ!", "It was a superb hit!"));
1100         dam *= 3;
1101     }
1102
1103     return dam;
1104 }
1105
1106 /*!
1107  * @brief 射撃時クリティカルによるダメージ期待値修正計算(スナイパーの集中処理と武器経験値) / critical happens at i / 10000
1108  * @param player_ptr プレイヤーへの参照ポインタ
1109  * @param plus_ammo 矢弾のダメージ修正
1110  * @param plus_bow 弓のダメージ修正
1111  * @return ダメージ期待値
1112  * @note 基本ダメージ量と重量はこの部位では計算に加わらない。
1113  */
1114 int calc_crit_ratio_shot(PlayerType *player_ptr, int plus_ammo, int plus_bow)
1115 {
1116     auto *j_ptr = &player_ptr->inventory_list[INVEN_BOW];
1117
1118     /* Extract "shot" power */
1119     auto i = player_ptr->to_h_b + plus_ammo;
1120     const auto tval = j_ptr->bi_key.tval();
1121     const auto sval = *j_ptr->bi_key.sval();
1122     if (player_ptr->tval_ammo == ItemKindType::BOLT) {
1123         i = (player_ptr->skill_thb + (player_ptr->weapon_exp[tval][sval] / 400 + i) * BTH_PLUS_ADJ);
1124     } else {
1125         i = (player_ptr->skill_thb + ((player_ptr->weapon_exp[tval][sval] - (PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2)) / 200 + i) * BTH_PLUS_ADJ);
1126     }
1127
1128     PlayerClass pc(player_ptr);
1129     auto sniper_data = pc.get_specific_data<SniperData>();
1130     auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1131
1132     /* Snipers can shot more critically with crossbows */
1133     i += ((i * sniper_concent) / 5);
1134     if (pc.equals(PlayerClassType::SNIPER) && (player_ptr->tval_ammo == ItemKindType::BOLT)) {
1135         i *= 2;
1136     }
1137
1138     /* Good bow makes more critical */
1139     i += plus_bow * 8 * (sniper_concent + 5);
1140
1141     if (i < 0) {
1142         i = 0;
1143     }
1144
1145     return i;
1146 }
1147
1148 /*!
1149  * @brief 射撃時クリティカルによるダメージ期待値修正計算(重量依存部分) / critical happens at i / 10000
1150  * @param weight 武器の重量
1151  * @param plus_ammo 矢弾のダメージ修正
1152  * @param plus_bow 弓のダメージ修正
1153  * @param dam 基本ダメージ量
1154  * @return ダメージ期待値
1155  */
1156 int calc_expect_crit_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam)
1157 {
1158     uint32_t num;
1159     int i, k, crit;
1160     i = calc_crit_ratio_shot(player_ptr, plus_ammo, plus_bow);
1161
1162     k = 0;
1163     num = 0;
1164
1165     crit = std::min(500, 900 / weight);
1166     num += dam * 3 / 2 * crit;
1167     k = crit;
1168
1169     crit = std::min(500, 1350 / weight);
1170     crit -= k;
1171     num += dam * 2 * crit;
1172     k += crit;
1173
1174     if (k < 500) {
1175         crit = 500 - k;
1176         num += dam * 3 * crit;
1177     }
1178
1179     num /= 500;
1180
1181     num *= i;
1182     num += (10000 - i) * dam;
1183     num /= 10000;
1184
1185     return num;
1186 }
1187
1188 /*!
1189  * @brief 攻撃時クリティカルによるダメージ期待値修正計算(重量と毒針処理) / critical happens at i / 10000
1190  * @param player_ptr プレイヤーへの参照ポインタ
1191  * @param weight 武器の重量
1192  * @param plus 武器のダメージ修正
1193  * @param dam 基本ダメージ
1194  * @param meichuu 命中値
1195  * @param dokubari 毒針処理か否か
1196  * @param impact 強撃かどうか
1197  * @return ダメージ期待値
1198  */
1199 int calc_expect_crit(PlayerType *player_ptr, WEIGHT weight, int plus, int dam, int16_t meichuu, bool dokubari, bool impact)
1200 {
1201     if (dokubari) {
1202         return dam;
1203     }
1204
1205     int i = (weight + (meichuu * 3 + plus * 5) + player_ptr->skill_thn);
1206     if (i < 0) {
1207         i = 0;
1208     }
1209
1210     // 通常ダメージdam、武器重量weightでクリティカルが発生した時のクリティカルダメージ期待値
1211     auto calc_weight_expect_dam = [](int dam, WEIGHT weight) {
1212         int sum = 0;
1213         for (int d = 1; d <= 650; ++d) {
1214             int k = weight + d;
1215             sum += std::get<0>(apply_critical_norm_damage(k, dam));
1216         }
1217         return sum / 650;
1218     };
1219
1220     uint32_t num = 0;
1221
1222     if (impact) {
1223         for (int d = 1; d <= 650; ++d) {
1224             num += calc_weight_expect_dam(dam, weight + d);
1225         }
1226         num /= 650;
1227     } else {
1228         num += calc_weight_expect_dam(dam, weight);
1229     }
1230
1231     int pow = PlayerClass(player_ptr).equals(PlayerClassType::NINJA) ? 4444 : 5000;
1232     if (impact) {
1233         pow /= 2;
1234     }
1235
1236     num *= i;
1237     num += (pow - i) * dam;
1238     num /= pow;
1239
1240     return num;
1241 }