OSDN Git Service

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