1 #include "combat/shoot.h"
2 #include "artifact/fixed-art-types.h"
3 #include "avatar/avatar.h"
4 #include "combat/attack-criticality.h"
5 #include "core/player-redraw-types.h"
6 #include "core/player-update-types.h"
7 #include "core/stuff-handler.h"
8 #include "effect/effect-characteristics.h"
9 #include "effect/effect-processor.h"
10 #include "effect/spells-effect-util.h"
11 #include "flavor/flavor-describer.h"
12 #include "flavor/object-flavor-types.h"
13 #include "floor/cave.h"
14 #include "floor/floor-object.h"
15 #include "floor/geometry.h"
16 #include "game-option/cheat-types.h"
17 #include "game-option/special-options.h"
18 #include "grid/feature-flag-types.h"
19 #include "grid/feature.h"
20 #include "grid/grid.h"
21 #include "inventory/inventory-object.h"
22 #include "inventory/inventory-slot-types.h"
23 #include "io/cursor.h"
24 #include "io/screen-util.h"
25 #include "main/sound-definitions-table.h"
26 #include "main/sound-of-music.h"
27 #include "mind/mind-sniper.h"
28 #include "mind/snipe-types.h"
29 #include "monster-floor/monster-death.h"
30 #include "monster-floor/monster-move.h"
31 #include "monster-race/monster-race.h"
32 #include "monster-race/race-flags-resistance.h"
33 #include "monster-race/race-flags1.h"
34 #include "monster-race/race-flags2.h"
35 #include "monster-race/race-flags3.h"
36 #include "monster-race/race-flags7.h"
37 #include "monster-race/race-indice-types.h"
38 #include "monster/monster-damage.h"
39 #include "monster/monster-describer.h"
40 #include "monster/monster-info.h"
41 #include "monster/monster-status-setter.h"
42 #include "monster/monster-status.h"
43 #include "monster/monster-update.h"
44 #include "object/object-broken.h"
45 #include "object/object-flags.h"
46 #include "object/object-info.h"
47 #include "object/object-kind.h"
48 #include "object/object-mark-types.h"
49 #include "player-info/class-info.h"
50 #include "player-status/player-energy.h"
51 #include "player/player-personality-types.h"
52 #include "player/player-skill.h"
53 #include "player/player-status-table.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 "system/grid-type-definition.h"
59 #include "system/monster-race-definition.h"
60 #include "system/monster-type-definition.h"
61 #include "system/player-type-definition.h"
62 #include "target/projection-path-calculator.h"
63 #include "target/target-checker.h"
64 #include "target/target-getter.h"
65 #include "util/bit-flags-calculator.h"
66 #include "view/display-messages.h"
67 #include "wizard/wizard-messages.h"
68 #include "world/world-object.h"
71 * @brief 矢弾を射撃した際のスレイ倍率をかけた結果を返す /
72 * Determines the odds of an object breaking when thrown at a monster
73 * @param bow_ptr 弓のオブジェクト構造体参照ポインタ
74 * @param arrow_ptr 矢弾のオブジェクト構造体参照ポインタ
75 * @param tdam 計算途中のダメージ量
76 * @param monster_ptr 目標モンスターの構造体参照ポインタ
77 * @return スレイ倍率をかけたダメージ量
79 static MULTIPLY calc_shot_damage_with_slay(
80 player_type *player_ptr, object_type *bow_ptr, object_type *arrow_ptr, HIT_POINT tdam, monster_type *monster_ptr, SPELL_IDX snipe_type)
84 monster_race *race_ptr = &r_info[monster_ptr->r_idx];
87 auto arrow_flags = object_flags(arrow_ptr);
88 auto bow_flags = object_flags(bow_ptr);
90 flags = bow_flags | arrow_flags;
92 /* Some "weapons" and "ammo" do extra damage */
93 switch (arrow_ptr->tval) {
97 if ((flags.has(TR_SLAY_ANIMAL)) && any_bits(race_ptr->flags3, RF3_ANIMAL)) {
98 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
99 set_bits(race_ptr->r_flags3, RF3_ANIMAL);
105 if ((flags.has(TR_KILL_ANIMAL)) && any_bits(race_ptr->flags3, RF3_ANIMAL)) {
106 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
107 set_bits(race_ptr->r_flags3, RF3_ANIMAL);
113 if ((flags.has(TR_SLAY_EVIL)) && any_bits(race_ptr->flags3, RF3_EVIL)) {
114 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
115 set_bits(race_ptr->r_flags3, RF3_EVIL);
121 if ((flags.has(TR_KILL_EVIL)) && any_bits(race_ptr->flags3, RF3_EVIL)) {
122 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
123 set_bits(race_ptr->r_flags3, RF3_EVIL);
129 if ((flags.has(TR_SLAY_GOOD)) && any_bits(race_ptr->flags3, RF3_GOOD)) {
130 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
131 set_bits(race_ptr->r_flags3, RF3_GOOD);
137 if ((flags.has(TR_KILL_GOOD)) && any_bits(race_ptr->flags3, RF3_GOOD)) {
138 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
139 set_bits(race_ptr->r_flags3, RF3_GOOD);
145 if ((flags.has(TR_SLAY_HUMAN)) && any_bits(race_ptr->flags2, RF2_HUMAN)) {
146 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
147 set_bits(race_ptr->r_flags2, RF2_HUMAN);
153 if ((flags.has(TR_KILL_HUMAN)) && any_bits(race_ptr->flags2, RF2_HUMAN)) {
154 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
155 set_bits(race_ptr->r_flags2, RF2_HUMAN);
161 if ((flags.has(TR_SLAY_UNDEAD)) && any_bits(race_ptr->flags3, RF3_UNDEAD)) {
162 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
163 set_bits(race_ptr->r_flags3, RF3_UNDEAD);
169 if ((flags.has(TR_KILL_UNDEAD)) && any_bits(race_ptr->flags3, RF3_UNDEAD)) {
170 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
171 set_bits(race_ptr->r_flags3, RF3_UNDEAD);
177 if ((flags.has(TR_SLAY_DEMON)) && any_bits(race_ptr->flags3, RF3_DEMON)) {
178 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
179 set_bits(race_ptr->r_flags3, RF3_DEMON);
185 if ((flags.has(TR_KILL_DEMON)) && any_bits(race_ptr->flags3, RF3_DEMON)) {
186 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
187 set_bits(race_ptr->r_flags3, RF3_DEMON);
193 if ((flags.has(TR_SLAY_ORC)) && any_bits(race_ptr->flags3, RF3_ORC)) {
194 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
195 set_bits(race_ptr->r_flags3, RF3_ORC);
201 if ((flags.has(TR_KILL_ORC)) && any_bits(race_ptr->flags3, RF3_ORC)) {
202 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
203 set_bits(race_ptr->r_flags3, RF3_ORC);
209 if ((flags.has(TR_SLAY_TROLL)) && any_bits(race_ptr->flags3, RF3_TROLL)) {
210 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
211 set_bits(race_ptr->r_flags3, RF3_TROLL);
218 if ((flags.has(TR_KILL_TROLL)) && any_bits(race_ptr->flags3, RF3_TROLL)) {
219 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
220 set_bits(race_ptr->r_flags3, RF3_TROLL);
226 if ((flags.has(TR_SLAY_GIANT)) && any_bits(race_ptr->flags3, RF3_GIANT)) {
227 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
228 set_bits(race_ptr->r_flags3, RF3_GIANT);
234 if ((flags.has(TR_KILL_GIANT)) && any_bits(race_ptr->flags3, RF3_GIANT)) {
235 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
236 set_bits(race_ptr->r_flags3, RF3_GIANT);
242 if ((flags.has(TR_SLAY_DRAGON)) && any_bits(race_ptr->flags3, RF3_DRAGON)) {
243 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
244 set_bits(race_ptr->r_flags3, RF3_DRAGON);
250 if ((flags.has(TR_KILL_DRAGON)) && any_bits(race_ptr->flags3, RF3_DRAGON)) {
251 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
252 set_bits(race_ptr->r_flags3, RF3_DRAGON);
256 if ((arrow_ptr->name1 == ART_BARD_ARROW) && (monster_ptr->r_idx == MON_SMAUG) && (player_ptr->inventory_list[INVEN_BOW].name1 == ART_BARD))
260 if (flags.has(TR_BRAND_ACID)) {
261 /* Notice immunity */
262 if (any_bits(race_ptr->flagsr, RFR_EFF_IM_ACID_MASK)) {
263 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
264 set_bits(race_ptr->r_flagsr, (race_ptr->flagsr & RFR_EFF_IM_ACID_MASK));
272 if (flags.has(TR_BRAND_ELEC)) {
273 /* Notice immunity */
274 if (any_bits(race_ptr->flagsr, RFR_EFF_IM_ELEC_MASK)) {
275 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
276 set_bits(race_ptr->r_flagsr, (race_ptr->flagsr & RFR_EFF_IM_ELEC_MASK));
284 if (flags.has(TR_BRAND_FIRE)) {
285 /* Notice immunity */
286 if (any_bits(race_ptr->flagsr, RFR_EFF_IM_FIRE_MASK)) {
287 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
288 set_bits(race_ptr->r_flagsr, (race_ptr->flagsr & RFR_EFF_IM_FIRE_MASK));
291 /* Otherwise, take the damage */
293 if (any_bits(race_ptr->flags3, RF3_HURT_FIRE)) {
296 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
297 set_bits(race_ptr->r_flags3, RF3_HURT_FIRE);
299 } else if (mult < 17)
304 if (flags.has(TR_BRAND_COLD)) {
305 /* Notice immunity */
306 if (any_bits(race_ptr->flagsr, RFR_EFF_IM_COLD_MASK)) {
307 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
308 set_bits(race_ptr->r_flagsr, (race_ptr->flagsr & RFR_EFF_IM_COLD_MASK));
311 /* Otherwise, take the damage */
313 if (any_bits(race_ptr->flags3, RF3_HURT_COLD)) {
316 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
317 set_bits(race_ptr->r_flags3, RF3_HURT_COLD);
319 } else if (mult < 17)
324 if (flags.has(TR_BRAND_POIS)) {
325 /* Notice immunity */
326 if (any_bits(race_ptr->flagsr, RFR_EFF_IM_POIS_MASK)) {
327 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
328 set_bits(race_ptr->r_flagsr, race_ptr->flagsr & RFR_EFF_IM_POIS_MASK);
331 /* Otherwise, take the damage */
338 if ((flags.has(TR_FORCE_WEAPON)) && (player_ptr->csp > (player_ptr->msp / 30))) {
339 player_ptr->csp -= (1 + (player_ptr->msp / 30));
340 set_bits(player_ptr->redraw, PR_MANA);
352 mult = calc_snipe_damage_with_slay(player_ptr, mult, monster_ptr, snipe_type);
354 /* Return the total damage */
355 return (tdam * mult / 10);
360 * Fire an object from the pack or floor.
361 * @param item 射撃するオブジェクトの所持ID
362 * @param bow_ptr 射撃武器のオブジェクト参照ポインタ
365 * You may only fire items that "match" your missile launcher.
366 * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
367 * See "calc_bonuses()" for more calculations and such.
368 * Note that "firing" a missile is MUCH better than "throwing" it.
369 * Note: "unseen" monsters are very hard to hit.
370 * Objects are more likely to break if they "attempt" to hit a monster.
371 * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
372 * The "extra shot" code works by decreasing the amount of energy
373 * required to make each shot, spreading the shots out over time.
374 * Note that when firing missiles, the launcher multiplier is applied
375 * after all the bonuses are added in, making multipliers very useful.
376 * Note that Bows of "Extra Might" get extra range and an extra bonus
377 * for the damage multiplier.
378 * Note that Bows of "Extra Shots" give an extra shot.
381 void exe_fire(player_type *player_ptr, INVENTORY_IDX item, object_type *j_ptr, SPELL_IDX snipe_type)
385 POSITION y, x, ny, nx, ty, tx, prev_y, prev_x;
386 int tdam_base, tdis, thits, tmul;
388 int cur_dis, visible;
396 bool hit_body = false;
398 GAME_TEXT o_name[MAX_NLEN];
400 uint16_t path_g[512]; /* For calcuration of path length */
402 int msec = delay_factor * delay_factor * delay_factor;
405 bool stick_to = false;
407 /* Access the item (if in the pack) */
409 o_ptr = &player_ptr->inventory_list[item];
411 o_ptr = &player_ptr->current_floor_ptr->o_list[0 - item];
414 /* Sniper - Cannot shot a single arrow twice */
415 if ((snipe_type == SP_DOUBLE) && (o_ptr->number < 2))
416 snipe_type = SP_NONE;
418 describe_flavor(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
420 /* Use the proper number of shots */
421 thits = player_ptr->num_fire;
423 /* Use a base distance */
426 /* Base damage from thrown object plus launcher bonus */
427 tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
429 /* Actually "fire" the object */
430 bonus = (player_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
431 if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
432 chance = (player_ptr->skill_thb + (player_ptr->weapon_exp[0][j_ptr->sval] / 400 + bonus) * BTH_PLUS_ADJ);
434 chance = (player_ptr->skill_thb + ((player_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + bonus) * BTH_PLUS_ADJ);
436 PlayerEnergy(player_ptr).set_player_turn_energy(bow_energy(j_ptr->sval));
437 tmul = bow_tmul(j_ptr->sval);
439 /* Get extra "power" from "extra might" */
440 if (player_ptr->xtra_might)
443 tmul = tmul * (100 + (int)(adj_str_td[player_ptr->stat_index[A_STR]]) - 128);
445 /* Boost the damage */
450 tdis = 13 + tmul / 80;
451 if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW)) {
452 if (player_ptr->concent)
453 tdis -= (5 - (player_ptr->concent + 1) / 2);
458 project_length = tdis + 1;
460 /* Get a direction (or cancel) */
461 if (!get_aim_dir(player_ptr, &dir)) {
462 PlayerEnergy(player_ptr).reset_player_turn();
464 if (snipe_type == SP_AWAY)
465 snipe_type = SP_NONE;
467 /* need not to reset project_length (already did)*/
472 if (snipe_type != SP_NONE)
475 /* Predict the "target" location */
476 tx = player_ptr->x + 99 * ddx[dir];
477 ty = player_ptr->y + 99 * ddy[dir];
479 /* Check for "target request" */
480 if ((dir == 5) && target_okay(player_ptr)) {
485 /* Get projection path length */
486 tdis = projection_path(player_ptr, path_g, project_length, player_ptr->y, player_ptr->x, ty, tx, PROJECT_PATH | PROJECT_THRU) - 1;
488 project_length = 0; /* reset to default */
490 /* Don't shoot at my feet */
491 if (tx == player_ptr->x && ty == player_ptr->y) {
492 PlayerEnergy(player_ptr).reset_player_turn();
494 /* project_length is already reset to 0 */
499 /* Take a (partial) turn */
500 PlayerEnergy(player_ptr).div_player_turn_energy((ENERGY)thits);
501 player_ptr->is_fired = true;
503 /* Sniper - Difficult to shot twice at 1 turn */
504 if (snipe_type == SP_DOUBLE)
505 player_ptr->concent = (player_ptr->concent + 1) / 2;
507 /* Sniper - Repeat shooting when double shots */
508 for (i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++) {
509 /* Start at the player */
513 q_ptr->copy_from(o_ptr);
518 vary_item(player_ptr, item, -1);
521 handle_stuff(player_ptr);
526 /* The shot does not hit yet */
529 /* Travel until stopped */
530 for (cur_dis = 0; cur_dis <= tdis;) {
533 /* Hack -- Stop at the target */
534 if ((y == ty) && (x == tx))
537 /* Calculate the new location (see "project()") */
540 mmove2(&ny, &nx, player_ptr->y, player_ptr->x, ty, tx);
543 if (snipe_type == SP_KILL_WALL) {
544 g_ptr = &player_ptr->current_floor_ptr->grid_array[ny][nx];
546 if (g_ptr->cave_has_flag(FF::HURT_ROCK) && !g_ptr->m_idx) {
547 if (any_bits(g_ptr->info, (CAVE_MARK)))
548 msg_print(_("岩が砕け散った。", "Wall rocks were shattered."));
549 /* Forget the wall */
550 reset_bits(g_ptr->info, (CAVE_MARK));
551 set_bits(player_ptr->update, PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
553 /* Destroy the wall */
554 cave_alter_feat(player_ptr, ny, nx, FF::HURT_ROCK);
561 /* Stopped by walls/doors */
562 if (!cave_has_flag_bold(player_ptr->current_floor_ptr, ny, nx, FF::PROJECT) && !player_ptr->current_floor_ptr->grid_array[ny][nx].m_idx)
565 /* Advance the distance */
569 if (snipe_type == SP_LITE) {
570 set_bits(player_ptr->current_floor_ptr->grid_array[ny][nx].info, CAVE_GLOW);
571 note_spot(player_ptr, ny, nx);
572 lite_spot(player_ptr, ny, nx);
575 /* The player can see the (on screen) missile */
576 if (panel_contains(ny, nx) && player_can_see_bold(player_ptr, ny, nx)) {
577 SYMBOL_CODE c = object_char(q_ptr);
578 byte a = object_attr(q_ptr);
580 /* Draw, Hilite, Fresh, Pause, Erase */
582 print_rel(player_ptr, c, a, ny, nx);
583 move_cursor_relative(ny, nx);
585 term_xtra(TERM_XTRA_DELAY, msec);
586 lite_spot(player_ptr, ny, nx);
591 /* The player cannot see the missile */
593 /* Pause anyway, for consistancy **/
595 term_xtra(TERM_XTRA_DELAY, msec);
600 if (snipe_type == SP_KILL_TRAP) {
601 project(player_ptr, 0, 0, ny, nx, 0, GF_KILL_TRAP, (PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM));
605 if (snipe_type == SP_EVILNESS) {
606 reset_bits(player_ptr->current_floor_ptr->grid_array[ny][nx].info, (CAVE_GLOW | CAVE_MARK));
607 note_spot(player_ptr, ny, nx);
608 lite_spot(player_ptr, ny, nx);
614 /* Save the new location */
618 /* Monster here, Try to hit it */
619 if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
620 sound(SOUND_SHOOT_HIT);
621 grid_type *c_mon_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
623 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[c_mon_ptr->m_idx];
624 monster_race *r_ptr = &r_info[m_ptr->r_idx];
626 /* Check the visibility */
629 /* Note the collision */
632 if (monster_csleep_remaining(m_ptr)) {
633 if (none_bits(r_ptr->flags3, RF3_EVIL) || one_in_(5))
634 chg_virtue(player_ptr, V_COMPASSION, -1);
635 if (none_bits(r_ptr->flags3, RF3_EVIL) || one_in_(5))
636 chg_virtue(player_ptr, V_HONOUR, -1);
639 if ((r_ptr->level + 10) > player_ptr->lev) {
640 int now_exp = player_ptr->weapon_exp[0][j_ptr->sval];
641 if (now_exp < s_info[player_ptr->pclass].w_max[0][j_ptr->sval]) {
643 if (now_exp < WEAPON_EXP_BEGINNER)
645 else if (now_exp < WEAPON_EXP_SKILLED)
647 else if ((now_exp < WEAPON_EXP_EXPERT) && (player_ptr->lev > 19))
649 else if (player_ptr->lev > 34)
651 player_ptr->weapon_exp[0][j_ptr->sval] += amount;
652 set_bits(player_ptr->update, PU_BONUS);
656 if (player_ptr->riding) {
657 if ((player_ptr->skill_exp[SKILL_RIDING] < s_info[player_ptr->pclass].s_max[SKILL_RIDING])
658 && ((player_ptr->skill_exp[SKILL_RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200
659 < r_info[player_ptr->current_floor_ptr->m_list[player_ptr->riding].r_idx].level)
661 player_ptr->skill_exp[SKILL_RIDING] += 1;
662 set_bits(player_ptr->update, PU_BONUS);
666 /* Did we hit it (penalize range) */
667 if (test_hit_fire(player_ptr, chance - cur_dis, m_ptr, m_ptr->ml, o_name)) {
669 auto tdam = tdam_base; //!< @note 実際に与えるダメージ
670 auto base_dam = tdam; //!< @note 補正前の与えるダメージ(無傷、全ての耐性など)
672 /* Get extra damage from concentration */
673 if (player_ptr->concent)
674 tdam = boost_concentration_damage(player_ptr, tdam);
676 /* Handle unseen monster */
678 /* Invisible monster */
679 msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
682 /* Handle visible monster */
684 GAME_TEXT m_name[MAX_NLEN];
686 /* Get "the monster" or "it" */
687 monster_desc(player_ptr, m_name, m_ptr, 0);
689 msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
692 if (!player_ptr->image)
693 monster_race_track(player_ptr, m_ptr->ap_r_idx);
694 health_track(player_ptr, c_mon_ptr->m_idx);
698 if (snipe_type == SP_NEEDLE) {
699 if ((randint1(randint1(r_ptr->level / (3 + player_ptr->concent)) + (8 - player_ptr->concent)) == 1)
700 && none_bits(r_ptr->flags1, RF1_UNIQUE) && none_bits(r_ptr->flags7, RF7_UNIQUE2)) {
701 GAME_TEXT m_name[MAX_NLEN];
703 /* Get "the monster" or "it" */
704 monster_desc(player_ptr, m_name, m_ptr, 0);
706 tdam = m_ptr->hp + 1;
708 msg_format(_("%sの急所に突き刺さった!", "Your shot hit a fatal spot of %s!"), m_name);
714 /* Apply special damage */
715 tdam = calc_shot_damage_with_slay(player_ptr, j_ptr, q_ptr, tdam, m_ptr, snipe_type);
716 tdam = critical_shot(player_ptr, q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
718 /* No negative damage */
722 /* Modify the damage */
724 tdam = mon_damage_mod(player_ptr, m_ptr, tdam, false);
727 msg_format_wizard(player_ptr, CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"), tdam,
728 m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
731 if (snipe_type == SP_EXPLODE) {
732 uint16_t flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
734 sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
735 project(player_ptr, 0, ((player_ptr->concent + 1) / 2 + 1), ny, nx, base_dam, GF_MISSILE, flg);
740 if (snipe_type == SP_HOLYNESS) {
741 set_bits(player_ptr->current_floor_ptr->grid_array[ny][nx].info, CAVE_GLOW);
742 note_spot(player_ptr, ny, nx);
743 lite_spot(player_ptr, ny, nx);
746 /* Hit the monster, check for death */
747 MonsterDamageProcessor mdp(player_ptr, c_mon_ptr->m_idx, tdam, &fear);
748 if (mdp.mon_take_hit(extract_note_dies(real_r_idx(m_ptr)))) {
755 if (q_ptr->is_fixed_artifact() && (player_ptr->pclass != CLASS_SNIPER || player_ptr->concent == 0)) {
756 GAME_TEXT m_name[MAX_NLEN];
758 monster_desc(player_ptr, m_name, m_ptr, 0);
761 msg_format(_("%sは%sに突き刺さった!", "%^s is stuck in %s!"), o_name, m_name);
764 message_pain(player_ptr, c_mon_ptr->m_idx, tdam);
766 /* Anger the monster */
768 anger_monster(player_ptr, m_ptr);
770 if (fear && m_ptr->ml) {
771 GAME_TEXT m_name[MAX_NLEN];
773 monster_desc(player_ptr, m_name, m_ptr, 0);
774 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
777 set_target(m_ptr, player_ptr->y, player_ptr->x);
780 if (snipe_type == SP_RUSH) {
781 int n = randint1(5) + 3;
782 MONSTER_IDX m_idx = c_mon_ptr->m_idx;
784 for (; cur_dis <= tdis;) {
791 /* Calculate the new location (see "project()") */
792 mmove2(&ny, &nx, player_ptr->y, player_ptr->x, ty, tx);
794 /* Stopped by wilderness boundary */
795 if (!in_bounds2(player_ptr->current_floor_ptr, ny, nx))
798 /* Stopped by walls/doors */
799 if (!player_can_enter(player_ptr, player_ptr->current_floor_ptr->grid_array[ny][nx].feat, 0))
802 /* Stopped by monsters */
803 if (!is_cave_empty_bold(player_ptr, ny, nx))
806 player_ptr->current_floor_ptr->grid_array[ny][nx].m_idx = m_idx;
807 player_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = 0;
812 update_monster(player_ptr, m_idx, true);
815 lite_spot(player_ptr, ny, nx);
816 lite_spot(player_ptr, oy, ox);
818 term_xtra(TERM_XTRA_DELAY, msec);
831 if (snipe_type == SP_PIERCE) {
832 if (player_ptr->concent < 1)
834 player_ptr->concent--;
843 /* Chance of breakage (during attacks) */
844 j = (hit_body ? breakage_chance(player_ptr, q_ptr, player_ptr->pclass == CLASS_ARCHER, snipe_type) : 0);
847 MONSTER_IDX m_idx = player_ptr->current_floor_ptr->grid_array[y][x].m_idx;
848 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
849 OBJECT_IDX o_idx = o_pop(player_ptr->current_floor_ptr);
852 msg_format(_("%sはどこかへ行った。", "The %s went somewhere."), o_name);
853 if (q_ptr->is_fixed_artifact()) {
854 a_info[j_ptr->name1].cur_num = 0;
859 o_ptr = &player_ptr->current_floor_ptr->o_list[o_idx];
860 o_ptr->copy_from(q_ptr);
863 reset_bits(o_ptr->marked, OM_TOUCHED);
865 /* Forget location */
866 o_ptr->iy = o_ptr->ix = 0;
868 /* Memorize monster */
869 o_ptr->held_m_idx = m_idx;
872 m_ptr->hold_o_idx_list.add(player_ptr->current_floor_ptr, o_idx);
873 } else if (cave_has_flag_bold(player_ptr->current_floor_ptr, y, x, FF::PROJECT)) {
874 /* Drop (or break) near that location */
875 (void)drop_near(player_ptr, q_ptr, j, y, x);
877 /* Drop (or break) near that location */
878 (void)drop_near(player_ptr, q_ptr, j, prev_y, prev_x);
881 /* Sniper - Repeat shooting when double shots */
884 /* Sniper - Loose his/her concentration after any shot */
885 if (player_ptr->concent)
886 reset_concentration(player_ptr, false);
890 * @brief プレイヤーからモンスターへの射撃命中判定 /
891 * Determine if the player "hits" a monster (normal combat).
892 * @param chance 基本命中値
893 * @param monster_ptr モンスターの構造体参照ポインタ
894 * @param vis 目標を視界に捕らえているならばTRUEを指定
895 * @param o_name メッセージ表示時のモンスター名
896 * @return 命中と判定された場合TRUEを返す
897 * @note Always miss 5%, always hit 5%, otherwise random.
899 bool test_hit_fire(player_type *player_ptr, int chance, monster_type *m_ptr, int vis, char *o_name)
903 monster_race *r_ptr = &r_info[m_ptr->r_idx];
905 /* Percentile dice */
908 /* Snipers with high-concentration reduce instant miss percentage.*/
909 k += player_ptr->concent;
911 /* Hack -- Instant miss or hit */
917 if (player_ptr->pseikaku == PERSONALITY_LAZY)
926 if (player_ptr->concent) {
927 ac *= (8 - player_ptr->concent);
931 if (m_ptr->r_idx == MON_GOEMON && !monster_csleep_remaining(m_ptr))
934 /* Invisible monsters are harder to hit */
936 chance = (chance + 1) / 2;
938 /* Power competes against armor */
939 if (randint0(chance) < (ac * 3 / 4)) {
940 if (m_ptr->r_idx == MON_GOEMON && !monster_csleep_remaining(m_ptr)) {
941 GAME_TEXT m_name[MAX_NLEN];
942 monster_desc(player_ptr, m_name, m_ptr, 0);
943 msg_format(_("%sは%sを斬り捨てた!", "%s cuts down %s!"), m_name, o_name);
953 * @brief プレイヤーからモンスターへの射撃クリティカル判定 /
954 * Critical hits (from objects thrown by player) Factor in item weight, total plusses, and player level.
955 * @param weight 矢弾の重量
956 * @param plus_ammo 矢弾の命中修正
957 * @param plus_bow 弓の命中修正
958 * @param dam 現在算出中のダメージ値
959 * @return クリティカル修正が入ったダメージ値
961 HIT_POINT critical_shot(player_type *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, HIT_POINT dam)
964 object_type *j_ptr = &player_ptr->inventory_list[INVEN_BOW];
966 /* Extract "shot" power */
967 i = player_ptr->to_h_b + plus_ammo;
969 if (player_ptr->tval_ammo == TV_BOLT)
970 i = (player_ptr->skill_thb + (player_ptr->weapon_exp[0][j_ptr->sval] / 400 + i) * BTH_PLUS_ADJ);
972 i = (player_ptr->skill_thb + ((player_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + i) * BTH_PLUS_ADJ);
974 /* Snipers can shot more critically with crossbows */
975 if (player_ptr->concent)
976 i += ((i * player_ptr->concent) / 5);
977 if ((player_ptr->pclass == CLASS_SNIPER) && (player_ptr->tval_ammo == TV_BOLT))
980 /* Good bow makes more critical */
981 i += plus_bow * 8 * (player_ptr->concent ? player_ptr->concent + 5 : 5);
984 if (randint1(10000) <= i) {
985 k = weight * randint1(500);
988 msg_print(_("手ごたえがあった!", "It was a good hit!"));
990 } else if (k < 1350) {
991 msg_print(_("かなりの手ごたえがあった!", "It was a great hit!"));
994 msg_print(_("会心の一撃だ!", "It was a superb hit!"));
1003 * @brief 射撃武器の攻撃に必要な基本消費エネルギーを返す/Return bow energy
1004 * @param sval 射撃武器のアイテム副分類ID
1005 * @return 消費する基本エネルギー
1007 ENERGY bow_energy(OBJECT_SUBTYPE_VALUE sval)
1009 ENERGY energy = 10000;
1011 /* Analyze the launcher */
1013 /* Sling and ammo */
1019 /* Short Bow and Arrow */
1020 case SV_SHORT_BOW: {
1025 /* Long Bow and Arrow */
1031 /* Bow of irresponsiblity and Arrow */
1032 case SV_NAMAKE_BOW: {
1037 /* Light Crossbow and Bolt */
1038 case SV_LIGHT_XBOW: {
1043 /* Heavy Crossbow and Bolt */
1044 case SV_HEAVY_XBOW: {
1056 int bow_tmul(OBJECT_SUBTYPE_VALUE sval)
1060 /* Analyze the launcher */
1062 /* Sling and ammo */
1068 /* Short Bow and Arrow */
1069 case SV_SHORT_BOW: {
1074 /* Long Bow and Arrow */
1080 /* Bow of irresponsiblity and Arrow */
1081 case SV_NAMAKE_BOW: {
1086 /* Light Crossbow and Bolt */
1087 case SV_LIGHT_XBOW: {
1092 /* Heavy Crossbow and Bolt */
1093 case SV_HEAVY_XBOW: {
1103 * @brief 射撃時クリティカルによるダメージ期待値修正計算(スナイパーの集中処理と武器経験値) / critical happens at i / 10000
1104 * @param player_ptr プレイヤーへの参照ポインタ
1105 * @param plus_ammo 矢弾のダメージ修正
1106 * @param plus_bow 弓のダメージ修正
1108 * @note 基本ダメージ量と重量はこの部位では計算に加わらない。
1110 HIT_POINT calc_crit_ratio_shot(player_type *player_ptr, HIT_POINT plus_ammo, HIT_POINT plus_bow)
1113 object_type *j_ptr = &player_ptr->inventory_list[INVEN_BOW];
1115 /* Extract "shot" power */
1116 i = player_ptr->to_h_b + plus_ammo;
1118 if (player_ptr->tval_ammo == TV_BOLT)
1119 i = (player_ptr->skill_thb + (player_ptr->weapon_exp[0][j_ptr->sval] / 400 + i) * BTH_PLUS_ADJ);
1121 i = (player_ptr->skill_thb + ((player_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + i) * BTH_PLUS_ADJ);
1123 /* Snipers can shot more critically with crossbows */
1124 if (player_ptr->concent)
1125 i += ((i * player_ptr->concent) / 5);
1126 if ((player_ptr->pclass == CLASS_SNIPER) && (player_ptr->tval_ammo == TV_BOLT))
1129 /* Good bow makes more critical */
1130 i += plus_bow * 8 * (player_ptr->concent ? player_ptr->concent + 5 : 5);
1139 * @brief 射撃時クリティカルによるダメージ期待値修正計算(重量依存部分) / critical happens at i / 10000
1140 * @param weight 武器の重量
1141 * @param plus_ammo 矢弾のダメージ修正
1142 * @param plus_bow 弓のダメージ修正
1143 * @param dam 基本ダメージ量
1146 HIT_POINT calc_expect_crit_shot(player_type *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, HIT_POINT dam)
1150 i = calc_crit_ratio_shot(player_ptr, plus_ammo, plus_bow);
1155 crit = MIN(500, 900 / weight);
1156 num += dam * 3 / 2 * crit;
1159 crit = MIN(500, 1350 / weight);
1161 num += dam * 2 * crit;
1166 num += dam * 3 * crit;
1172 num += (10000 - i) * dam;
1179 * @brief 攻撃時クリティカルによるダメージ期待値修正計算(重量と毒針処理) / critical happens at i / 10000
1180 * @param player_ptr プレイヤーへの参照ポインタ
1181 * @param weight 武器の重量
1182 * @param plus 武器のダメージ修正
1184 * @param meichuu 命中値
1185 * @param dokubari 毒針処理か否か
1186 * @param impact 強撃かどうか
1189 HIT_POINT calc_expect_crit(player_type *player_ptr, WEIGHT weight, int plus, HIT_POINT dam, int16_t meichuu, bool dokubari, bool impact)
1194 int i = (weight + (meichuu * 3 + plus * 5) + player_ptr->skill_thn);
1198 // 通常ダメージdam、武器重量weightでクリティカルが発生した時のクリティカルダメージ期待値
1199 auto calc_weight_expect_dam = [](HIT_POINT dam, WEIGHT weight) {
1201 for (int d = 1; d <= 650; ++d) {
1203 sum += std::get<0>(apply_critical_norm_damage(k, dam));
1211 for (int d = 1; d <= 650; ++d) {
1212 num += calc_weight_expect_dam(dam, weight + d);
1216 num += calc_weight_expect_dam(dam, weight);
1219 int pow = (player_ptr->pclass == CLASS_NINJA) ? 4444 : 5000;
1224 num += (pow - i) * dam;