OSDN Git Service

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