OSDN Git Service

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