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 MonsterRaceInfo *race_ptr = &monraces_info[monster_ptr->r_idx];
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)) && race_ptr->kind_flags.has(MonsterKindType::ANIMAL)) {
168 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
169 race_ptr->r_kind_flags.set(MonsterKindType::ANIMAL);
176 if ((flags.has(TR_KILL_ANIMAL)) && race_ptr->kind_flags.has(MonsterKindType::ANIMAL)) {
177 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
178 race_ptr->r_kind_flags.set(MonsterKindType::ANIMAL);
185 if ((flags.has(TR_SLAY_EVIL)) && race_ptr->kind_flags.has(MonsterKindType::EVIL)) {
186 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
187 race_ptr->r_kind_flags.set(MonsterKindType::EVIL);
194 if ((flags.has(TR_KILL_EVIL)) && race_ptr->kind_flags.has(MonsterKindType::EVIL)) {
195 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
196 race_ptr->r_kind_flags.set(MonsterKindType::EVIL);
203 if ((flags.has(TR_SLAY_GOOD)) && race_ptr->kind_flags.has(MonsterKindType::GOOD)) {
204 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
205 race_ptr->r_kind_flags.set(MonsterKindType::GOOD);
212 if ((flags.has(TR_KILL_GOOD)) && race_ptr->kind_flags.has(MonsterKindType::GOOD)) {
213 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
214 race_ptr->r_kind_flags.set(MonsterKindType::GOOD);
221 if ((flags.has(TR_SLAY_HUMAN)) && race_ptr->kind_flags.has(MonsterKindType::HUMAN)) {
222 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
223 race_ptr->r_kind_flags.set(MonsterKindType::HUMAN);
230 if ((flags.has(TR_KILL_HUMAN)) && race_ptr->kind_flags.has(MonsterKindType::HUMAN)) {
231 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
232 race_ptr->r_kind_flags.set(MonsterKindType::HUMAN);
239 if ((flags.has(TR_SLAY_UNDEAD)) && race_ptr->kind_flags.has(MonsterKindType::UNDEAD)) {
240 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
241 race_ptr->r_kind_flags.set(MonsterKindType::UNDEAD);
248 if ((flags.has(TR_KILL_UNDEAD)) && race_ptr->kind_flags.has(MonsterKindType::UNDEAD)) {
249 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
250 race_ptr->r_kind_flags.set(MonsterKindType::UNDEAD);
257 if ((flags.has(TR_SLAY_DEMON)) && race_ptr->kind_flags.has(MonsterKindType::DEMON)) {
258 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
259 race_ptr->r_kind_flags.set(MonsterKindType::DEMON);
266 if ((flags.has(TR_KILL_DEMON)) && race_ptr->kind_flags.has(MonsterKindType::DEMON)) {
267 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
268 race_ptr->r_kind_flags.set(MonsterKindType::DEMON);
275 if ((flags.has(TR_SLAY_ORC)) && race_ptr->kind_flags.has(MonsterKindType::ORC)) {
276 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
277 race_ptr->r_kind_flags.set(MonsterKindType::ORC);
284 if ((flags.has(TR_KILL_ORC)) && race_ptr->kind_flags.has(MonsterKindType::ORC)) {
285 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
286 race_ptr->r_kind_flags.set(MonsterKindType::ORC);
293 if ((flags.has(TR_SLAY_TROLL)) && race_ptr->kind_flags.has(MonsterKindType::TROLL)) {
294 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
295 race_ptr->r_kind_flags.set(MonsterKindType::TROLL);
303 if ((flags.has(TR_KILL_TROLL)) && race_ptr->kind_flags.has(MonsterKindType::TROLL)) {
304 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
305 race_ptr->r_kind_flags.set(MonsterKindType::TROLL);
312 if ((flags.has(TR_SLAY_GIANT)) && race_ptr->kind_flags.has(MonsterKindType::GIANT)) {
313 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
314 race_ptr->r_kind_flags.set(MonsterKindType::GIANT);
321 if ((flags.has(TR_KILL_GIANT)) && race_ptr->kind_flags.has(MonsterKindType::GIANT)) {
322 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
323 race_ptr->r_kind_flags.set(MonsterKindType::GIANT);
330 if ((flags.has(TR_SLAY_DRAGON)) && race_ptr->kind_flags.has(MonsterKindType::DRAGON)) {
331 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
332 race_ptr->r_kind_flags.set(MonsterKindType::DRAGON);
339 if ((flags.has(TR_KILL_DRAGON)) && race_ptr->kind_flags.has(MonsterKindType::DRAGON)) {
340 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
341 race_ptr->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 (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_ACID_MASK)) {
358 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
359 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_ACID_MASK);
368 if (flags.has(TR_BRAND_ELEC)) {
369 /* Notice immunity */
370 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_ELEC_MASK)) {
371 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
372 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_ELEC_MASK);
381 if (flags.has(TR_BRAND_FIRE)) {
382 /* Notice immunity */
383 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_FIRE_MASK)) {
384 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
385 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_FIRE_MASK);
388 /* Otherwise, take the damage */
390 if (race_ptr->resistance_flags.has(MonsterResistanceType::HURT_FIRE)) {
394 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
395 race_ptr->r_resistance_flags.set(MonsterResistanceType::HURT_FIRE);
397 } else if (mult < 17) {
403 if (flags.has(TR_BRAND_COLD)) {
404 /* Notice immunity */
405 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_COLD_MASK)) {
406 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
407 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_COLD_MASK);
410 /* Otherwise, take the damage */
412 if (race_ptr->resistance_flags.has(MonsterResistanceType::HURT_COLD)) {
416 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
417 race_ptr->r_resistance_flags.set(MonsterResistanceType::HURT_COLD);
419 } else if (mult < 17) {
425 if (flags.has(TR_BRAND_POIS)) {
426 /* Notice immunity */
427 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_POISON_MASK)) {
428 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
429 race_ptr->r_resistance_flags.set(race_ptr->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 * Fire an object from the pack or floor.
464 * @param item 射撃するオブジェクトの所持ID
465 * @param bow_ptr 射撃武器のオブジェクト参照ポインタ
468 * You may only fire items that "match" your missile launcher.
469 * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
470 * See "calc_bonuses()" for more calculations and such.
471 * Note that "firing" a missile is MUCH better than "throwing" it.
472 * Note: "unseen" monsters are very hard to hit.
473 * Objects are more likely to break if they "attempt" to hit a monster.
474 * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
475 * The "extra shot" code works by decreasing the amount of energy
476 * required to make each shot, spreading the shots out over time.
477 * Note that when firing missiles, the launcher multiplier is applied
478 * after all the bonuses are added in, making multipliers very useful.
479 * Note that Bows of "Extra Might" get extra range and an extra bonus
480 * for the damage multiplier.
481 * Note that Bows of "Extra Shots" give an extra shot.
484 void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPELL_IDX snipe_type)
486 POSITION y, x, ny, nx, ty, tx, prev_y, prev_x;
491 AttributeFlags attribute_flags{};
492 attribute_flags.set(AttributeType::PLAYER_SHOOT);
494 auto hit_body = false;
495 auto stick_to = false;
497 /* Access the item (if in the pack) */
498 auto *floor_ptr = player_ptr->current_floor_ptr;
500 o_ptr = &player_ptr->inventory_list[item];
502 o_ptr = &floor_ptr->o_list[0 - item];
505 /* Sniper - Cannot shot a single arrow twice */
506 if ((snipe_type == SP_DOUBLE) && (o_ptr->number < 2)) {
507 snipe_type = SP_NONE;
510 const auto item_name = describe_flavor(player_ptr, o_ptr, OD_OMIT_PREFIX);
512 /* Use the proper number of shots */
513 auto thits = player_ptr->num_fire;
515 /* Use a base distance */
518 /* Base damage from thrown object plus launcher bonus */
519 auto tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
521 /* Actually "fire" the object */
522 const auto tval = j_ptr->bi_key.tval();
523 const auto median_skill_exp = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2;
524 const auto bonus = (player_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
525 const auto &weapon_exps = player_ptr->weapon_exp[tval];
526 constexpr auto bow_magnification = 200;
527 constexpr auto xbow_magnification = 400;
529 if (tval == ItemKindType::NONE) {
530 chance = (player_ptr->skill_thb + ((weapon_exps[0] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ);
532 const auto sval = j_ptr->bi_key.sval().value();
533 if (j_ptr->is_cross_bow()) {
534 chance = (player_ptr->skill_thb + (weapon_exps[sval] / xbow_magnification + bonus) * BTH_PLUS_ADJ);
536 chance = (player_ptr->skill_thb + ((weapon_exps[sval] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ);
540 PlayerEnergy(player_ptr).set_player_turn_energy(j_ptr->get_bow_energy());
541 auto tmul = j_ptr->get_arrow_magnification();
543 /* Get extra "power" from "extra might" */
544 if (player_ptr->xtra_might) {
548 tmul = tmul * (100 + (int)(adj_str_td[player_ptr->stat_index[A_STR]]) - 128);
550 /* Boost the damage */
554 auto sniper_data = PlayerClass(player_ptr).get_specific_data<SniperData>();
555 auto sniper_concent = sniper_data ? sniper_data->concent : 0;
558 tdis = 13 + tmul / 80;
559 if (j_ptr->is_cross_bow()) {
560 tdis -= (5 - (sniper_concent + 1) / 2);
563 project_length = tdis + 1;
565 /* Get a direction (or cancel) */
567 if (!get_aim_dir(player_ptr, &dir)) {
568 PlayerEnergy(player_ptr).reset_player_turn();
570 if (snipe_type == SP_AWAY) {
571 snipe_type = SP_NONE;
574 /* need not to reset project_length (already did)*/
579 if (snipe_type != SP_NONE) {
583 /* Predict the "target" location */
584 tx = player_ptr->x + 99 * ddx[dir];
585 ty = player_ptr->y + 99 * ddy[dir];
587 /* Check for "target request" */
588 if ((dir == 5) && target_okay(player_ptr)) {
593 /* Get projection path length */
594 projection_path path_g(player_ptr, project_length, player_ptr->y, player_ptr->x, ty, tx, PROJECT_PATH | PROJECT_THRU);
595 tdis = path_g.path_num() - 1;
597 project_length = 0; /* reset to default */
599 /* Don't shoot at my feet */
600 if (tx == player_ptr->x && ty == player_ptr->y) {
601 PlayerEnergy(player_ptr).reset_player_turn();
603 /* project_length is already reset to 0 */
608 /* Take a (partial) turn */
609 PlayerEnergy(player_ptr).div_player_turn_energy(thits);
610 player_ptr->is_fired = true;
612 /* Sniper - Difficult to shot twice at 1 turn */
613 if (snipe_type == SP_DOUBLE) {
614 sniper_concent = (sniper_concent + 1) / 2;
617 /* Sniper - Repeat shooting when double shots */
618 for (auto i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++) {
619 /* Start at the player */
623 q_ptr->copy_from(o_ptr);
628 vary_item(player_ptr, item, -1);
631 handle_stuff(player_ptr);
636 /* The shot does not hit yet */
639 /* Travel until stopped */
640 for (auto cur_dis = 0; cur_dis <= tdis;) {
643 /* Hack -- Stop at the target */
644 if ((y == ty) && (x == tx)) {
648 /* Calculate the new location (see "project()") */
651 mmove2(&ny, &nx, player_ptr->y, player_ptr->x, ty, tx);
654 if (snipe_type == SP_KILL_WALL) {
655 g_ptr = &floor_ptr->grid_array[ny][nx];
657 if (g_ptr->cave_has_flag(TerrainCharacteristics::HURT_ROCK) && !g_ptr->m_idx) {
658 if (any_bits(g_ptr->info, (CAVE_MARK))) {
659 msg_print(_("岩が砕け散った。", "Wall rocks were shattered."));
661 /* Forget the wall */
662 reset_bits(g_ptr->info, (CAVE_MARK));
663 static constexpr auto flags = {
664 StatusRecalculatingFlag::VIEW,
665 StatusRecalculatingFlag::LITE,
666 StatusRecalculatingFlag::FLOW,
667 StatusRecalculatingFlag::MONSTER_LITE,
669 RedrawingFlagsUpdater::get_instance().set_flags(flags);
671 /* Destroy the wall */
672 cave_alter_feat(player_ptr, ny, nx, TerrainCharacteristics::HURT_ROCK);
679 /* Stopped by walls/doors */
680 if (!cave_has_flag_bold(floor_ptr, ny, nx, TerrainCharacteristics::PROJECT) && !floor_ptr->grid_array[ny][nx].m_idx) {
684 /* Advance the distance */
688 if (snipe_type == SP_LITE) {
689 set_bits(floor_ptr->grid_array[ny][nx].info, CAVE_GLOW);
690 note_spot(player_ptr, ny, nx);
691 lite_spot(player_ptr, ny, nx);
694 /* The player can see the (on screen) missile */
695 if (panel_contains(ny, nx) && player_can_see_bold(player_ptr, ny, nx)) {
696 const auto a = q_ptr->get_color();
697 const auto c = q_ptr->get_symbol();
699 /* Draw, Hilite, Fresh, Pause, Erase */
700 if (delay_factor > 0) {
701 print_rel(player_ptr, c, a, ny, nx);
702 move_cursor_relative(ny, nx);
704 term_xtra(TERM_XTRA_DELAY, delay_factor);
705 lite_spot(player_ptr, ny, nx);
710 /* The player cannot see the missile */
712 /* Pause anyway, for consistancy **/
713 if (delay_factor > 0) {
714 term_xtra(TERM_XTRA_DELAY, delay_factor);
719 if (snipe_type == SP_KILL_TRAP) {
720 constexpr auto flags = PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM;
721 project(player_ptr, 0, 0, ny, nx, 0, AttributeType::KILL_TRAP, flags);
725 if (snipe_type == SP_EVILNESS) {
726 reset_bits(floor_ptr->grid_array[ny][nx].info, (CAVE_GLOW | CAVE_MARK));
727 note_spot(player_ptr, ny, nx);
728 lite_spot(player_ptr, ny, nx);
734 /* Save the new location */
738 /* Monster here, Try to hit it */
739 if (floor_ptr->grid_array[y][x].m_idx) {
740 sound(SOUND_SHOOT_HIT);
741 grid_type *c_mon_ptr = &floor_ptr->grid_array[y][x];
743 auto *m_ptr = &floor_ptr->m_list[c_mon_ptr->m_idx];
744 auto *r_ptr = &monraces_info[m_ptr->r_idx];
746 /* Check the visibility */
747 auto visible = m_ptr->ml;
749 /* Note the collision */
752 if (m_ptr->is_asleep()) {
753 if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5)) {
754 chg_virtue(player_ptr, Virtue::COMPASSION, -1);
756 if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5)) {
757 chg_virtue(player_ptr, Virtue::HONOUR, -1);
761 if ((r_ptr->level + 10) > player_ptr->lev) {
762 PlayerSkill(player_ptr).gain_range_weapon_exp(j_ptr);
765 if (player_ptr->riding) {
766 PlayerSkill(player_ptr).gain_riding_skill_exp_on_range_attack();
769 /* Did we hit it (penalize range) */
770 if (test_hit_fire(player_ptr, chance - cur_dis, m_ptr, m_ptr->ml, item_name.data())) {
772 auto tdam = tdam_base; //!< @note 実際に与えるダメージ
773 auto base_dam = tdam; //!< @note 補正前の与えるダメージ(無傷、全ての耐性など)
775 /* Get extra damage from concentration */
776 tdam = boost_concentration_damage(player_ptr, tdam);
778 /* Handle unseen monster */
780 /* Invisible monster */
781 msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), item_name.data());
784 /* Handle visible monster */
786 /* Get "the monster" or "it" */
787 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
789 msg_format(_("%sが%sに命中した。", "The %s hits %s."), item_name.data(), m_name.data());
792 if (!player_ptr->effects()->hallucination()->is_hallucinated()) {
793 monster_race_track(player_ptr, m_ptr->ap_r_idx);
796 health_track(player_ptr, c_mon_ptr->m_idx);
800 if (snipe_type == SP_NEEDLE) {
801 const auto is_unique = r_ptr->kind_flags.has(MonsterKindType::UNIQUE);
802 const auto fatality = randint1(r_ptr->level / (3 + sniper_concent)) + (8 - sniper_concent);
803 if ((randint1(fatality) == 1) && !is_unique && none_bits(r_ptr->flags7, RF7_UNIQUE2)) {
804 /* Get "the monster" or "it" */
805 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
807 tdam = m_ptr->hp + 1;
809 msg_format(_("%sの急所に突き刺さった!", "Your shot hit a fatal spot of %s!"), m_name.data());
816 attribute_flags = shot_attribute(player_ptr, j_ptr, q_ptr, snipe_type);
817 /* Apply special damage */
818 tdam = calc_shot_damage_with_slay(player_ptr, j_ptr, q_ptr, tdam, m_ptr, snipe_type);
819 tdam = critical_shot(player_ptr, q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
821 /* No negative damage */
826 /* Modify the damage */
828 tdam = mon_damage_mod(player_ptr, m_ptr, tdam, false);
831 msg_format_wizard(player_ptr, CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"), tdam,
832 m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
835 if (snipe_type == SP_EXPLODE) {
836 uint16_t flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
838 sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
839 project(player_ptr, 0, ((sniper_concent + 1) / 2 + 1), ny, nx, base_dam, AttributeType::MISSILE, flg);
844 if (snipe_type == SP_HOLYNESS) {
845 set_bits(floor_ptr->grid_array[ny][nx].info, CAVE_GLOW);
846 note_spot(player_ptr, ny, nx);
847 lite_spot(player_ptr, ny, nx);
850 /* Hit the monster, check for death */
851 MonsterDamageProcessor mdp(player_ptr, c_mon_ptr->m_idx, tdam, &fear, attribute_flags);
852 if (mdp.mon_take_hit(m_ptr->get_died_message())) {
859 if (q_ptr->is_fixed_artifact() && (sniper_concent == 0)) {
860 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
863 msg_format(_("%sは%sに突き刺さった!", "%s^ is stuck in %s!"), item_name.data(), m_name.data());
866 if (const auto pain_message = MonsterPainDescriber(player_ptr, c_mon_ptr->m_idx).describe(tdam);
867 !pain_message.empty()) {
868 msg_print(pain_message);
871 /* Anger the monster */
873 anger_monster(player_ptr, m_ptr);
876 if (fear && m_ptr->ml) {
877 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
879 msg_format(_("%s^は恐怖して逃げ出した!", "%s^ flees in terror!"), m_name.data());
882 set_target(m_ptr, player_ptr->y, player_ptr->x);
885 if (snipe_type == SP_RUSH) {
886 int n = randint1(5) + 3;
887 MONSTER_IDX m_idx = c_mon_ptr->m_idx;
889 for (; cur_dis <= tdis;) {
897 /* Calculate the new location (see "project()") */
898 mmove2(&ny, &nx, player_ptr->y, player_ptr->x, ty, tx);
900 /* Stopped by wilderness boundary */
901 if (!in_bounds2(floor_ptr, ny, nx)) {
905 /* Stopped by walls/doors */
906 if (!player_can_enter(player_ptr, floor_ptr->grid_array[ny][nx].feat, 0)) {
910 /* Stopped by monsters */
911 if (!is_cave_empty_bold(player_ptr, ny, nx)) {
915 floor_ptr->grid_array[ny][nx].m_idx = m_idx;
916 floor_ptr->grid_array[oy][ox].m_idx = 0;
921 update_monster(player_ptr, m_idx, true);
923 if (delay_factor > 0) {
924 lite_spot(player_ptr, ny, nx);
925 lite_spot(player_ptr, oy, ox);
927 term_xtra(TERM_XTRA_DELAY, delay_factor);
940 if (snipe_type == SP_PIERCE && sniper_concent > 0) {
950 /* Chance of breakage (during attacks) */
951 auto j = (hit_body ? breakage_chance(player_ptr, q_ptr, PlayerClass(player_ptr).equals(PlayerClassType::ARCHER), snipe_type) : 0);
954 MONSTER_IDX m_idx = floor_ptr->grid_array[y][x].m_idx;
955 auto *m_ptr = &floor_ptr->m_list[m_idx];
956 OBJECT_IDX o_idx = o_pop(floor_ptr);
959 msg_format(_("%sはどこかへ行った。", "The %s went somewhere."), item_name.data());
960 if (q_ptr->is_fixed_artifact()) {
961 ArtifactsInfo::get_instance().get_artifact(j_ptr->fixed_artifact_idx).is_generated = false;
966 o_ptr = &floor_ptr->o_list[o_idx];
967 o_ptr->copy_from(q_ptr);
970 o_ptr->marked.reset(OmType::TOUCHED);
972 /* Forget location */
973 o_ptr->iy = o_ptr->ix = 0;
975 /* Memorize monster */
976 o_ptr->held_m_idx = m_idx;
979 m_ptr->hold_o_idx_list.add(floor_ptr, o_idx);
980 } else if (cave_has_flag_bold(floor_ptr, y, x, TerrainCharacteristics::PROJECT)) {
981 /* Drop (or break) near that location */
982 (void)drop_near(player_ptr, q_ptr, j, y, x);
984 /* Drop (or break) near that location */
985 (void)drop_near(player_ptr, q_ptr, j, prev_y, prev_x);
988 /* Sniper - Repeat shooting when double shots */
991 /* Sniper - Loose his/her concentration after any shot */
992 reset_concentration(player_ptr, false);
996 * @brief プレイヤーからモンスターへの射撃命中判定
997 * @param chance 基本命中値
998 * @param monster_ptr モンスターの構造体参照ポインタ
999 * @param vis 目標を視界に捕らえているならばTRUEを指定
1000 * @param item_name 石川五右衛門専用メッセージ:無効化した矢弾の名前
1001 * @return 命中と判定された場合TRUEを返す
1002 * @note 最低命中率5%、最大命中率95%
1004 bool test_hit_fire(PlayerType *player_ptr, int chance, MonsterEntity *m_ptr, int vis, std::string_view item_name)
1008 auto *r_ptr = &monraces_info[m_ptr->r_idx];
1010 /* Percentile dice */
1013 auto sniper_data = PlayerClass(player_ptr).get_specific_data<SniperData>();
1014 auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1016 /* Snipers with high-concentration reduce instant miss percentage.*/
1017 k += sniper_concent;
1019 /* Hack -- Instant miss or hit */
1027 if (player_ptr->ppersonality == PERSONALITY_LAZY) {
1039 ac = ac * (8 - sniper_concent) / 8;
1041 if (m_ptr->r_idx == MonsterRaceId::GOEMON && !m_ptr->is_asleep()) {
1045 /* Invisible monsters are harder to hit */
1047 chance = (chance + 1) / 2;
1050 /* Power competes against armor */
1051 if (randint0(chance) < (ac * 3 / 4)) {
1052 if (m_ptr->r_idx == MonsterRaceId::GOEMON && !m_ptr->is_asleep()) {
1053 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
1054 msg_format(_("%sは%sを斬り捨てた!", "%s cuts down %s!"), m_name.data(), item_name.data());
1064 * @brief プレイヤーからモンスターへの射撃クリティカル判定
1065 * @param weight 矢弾の重量
1066 * @param plus_ammo 矢弾の命中修正
1067 * @param plus_bow 弓の命中修正
1068 * @param dam 現在算出中のダメージ値
1069 * @return クリティカル修正が入ったダメージ値
1071 int critical_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam)
1073 const auto &item = player_ptr->inventory_list[INVEN_BOW];
1074 const auto bonus = player_ptr->to_h_b + plus_ammo;
1075 const auto tval = item.bi_key.tval();
1076 const auto median_skill_exp = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2;
1077 const auto &weapon_exps = player_ptr->weapon_exp[tval];
1078 constexpr auto bow_magnification = 200;
1079 constexpr auto xbow_magnification = 400;
1081 if (tval == ItemKindType::NONE) {
1082 power = player_ptr->skill_thb + ((weapon_exps[0] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ;
1084 const auto sval = item.bi_key.sval().value();
1085 const auto weapon_exp = weapon_exps[sval];
1086 if (player_ptr->tval_ammo == ItemKindType::BOLT) {
1087 power = (player_ptr->skill_thb + (weapon_exp / xbow_magnification + bonus) * BTH_PLUS_ADJ);
1089 power = player_ptr->skill_thb + ((weapon_exp - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ;
1093 PlayerClass pc(player_ptr);
1094 const auto sniper_data = pc.get_specific_data<SniperData>();
1095 const auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1097 /* Snipers can shot more critically with crossbows */
1098 power += ((power * sniper_concent) / 5);
1099 if (pc.equals(PlayerClassType::SNIPER) && (player_ptr->tval_ammo == ItemKindType::BOLT)) {
1103 /* Good bow makes more critical */
1104 power += plus_bow * 8 * (sniper_concent + 5);
1105 if (randint1(10000) > power) {
1109 const auto k = weight * randint1(500);
1111 msg_print(_("手ごたえがあった!", "It was a good hit!"));
1113 } else if (k < 1350) {
1114 msg_print(_("かなりの手ごたえがあった!", "It was a great hit!"));
1117 msg_print(_("会心の一撃だ!", "It was a superb hit!"));
1125 * @brief 射撃時クリティカルによるダメージ期待値修正計算(スナイパーの集中処理と武器経験値) / critical happens at i / 10000
1126 * @param player_ptr プレイヤーへの参照ポインタ
1127 * @param plus_ammo 矢弾のダメージ修正
1128 * @param plus_bow 弓のダメージ修正
1130 * @note 基本ダメージ量と重量はこの部位では計算に加わらない。
1132 int calc_crit_ratio_shot(PlayerType *player_ptr, int plus_ammo, int plus_bow)
1134 auto *j_ptr = &player_ptr->inventory_list[INVEN_BOW];
1136 /* Extract "shot" power */
1137 auto i = player_ptr->to_h_b + plus_ammo;
1138 const auto tval = j_ptr->bi_key.tval();
1139 const auto sval = j_ptr->bi_key.sval().value();
1140 if (player_ptr->tval_ammo == ItemKindType::BOLT) {
1141 i = (player_ptr->skill_thb + (player_ptr->weapon_exp[tval][sval] / 400 + i) * BTH_PLUS_ADJ);
1143 i = (player_ptr->skill_thb + ((player_ptr->weapon_exp[tval][sval] - (PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2)) / 200 + i) * BTH_PLUS_ADJ);
1146 PlayerClass pc(player_ptr);
1147 auto sniper_data = pc.get_specific_data<SniperData>();
1148 auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1150 /* Snipers can shot more critically with crossbows */
1151 i += ((i * sniper_concent) / 5);
1152 if (pc.equals(PlayerClassType::SNIPER) && (player_ptr->tval_ammo == ItemKindType::BOLT)) {
1156 /* Good bow makes more critical */
1157 i += plus_bow * 8 * (sniper_concent + 5);
1167 * @brief 射撃時クリティカルによるダメージ期待値修正計算(重量依存部分) / critical happens at i / 10000
1168 * @param weight 武器の重量
1169 * @param plus_ammo 矢弾のダメージ修正
1170 * @param plus_bow 弓のダメージ修正
1171 * @param dam 基本ダメージ量
1174 int calc_expect_crit_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam)
1178 i = calc_crit_ratio_shot(player_ptr, plus_ammo, plus_bow);
1183 crit = std::min(500, 900 / weight);
1184 num += dam * 3 / 2 * crit;
1187 crit = std::min(500, 1350 / weight);
1189 num += dam * 2 * crit;
1194 num += dam * 3 * crit;
1200 num += (10000 - i) * dam;
1207 * @brief 攻撃時クリティカルによるダメージ期待値修正計算(重量と毒針処理) / critical happens at i / 10000
1208 * @param player_ptr プレイヤーへの参照ポインタ
1209 * @param weight 武器の重量
1210 * @param plus 武器のダメージ修正
1212 * @param meichuu 命中値
1213 * @param dokubari 毒針処理か否か
1214 * @param impact 強撃かどうか
1217 int calc_expect_crit(PlayerType *player_ptr, WEIGHT weight, int plus, int dam, int16_t meichuu, bool dokubari, bool impact)
1223 int i = (weight + (meichuu * 3 + plus * 5) + player_ptr->skill_thn);
1228 // 通常ダメージdam、武器重量weightでクリティカルが発生した時のクリティカルダメージ期待値
1229 auto calc_weight_expect_dam = [](int dam, WEIGHT weight) {
1231 for (int d = 1; d <= 650; ++d) {
1233 sum += std::get<0>(apply_critical_norm_damage(k, dam));
1241 for (int d = 1; d <= 650; ++d) {
1242 num += calc_weight_expect_dam(dam, weight + d);
1246 num += calc_weight_expect_dam(dam, weight);
1249 int pow = PlayerClass(player_ptr).equals(PlayerClassType::NINJA) ? 4444 : 5000;
1255 num += (pow - i) * dam;