OSDN Git Service

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