OSDN Git Service

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