OSDN Git Service

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