OSDN Git Service

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