OSDN Git Service

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