OSDN Git Service

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