OSDN Git Service

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