OSDN Git Service

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