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/stuff-handler.h"
6 #include "effect/attribute-types.h"
7 #include "effect/effect-characteristics.h"
8 #include "effect/effect-processor.h"
9 #include "effect/spells-effect-util.h"
10 #include "flavor/flavor-describer.h"
11 #include "flavor/object-flavor-types.h"
12 #include "floor/cave.h"
13 #include "floor/floor-object.h"
14 #include "floor/geometry.h"
15 #include "game-option/cheat-types.h"
16 #include "game-option/special-options.h"
17 #include "grid/feature-flag-types.h"
18 #include "grid/feature.h"
19 #include "grid/grid.h"
20 #include "inventory/inventory-object.h"
21 #include "inventory/inventory-slot-types.h"
22 #include "io/cursor.h"
23 #include "io/screen-util.h"
24 #include "main/sound-definitions-table.h"
25 #include "main/sound-of-music.h"
26 #include "mind/mind-sniper.h"
27 #include "mind/snipe-types.h"
28 #include "monster-floor/monster-death.h"
29 #include "monster-floor/monster-move.h"
30 #include "monster-race/monster-race.h"
31 #include "monster-race/race-flags-resistance.h"
32 #include "monster-race/race-flags1.h"
33 #include "monster-race/race-flags2.h"
34 #include "monster-race/race-flags3.h"
35 #include "monster-race/race-flags7.h"
36 #include "monster-race/race-indice-types.h"
37 #include "monster-race/race-resistance-mask.h"
38 #include "monster/monster-damage.h"
39 #include "monster/monster-describer.h"
40 #include "monster/monster-info.h"
41 #include "monster/monster-pain-describer.h"
42 #include "monster/monster-status-setter.h"
43 #include "monster/monster-status.h"
44 #include "monster/monster-update.h"
45 #include "object/object-broken.h"
46 #include "object/object-info.h"
47 #include "object/object-mark-types.h"
48 #include "player-base/player-class.h"
49 #include "player-info/class-info.h"
50 #include "player-info/sniper-data-type.h"
51 #include "player-status/player-energy.h"
52 #include "player/player-personality-types.h"
53 #include "player/player-skill.h"
54 #include "player/player-status-table.h"
55 #include "sv-definition/sv-bow-types.h"
56 #include "system/artifact-type-definition.h"
57 #include "system/baseitem-info.h"
58 #include "system/floor-type-definition.h"
59 #include "system/grid-type-definition.h"
60 #include "system/item-entity.h"
61 #include "system/monster-entity.h"
62 #include "system/monster-race-info.h"
63 #include "system/player-type-definition.h"
64 #include "system/redrawing-flags-updater.h"
65 #include "target/projection-path-calculator.h"
66 #include "target/target-checker.h"
67 #include "target/target-getter.h"
68 #include "timed-effect/player-hallucination.h"
69 #include "timed-effect/timed-effects.h"
70 #include "util/bit-flags-calculator.h"
71 #include "view/display-messages.h"
72 #include "wizard/wizard-messages.h"
73 #include "world/world-object.h"
77 * @param bow_ptr 弓のオブジェクト構造体参照ポインタ
78 * @param arrow_ptr 矢弾のオブジェクト構造体参照ポインタ
79 * @return スナイパーの射撃属性、弓矢の属性を考慮する。デフォルトはGF_PLAYER_SHOOT。
81 AttributeFlags shot_attribute(PlayerType *player_ptr, ItemEntity *bow_ptr, ItemEntity *arrow_ptr, SPELL_IDX snipe_type)
83 AttributeFlags attribute_flags{};
84 attribute_flags.set(AttributeType::PLAYER_SHOOT);
86 const auto arrow_flags = arrow_ptr->get_flags();
87 const auto bow_flags = bow_ptr->get_flags();
88 const auto flags = bow_flags | arrow_flags;
90 static const struct snipe_convert_table_t {
92 AttributeType attribute;
93 } snipe_convert_table[] = {
94 { SP_LITE, AttributeType::LITE },
95 { SP_FIRE, AttributeType::FIRE },
96 { SP_COLD, AttributeType::COLD },
97 { SP_ELEC, AttributeType::ELEC },
98 { SP_KILL_WALL, AttributeType::KILL_WALL },
99 { SP_EVILNESS, AttributeType::HELL_FIRE },
100 { SP_HOLYNESS, AttributeType::HOLY_FIRE },
101 { SP_FINAL, AttributeType::MANA },
104 static const struct brand_convert_table_t {
106 AttributeType attribute;
107 } brand_convert_table[] = {
108 { TR_BRAND_ACID, AttributeType::ACID },
109 { TR_BRAND_FIRE, AttributeType::FIRE },
110 { TR_BRAND_ELEC, AttributeType::ELEC },
111 { TR_BRAND_COLD, AttributeType::COLD },
112 { TR_BRAND_POIS, AttributeType::POIS },
113 { TR_SLAY_GOOD, AttributeType::HELL_FIRE },
114 { TR_KILL_GOOD, AttributeType::HELL_FIRE },
115 { TR_SLAY_EVIL, AttributeType::HOLY_FIRE },
116 { TR_KILL_EVIL, AttributeType::HOLY_FIRE },
119 for (size_t i = 0; i < sizeof(snipe_convert_table) / sizeof(snipe_convert_table[0]); ++i) {
120 const struct snipe_convert_table_t *p = &snipe_convert_table[i];
122 if (snipe_type == p->snipe_type) {
123 attribute_flags.set(p->attribute);
127 for (size_t i = 0; i < sizeof(brand_convert_table) / sizeof(brand_convert_table[0]); ++i) {
128 const struct brand_convert_table_t *p = &brand_convert_table[i];
130 if (flags.has(p->brand_type)) {
131 attribute_flags.set(p->attribute);
135 if ((flags.has(TR_FORCE_WEAPON)) && (player_ptr->csp > (player_ptr->msp / 30))) {
136 attribute_flags.set(AttributeType::MANA);
139 return attribute_flags;
143 * @brief 矢弾を射撃した際のスレイ倍率をかけた結果を返す /
144 * Determines the odds of an object breaking when thrown at a monster
145 * @param bow_ptr 弓のオブジェクト構造体参照ポインタ
146 * @param arrow_ptr 矢弾のオブジェクト構造体参照ポインタ
147 * @param tdam 計算途中のダメージ量
148 * @param monster_ptr 目標モンスターの構造体参照ポインタ
149 * @return スレイ倍率をかけたダメージ量
151 static MULTIPLY calc_shot_damage_with_slay(
152 PlayerType *player_ptr, ItemEntity *bow_ptr, ItemEntity *arrow_ptr, int tdam, MonsterEntity *monster_ptr, SPELL_IDX snipe_type)
156 auto &monrace = monster_ptr->get_monrace();
158 const auto arrow_flags = arrow_ptr->get_flags();
159 const auto bow_flags = bow_ptr->get_flags();
160 const auto flags = bow_flags | arrow_flags;
162 /* Some "weapons" and "ammo" do extra damage */
163 switch (arrow_ptr->bi_key.tval()) {
164 case ItemKindType::SHOT:
165 case ItemKindType::ARROW:
166 case ItemKindType::BOLT: {
167 if ((flags.has(TR_SLAY_ANIMAL)) && monrace.kind_flags.has(MonsterKindType::ANIMAL)) {
168 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
169 monrace.r_kind_flags.set(MonsterKindType::ANIMAL);
176 if ((flags.has(TR_KILL_ANIMAL)) && monrace.kind_flags.has(MonsterKindType::ANIMAL)) {
177 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
178 monrace.r_kind_flags.set(MonsterKindType::ANIMAL);
185 if ((flags.has(TR_SLAY_EVIL)) && monrace.kind_flags.has(MonsterKindType::EVIL)) {
186 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
187 monrace.r_kind_flags.set(MonsterKindType::EVIL);
194 if ((flags.has(TR_KILL_EVIL)) && monrace.kind_flags.has(MonsterKindType::EVIL)) {
195 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
196 monrace.r_kind_flags.set(MonsterKindType::EVIL);
203 if ((flags.has(TR_SLAY_GOOD)) && monrace.kind_flags.has(MonsterKindType::GOOD)) {
204 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
205 monrace.r_kind_flags.set(MonsterKindType::GOOD);
212 if ((flags.has(TR_KILL_GOOD)) && monrace.kind_flags.has(MonsterKindType::GOOD)) {
213 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
214 monrace.r_kind_flags.set(MonsterKindType::GOOD);
221 if ((flags.has(TR_SLAY_HUMAN)) && monrace.kind_flags.has(MonsterKindType::HUMAN)) {
222 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
223 monrace.r_kind_flags.set(MonsterKindType::HUMAN);
230 if ((flags.has(TR_KILL_HUMAN)) && monrace.kind_flags.has(MonsterKindType::HUMAN)) {
231 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
232 monrace.r_kind_flags.set(MonsterKindType::HUMAN);
239 if ((flags.has(TR_SLAY_UNDEAD)) && monrace.kind_flags.has(MonsterKindType::UNDEAD)) {
240 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
241 monrace.r_kind_flags.set(MonsterKindType::UNDEAD);
248 if ((flags.has(TR_KILL_UNDEAD)) && monrace.kind_flags.has(MonsterKindType::UNDEAD)) {
249 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
250 monrace.r_kind_flags.set(MonsterKindType::UNDEAD);
257 if ((flags.has(TR_SLAY_DEMON)) && monrace.kind_flags.has(MonsterKindType::DEMON)) {
258 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
259 monrace.r_kind_flags.set(MonsterKindType::DEMON);
266 if ((flags.has(TR_KILL_DEMON)) && monrace.kind_flags.has(MonsterKindType::DEMON)) {
267 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
268 monrace.r_kind_flags.set(MonsterKindType::DEMON);
275 if ((flags.has(TR_SLAY_ORC)) && monrace.kind_flags.has(MonsterKindType::ORC)) {
276 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
277 monrace.r_kind_flags.set(MonsterKindType::ORC);
284 if ((flags.has(TR_KILL_ORC)) && monrace.kind_flags.has(MonsterKindType::ORC)) {
285 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
286 monrace.r_kind_flags.set(MonsterKindType::ORC);
293 if ((flags.has(TR_SLAY_TROLL)) && monrace.kind_flags.has(MonsterKindType::TROLL)) {
294 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
295 monrace.r_kind_flags.set(MonsterKindType::TROLL);
303 if ((flags.has(TR_KILL_TROLL)) && monrace.kind_flags.has(MonsterKindType::TROLL)) {
304 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
305 monrace.r_kind_flags.set(MonsterKindType::TROLL);
312 if ((flags.has(TR_SLAY_GIANT)) && monrace.kind_flags.has(MonsterKindType::GIANT)) {
313 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
314 monrace.r_kind_flags.set(MonsterKindType::GIANT);
321 if ((flags.has(TR_KILL_GIANT)) && monrace.kind_flags.has(MonsterKindType::GIANT)) {
322 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
323 monrace.r_kind_flags.set(MonsterKindType::GIANT);
330 if ((flags.has(TR_SLAY_DRAGON)) && monrace.kind_flags.has(MonsterKindType::DRAGON)) {
331 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
332 monrace.r_kind_flags.set(MonsterKindType::DRAGON);
339 if ((flags.has(TR_KILL_DRAGON)) && monrace.kind_flags.has(MonsterKindType::DRAGON)) {
340 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
341 monrace.r_kind_flags.set(MonsterKindType::DRAGON);
347 auto can_eliminate_smaug = arrow_ptr->is_specific_artifact(FixedArtifactId::BARD_ARROW);
348 can_eliminate_smaug &= player_ptr->inventory_list[INVEN_BOW].is_specific_artifact(FixedArtifactId::BARD);
349 can_eliminate_smaug &= monster_ptr->r_idx == MonsterRaceId::SMAUG;
350 if (can_eliminate_smaug) {
355 if (flags.has(TR_BRAND_ACID)) {
356 /* Notice immunity */
357 if (monrace.resistance_flags.has_any_of(RFR_EFF_IM_ACID_MASK)) {
358 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
359 monrace.r_resistance_flags.set(monrace.resistance_flags & RFR_EFF_IM_ACID_MASK);
368 if (flags.has(TR_BRAND_ELEC)) {
369 /* Notice immunity */
370 if (monrace.resistance_flags.has_any_of(RFR_EFF_IM_ELEC_MASK)) {
371 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
372 monrace.r_resistance_flags.set(monrace.resistance_flags & RFR_EFF_IM_ELEC_MASK);
381 if (flags.has(TR_BRAND_FIRE)) {
382 /* Notice immunity */
383 if (monrace.resistance_flags.has_any_of(RFR_EFF_IM_FIRE_MASK)) {
384 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
385 monrace.r_resistance_flags.set(monrace.resistance_flags & RFR_EFF_IM_FIRE_MASK);
388 /* Otherwise, take the damage */
390 if (monrace.resistance_flags.has(MonsterResistanceType::HURT_FIRE)) {
394 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
395 monrace.r_resistance_flags.set(MonsterResistanceType::HURT_FIRE);
397 } else if (mult < 17) {
403 if (flags.has(TR_BRAND_COLD)) {
404 /* Notice immunity */
405 if (monrace.resistance_flags.has_any_of(RFR_EFF_IM_COLD_MASK)) {
406 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
407 monrace.r_resistance_flags.set(monrace.resistance_flags & RFR_EFF_IM_COLD_MASK);
410 /* Otherwise, take the damage */
412 if (monrace.resistance_flags.has(MonsterResistanceType::HURT_COLD)) {
416 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
417 monrace.r_resistance_flags.set(MonsterResistanceType::HURT_COLD);
419 } else if (mult < 17) {
425 if (flags.has(TR_BRAND_POIS)) {
426 /* Notice immunity */
427 if (monrace.resistance_flags.has_any_of(RFR_EFF_IM_POISON_MASK)) {
428 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
429 monrace.r_resistance_flags.set(monrace.resistance_flags & RFR_EFF_IM_POISON_MASK);
432 /* Otherwise, take the damage */
440 if ((flags.has(TR_FORCE_WEAPON)) && (player_ptr->csp > (player_ptr->msp / 30))) {
441 player_ptr->csp -= (1 + (player_ptr->msp / 30));
442 RedrawingFlagsUpdater::get_instance().set_flag(MainWindowRedrawingFlag::MP);
454 mult = calc_snipe_damage_with_slay(player_ptr, mult, monster_ptr, snipe_type);
457 /* Return the total damage */
458 return tdam * mult / 10;
463 * @param i_idx 射撃するオブジェクトの所持ID
464 * @param bow_ptr 射撃武器のオブジェクト参照ポインタ
466 void exe_fire(PlayerType *player_ptr, INVENTORY_IDX i_idx, ItemEntity *j_ptr, SPELL_IDX snipe_type)
468 POSITION y, x, ny, nx, ty, tx, prev_y, prev_x;
473 AttributeFlags attribute_flags{};
474 attribute_flags.set(AttributeType::PLAYER_SHOOT);
476 auto hit_body = false;
477 auto stick_to = false;
479 /* Access the item (if in the pack) */
480 auto *floor_ptr = player_ptr->current_floor_ptr;
482 o_ptr = &player_ptr->inventory_list[i_idx];
484 o_ptr = &floor_ptr->o_list[0 - i_idx];
487 /* Sniper - Cannot shot a single arrow twice */
488 if ((snipe_type == SP_DOUBLE) && (o_ptr->number < 2)) {
489 snipe_type = SP_NONE;
492 const auto item_name = describe_flavor(player_ptr, o_ptr, OD_OMIT_PREFIX);
494 /* Use the proper number of shots */
495 auto thits = player_ptr->num_fire;
497 /* Use a base distance */
500 /* Base damage from thrown object plus launcher bonus */
501 auto tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
503 /* Actually "fire" the object */
504 const auto tval = j_ptr->bi_key.tval();
505 const auto median_skill_exp = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2;
506 const auto bonus = (player_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
507 const auto &weapon_exps = player_ptr->weapon_exp[tval];
508 constexpr auto bow_magnification = 200;
509 constexpr auto xbow_magnification = 400;
511 if (tval == ItemKindType::NONE) {
512 chance = (player_ptr->skill_thb + ((weapon_exps[0] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ);
514 const auto sval = *j_ptr->bi_key.sval();
515 if (j_ptr->is_cross_bow()) {
516 chance = (player_ptr->skill_thb + (weapon_exps[sval] / xbow_magnification + bonus) * BTH_PLUS_ADJ);
518 chance = (player_ptr->skill_thb + ((weapon_exps[sval] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ);
522 PlayerEnergy(player_ptr).set_player_turn_energy(j_ptr->get_bow_energy());
523 auto tmul = j_ptr->get_arrow_magnification();
525 /* Get extra "power" from "extra might" */
526 if (player_ptr->xtra_might) {
530 tmul = tmul * (100 + (int)(adj_str_td[player_ptr->stat_index[A_STR]]) - 128);
532 /* Boost the damage */
536 auto sniper_data = PlayerClass(player_ptr).get_specific_data<SniperData>();
537 auto sniper_concent = sniper_data ? sniper_data->concent : 0;
540 tdis = 13 + tmul / 80;
541 if (j_ptr->is_cross_bow()) {
542 tdis -= (5 - (sniper_concent + 1) / 2);
545 project_length = tdis + 1;
547 /* Get a direction (or cancel) */
549 if (!get_aim_dir(player_ptr, &dir)) {
550 PlayerEnergy(player_ptr).reset_player_turn();
552 if (snipe_type == SP_AWAY) {
553 snipe_type = SP_NONE;
556 /* need not to reset project_length (already did)*/
561 if (snipe_type != SP_NONE) {
565 /* Predict the "target" location */
566 tx = player_ptr->x + 99 * ddx[dir];
567 ty = player_ptr->y + 99 * ddy[dir];
569 /* Check for "target request" */
570 if ((dir == 5) && target_okay(player_ptr)) {
575 /* Get projection path length */
576 projection_path path_g(player_ptr, project_length, player_ptr->y, player_ptr->x, ty, tx, PROJECT_PATH | PROJECT_THRU);
577 tdis = path_g.path_num() - 1;
579 project_length = 0; /* reset to default */
581 /* Don't shoot at my feet */
582 if (tx == player_ptr->x && ty == player_ptr->y) {
583 PlayerEnergy(player_ptr).reset_player_turn();
585 /* project_length is already reset to 0 */
590 /* Take a (partial) turn */
591 PlayerEnergy(player_ptr).div_player_turn_energy(thits);
592 player_ptr->is_fired = true;
594 /* Sniper - Difficult to shot twice at 1 turn */
595 if (snipe_type == SP_DOUBLE) {
596 sniper_concent = (sniper_concent + 1) / 2;
599 /* Sniper - Repeat shooting when double shots */
600 for (auto i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++) {
601 /* Start at the player */
605 q_ptr->copy_from(o_ptr);
610 vary_item(player_ptr, i_idx, -1);
613 handle_stuff(player_ptr);
618 /* The shot does not hit yet */
621 /* Travel until stopped */
622 for (auto cur_dis = 0; cur_dis <= tdis;) {
625 /* Hack -- Stop at the target */
626 if ((y == ty) && (x == tx)) {
630 /* Calculate the new location (see "project()") */
631 const auto pos = mmove2({ y, x }, player_ptr->get_position(), { ty, tx });
636 if (snipe_type == SP_KILL_WALL) {
637 g_ptr = &floor_ptr->grid_array[ny][nx];
639 if (g_ptr->cave_has_flag(TerrainCharacteristics::HURT_ROCK) && !g_ptr->m_idx) {
640 if (any_bits(g_ptr->info, (CAVE_MARK))) {
641 msg_print(_("岩が砕け散った。", "Wall rocks were shattered."));
643 /* Forget the wall */
644 reset_bits(g_ptr->info, (CAVE_MARK));
645 static constexpr auto flags = {
646 StatusRecalculatingFlag::VIEW,
647 StatusRecalculatingFlag::LITE,
648 StatusRecalculatingFlag::FLOW,
649 StatusRecalculatingFlag::MONSTER_LITE,
651 RedrawingFlagsUpdater::get_instance().set_flags(flags);
653 /* Destroy the wall */
654 cave_alter_feat(player_ptr, ny, nx, TerrainCharacteristics::HURT_ROCK);
661 /* Stopped by walls/doors */
662 if (!cave_has_flag_bold(floor_ptr, ny, nx, TerrainCharacteristics::PROJECT) && !floor_ptr->grid_array[ny][nx].m_idx) {
666 /* Advance the distance */
670 if (snipe_type == SP_LITE) {
671 set_bits(floor_ptr->grid_array[ny][nx].info, CAVE_GLOW);
672 note_spot(player_ptr, ny, nx);
673 lite_spot(player_ptr, ny, nx);
676 /* The player can see the (on screen) missile */
677 if (panel_contains(ny, nx) && player_can_see_bold(player_ptr, ny, nx)) {
678 const auto a = q_ptr->get_color();
679 const auto c = q_ptr->get_symbol();
681 /* Draw, Hilite, Fresh, Pause, Erase */
682 if (delay_factor > 0) {
683 print_rel(player_ptr, c, a, ny, nx);
684 move_cursor_relative(ny, nx);
686 term_xtra(TERM_XTRA_DELAY, delay_factor);
687 lite_spot(player_ptr, ny, nx);
692 /* The player cannot see the missile */
694 /* Pause anyway, for consistancy **/
695 if (delay_factor > 0) {
696 term_xtra(TERM_XTRA_DELAY, delay_factor);
701 if (snipe_type == SP_KILL_TRAP) {
702 constexpr auto flags = PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM;
703 project(player_ptr, 0, 0, ny, nx, 0, AttributeType::KILL_TRAP, flags);
707 if (snipe_type == SP_EVILNESS) {
708 reset_bits(floor_ptr->grid_array[ny][nx].info, (CAVE_GLOW | CAVE_MARK));
709 note_spot(player_ptr, ny, nx);
710 lite_spot(player_ptr, ny, nx);
716 /* Save the new location */
720 /* Monster here, Try to hit it */
721 if (floor_ptr->grid_array[y][x].m_idx) {
722 sound(SOUND_SHOOT_HIT);
723 Grid *c_mon_ptr = &floor_ptr->grid_array[y][x];
725 auto *m_ptr = &floor_ptr->m_list[c_mon_ptr->m_idx];
726 auto *r_ptr = &m_ptr->get_monrace();
728 /* Check the visibility */
729 auto visible = m_ptr->ml;
731 /* Note the collision */
734 if (m_ptr->is_asleep()) {
735 if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5)) {
736 chg_virtue(player_ptr, Virtue::COMPASSION, -1);
738 if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5)) {
739 chg_virtue(player_ptr, Virtue::HONOUR, -1);
743 if ((r_ptr->level + 10) > player_ptr->lev) {
744 PlayerSkill(player_ptr).gain_range_weapon_exp(j_ptr);
747 if (player_ptr->riding) {
748 PlayerSkill(player_ptr).gain_riding_skill_exp_on_range_attack();
751 /* Did we hit it (penalize range) */
752 if (test_hit_fire(player_ptr, chance - cur_dis, m_ptr, m_ptr->ml, item_name.data())) {
754 auto tdam = tdam_base; //!< @note 実際に与えるダメージ
755 auto base_dam = tdam; //!< @note 補正前の与えるダメージ(無傷、全ての耐性など)
757 /* Get extra damage from concentration */
758 tdam = boost_concentration_damage(player_ptr, tdam);
760 /* Handle unseen monster */
762 /* Invisible monster */
763 msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), item_name.data());
766 /* Handle visible monster */
768 /* Get "the monster" or "it" */
769 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
771 msg_format(_("%sが%sに命中した。", "The %s hits %s."), item_name.data(), m_name.data());
774 if (!player_ptr->effects()->hallucination()->is_hallucinated()) {
775 monster_race_track(player_ptr, m_ptr->ap_r_idx);
778 health_track(player_ptr, c_mon_ptr->m_idx);
782 if (snipe_type == SP_NEEDLE) {
783 const auto is_unique = r_ptr->kind_flags.has(MonsterKindType::UNIQUE);
784 const auto fatality = randint1(r_ptr->level / (3 + sniper_concent)) + (8 - sniper_concent);
785 if ((randint1(fatality) == 1) && !is_unique && none_bits(r_ptr->flags7, RF7_UNIQUE2)) {
786 /* Get "the monster" or "it" */
787 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
789 tdam = m_ptr->hp + 1;
791 msg_format(_("%sの急所に突き刺さった!", "Your shot hit a fatal spot of %s!"), m_name.data());
798 attribute_flags = shot_attribute(player_ptr, j_ptr, q_ptr, snipe_type);
799 /* Apply special damage */
800 tdam = calc_shot_damage_with_slay(player_ptr, j_ptr, q_ptr, tdam, m_ptr, snipe_type);
801 tdam = critical_shot(player_ptr, q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
803 /* No negative damage */
808 /* Modify the damage */
810 tdam = mon_damage_mod(player_ptr, m_ptr, tdam, false);
813 msg_format_wizard(player_ptr, CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"), tdam,
814 m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
817 if (snipe_type == SP_EXPLODE) {
818 uint16_t flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
820 sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
821 project(player_ptr, 0, ((sniper_concent + 1) / 2 + 1), ny, nx, base_dam, AttributeType::MISSILE, flg);
826 if (snipe_type == SP_HOLYNESS) {
827 set_bits(floor_ptr->grid_array[ny][nx].info, CAVE_GLOW);
828 note_spot(player_ptr, ny, nx);
829 lite_spot(player_ptr, ny, nx);
832 /* Hit the monster, check for death */
833 MonsterDamageProcessor mdp(player_ptr, c_mon_ptr->m_idx, tdam, &fear, attribute_flags);
834 if (mdp.mon_take_hit(m_ptr->get_died_message())) {
841 if (q_ptr->is_fixed_artifact() && (sniper_concent == 0)) {
842 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
845 msg_format(_("%sは%sに突き刺さった!", "%s^ is stuck in %s!"), item_name.data(), m_name.data());
848 if (const auto pain_message = MonsterPainDescriber(player_ptr, c_mon_ptr->m_idx).describe(tdam);
849 !pain_message.empty()) {
850 msg_print(pain_message);
853 /* Anger the monster */
855 anger_monster(player_ptr, m_ptr);
858 if (fear && m_ptr->ml) {
859 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
861 msg_format(_("%s^は恐怖して逃げ出した!", "%s^ flees in terror!"), m_name.data());
864 set_target(m_ptr, player_ptr->y, player_ptr->x);
867 if (snipe_type == SP_RUSH) {
868 int n = randint1(5) + 3;
869 MONSTER_IDX m_idx = c_mon_ptr->m_idx;
871 for (; cur_dis <= tdis;) {
879 /* Calculate the new location (see "project()") */
880 const auto pos_to = mmove2({ ny, nx }, player_ptr->get_position(), { ty, tx });
884 /* Stopped by wilderness boundary */
885 if (!in_bounds2(floor_ptr, ny, nx)) {
889 /* Stopped by walls/doors */
890 if (!player_can_enter(player_ptr, floor_ptr->grid_array[ny][nx].feat, 0)) {
894 /* Stopped by monsters */
895 if (!is_cave_empty_bold(player_ptr, ny, nx)) {
899 floor_ptr->grid_array[ny][nx].m_idx = m_idx;
900 floor_ptr->grid_array[oy][ox].m_idx = 0;
905 update_monster(player_ptr, m_idx, true);
907 if (delay_factor > 0) {
908 lite_spot(player_ptr, ny, nx);
909 lite_spot(player_ptr, oy, ox);
911 term_xtra(TERM_XTRA_DELAY, delay_factor);
924 if (snipe_type == SP_PIERCE && sniper_concent > 0) {
934 /* Chance of breakage (during attacks) */
935 auto j = (hit_body ? breakage_chance(player_ptr, q_ptr, PlayerClass(player_ptr).equals(PlayerClassType::ARCHER), snipe_type) : 0);
938 MONSTER_IDX m_idx = floor_ptr->grid_array[y][x].m_idx;
939 auto *m_ptr = &floor_ptr->m_list[m_idx];
940 OBJECT_IDX o_idx = o_pop(floor_ptr);
943 msg_format(_("%sはどこかへ行った。", "The %s went somewhere."), item_name.data());
944 if (q_ptr->is_fixed_artifact()) {
945 ArtifactsInfo::get_instance().get_artifact(j_ptr->fixed_artifact_idx).is_generated = false;
950 o_ptr = &floor_ptr->o_list[o_idx];
951 o_ptr->copy_from(q_ptr);
954 o_ptr->marked.reset(OmType::TOUCHED);
956 /* Forget location */
957 o_ptr->iy = o_ptr->ix = 0;
959 /* Memorize monster */
960 o_ptr->held_m_idx = m_idx;
963 m_ptr->hold_o_idx_list.add(floor_ptr, o_idx);
964 } else if (cave_has_flag_bold(floor_ptr, y, x, TerrainCharacteristics::PROJECT)) {
965 /* Drop (or break) near that location */
966 (void)drop_near(player_ptr, q_ptr, j, y, x);
968 /* Drop (or break) near that location */
969 (void)drop_near(player_ptr, q_ptr, j, prev_y, prev_x);
972 /* Sniper - Repeat shooting when double shots */
975 /* Sniper - Loose his/her concentration after any shot */
976 reset_concentration(player_ptr, false);
980 * @brief プレイヤーからモンスターへの射撃命中判定
981 * @param chance 基本命中値
982 * @param monster_ptr モンスターの構造体参照ポインタ
983 * @param vis 目標を視界に捕らえているならばTRUEを指定
984 * @param item_name 石川五右衛門専用メッセージ:無効化した矢弾の名前
985 * @return 命中と判定された場合TRUEを返す
986 * @note 最低命中率5%、最大命中率95%
988 bool test_hit_fire(PlayerType *player_ptr, int chance, MonsterEntity *m_ptr, int vis, std::string_view item_name)
992 auto *r_ptr = &m_ptr->get_monrace();
994 /* Percentile dice */
997 auto sniper_data = PlayerClass(player_ptr).get_specific_data<SniperData>();
998 auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1000 /* Snipers with high-concentration reduce instant miss percentage.*/
1001 k += sniper_concent;
1003 /* Hack -- Instant miss or hit */
1011 if (player_ptr->ppersonality == PERSONALITY_LAZY) {
1023 ac = ac * (8 - sniper_concent) / 8;
1025 if (m_ptr->r_idx == MonsterRaceId::GOEMON && !m_ptr->is_asleep()) {
1029 /* Invisible monsters are harder to hit */
1031 chance = (chance + 1) / 2;
1034 /* Power competes against armor */
1035 if (randint0(chance) < (ac * 3 / 4)) {
1036 if (m_ptr->r_idx == MonsterRaceId::GOEMON && !m_ptr->is_asleep()) {
1037 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
1038 msg_format(_("%sは%sを斬り捨てた!", "%s cuts down %s!"), m_name.data(), item_name.data());
1048 * @brief プレイヤーからモンスターへの射撃クリティカル判定
1049 * @param weight 矢弾の重量
1050 * @param plus_ammo 矢弾の命中修正
1051 * @param plus_bow 弓の命中修正
1052 * @param dam 現在算出中のダメージ値
1053 * @return クリティカル修正が入ったダメージ値
1055 int critical_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam)
1057 const auto &item = player_ptr->inventory_list[INVEN_BOW];
1058 const auto bonus = player_ptr->to_h_b + plus_ammo;
1059 const auto tval = item.bi_key.tval();
1060 const auto median_skill_exp = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2;
1061 const auto &weapon_exps = player_ptr->weapon_exp[tval];
1062 constexpr auto bow_magnification = 200;
1063 constexpr auto xbow_magnification = 400;
1065 if (tval == ItemKindType::NONE) {
1066 power = player_ptr->skill_thb + ((weapon_exps[0] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ;
1068 const auto sval = *item.bi_key.sval();
1069 const auto weapon_exp = weapon_exps[sval];
1070 if (player_ptr->tval_ammo == ItemKindType::BOLT) {
1071 power = (player_ptr->skill_thb + (weapon_exp / xbow_magnification + bonus) * BTH_PLUS_ADJ);
1073 power = player_ptr->skill_thb + ((weapon_exp - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ;
1077 PlayerClass pc(player_ptr);
1078 const auto sniper_data = pc.get_specific_data<SniperData>();
1079 const auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1081 /* Snipers can shot more critically with crossbows */
1082 power += ((power * sniper_concent) / 5);
1083 if (pc.equals(PlayerClassType::SNIPER) && (player_ptr->tval_ammo == ItemKindType::BOLT)) {
1087 /* Good bow makes more critical */
1088 power += plus_bow * 8 * (sniper_concent + 5);
1089 if (randint1(10000) > power) {
1093 const auto k = weight * randint1(500);
1095 msg_print(_("手ごたえがあった!", "It was a good hit!"));
1097 } else if (k < 1350) {
1098 msg_print(_("かなりの手ごたえがあった!", "It was a great hit!"));
1101 msg_print(_("会心の一撃だ!", "It was a superb hit!"));
1109 * @brief 射撃時クリティカルによるダメージ期待値修正計算(スナイパーの集中処理と武器経験値) / critical happens at i / 10000
1110 * @param player_ptr プレイヤーへの参照ポインタ
1111 * @param plus_ammo 矢弾のダメージ修正
1112 * @param plus_bow 弓のダメージ修正
1114 * @note 基本ダメージ量と重量はこの部位では計算に加わらない。
1116 int calc_crit_ratio_shot(PlayerType *player_ptr, int plus_ammo, int plus_bow)
1118 auto *j_ptr = &player_ptr->inventory_list[INVEN_BOW];
1120 /* Extract "shot" power */
1121 auto i = player_ptr->to_h_b + plus_ammo;
1122 const auto tval = j_ptr->bi_key.tval();
1123 const auto sval = *j_ptr->bi_key.sval();
1124 if (player_ptr->tval_ammo == ItemKindType::BOLT) {
1125 i = (player_ptr->skill_thb + (player_ptr->weapon_exp[tval][sval] / 400 + i) * BTH_PLUS_ADJ);
1127 i = (player_ptr->skill_thb + ((player_ptr->weapon_exp[tval][sval] - (PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2)) / 200 + i) * BTH_PLUS_ADJ);
1130 PlayerClass pc(player_ptr);
1131 auto sniper_data = pc.get_specific_data<SniperData>();
1132 auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1134 /* Snipers can shot more critically with crossbows */
1135 i += ((i * sniper_concent) / 5);
1136 if (pc.equals(PlayerClassType::SNIPER) && (player_ptr->tval_ammo == ItemKindType::BOLT)) {
1140 /* Good bow makes more critical */
1141 i += plus_bow * 8 * (sniper_concent + 5);
1151 * @brief 射撃時クリティカルによるダメージ期待値修正計算(重量依存部分) / critical happens at i / 10000
1152 * @param weight 武器の重量
1153 * @param plus_ammo 矢弾のダメージ修正
1154 * @param plus_bow 弓のダメージ修正
1155 * @param dam 基本ダメージ量
1158 int calc_expect_crit_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam)
1162 i = calc_crit_ratio_shot(player_ptr, plus_ammo, plus_bow);
1167 crit = std::min(500, 900 / weight);
1168 num += dam * 3 / 2 * crit;
1171 crit = std::min(500, 1350 / weight);
1173 num += dam * 2 * crit;
1178 num += dam * 3 * crit;
1184 num += (10000 - i) * dam;
1191 * @brief 攻撃時クリティカルによるダメージ期待値修正計算(重量と毒針処理) / critical happens at i / 10000
1192 * @param player_ptr プレイヤーへの参照ポインタ
1193 * @param weight 武器の重量
1194 * @param plus 武器のダメージ修正
1196 * @param meichuu 命中値
1197 * @param dokubari 毒針処理か否か
1198 * @param impact 強撃かどうか
1201 int calc_expect_crit(PlayerType *player_ptr, WEIGHT weight, int plus, int dam, int16_t meichuu, bool dokubari, bool impact)
1207 int i = (weight + (meichuu * 3 + plus * 5) + player_ptr->skill_thn);
1212 // 通常ダメージdam、武器重量weightでクリティカルが発生した時のクリティカルダメージ期待値
1213 auto calc_weight_expect_dam = [](int dam, WEIGHT weight) {
1215 for (int d = 1; d <= 650; ++d) {
1217 sum += std::get<0>(apply_critical_norm_damage(k, dam));
1225 for (int d = 1; d <= 650; ++d) {
1226 num += calc_weight_expect_dam(dam, weight + d);
1230 num += calc_weight_expect_dam(dam, weight);
1233 int pow = PlayerClass(player_ptr).equals(PlayerClassType::NINJA) ? 4444 : 5000;
1239 num += (pow - i) * dam;