OSDN Git Service

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