OSDN Git Service

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