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/attribute-types.h"
9 #include "effect/effect-characteristics.h"
10 #include "effect/effect-processor.h"
11 #include "effect/spells-effect-util.h"
12 #include "flavor/flavor-describer.h"
13 #include "flavor/object-flavor-types.h"
14 #include "floor/cave.h"
15 #include "floor/floor-object.h"
16 #include "floor/geometry.h"
17 #include "game-option/cheat-types.h"
18 #include "game-option/special-options.h"
19 #include "grid/feature-flag-types.h"
20 #include "grid/feature.h"
21 #include "grid/grid.h"
22 #include "inventory/inventory-object.h"
23 #include "inventory/inventory-slot-types.h"
24 #include "io/cursor.h"
25 #include "io/screen-util.h"
26 #include "main/sound-definitions-table.h"
27 #include "main/sound-of-music.h"
28 #include "mind/mind-sniper.h"
29 #include "mind/snipe-types.h"
30 #include "monster-floor/monster-death.h"
31 #include "monster-floor/monster-move.h"
32 #include "monster-race/monster-race.h"
33 #include "monster-race/race-flags-resistance.h"
34 #include "monster-race/race-flags1.h"
35 #include "monster-race/race-flags2.h"
36 #include "monster-race/race-flags3.h"
37 #include "monster-race/race-flags7.h"
38 #include "monster-race/race-indice-types.h"
39 #include "monster-race/race-resistance-mask.h"
40 #include "monster/monster-damage.h"
41 #include "monster/monster-describer.h"
42 #include "monster/monster-info.h"
43 #include "monster/monster-pain-describer.h"
44 #include "monster/monster-status-setter.h"
45 #include "monster/monster-status.h"
46 #include "monster/monster-update.h"
47 #include "object/object-broken.h"
48 #include "object/object-flags.h"
49 #include "object/object-info.h"
50 #include "object/object-mark-types.h"
51 #include "player-base/player-class.h"
52 #include "player-info/class-info.h"
53 #include "player-info/sniper-data-type.h"
54 #include "player-status/player-energy.h"
55 #include "player/player-personality-types.h"
56 #include "player/player-skill.h"
57 #include "player/player-status-table.h"
58 #include "sv-definition/sv-bow-types.h"
59 #include "system/artifact-type-definition.h"
60 #include "system/baseitem-info.h"
61 #include "system/floor-type-definition.h"
62 #include "system/grid-type-definition.h"
63 #include "system/item-entity.h"
64 #include "system/monster-entity.h"
65 #include "system/monster-race-info.h"
66 #include "system/player-type-definition.h"
67 #include "system/redrawing-flags-updater.h"
68 #include "target/projection-path-calculator.h"
69 #include "target/target-checker.h"
70 #include "target/target-getter.h"
71 #include "timed-effect/player-hallucination.h"
72 #include "timed-effect/timed-effects.h"
73 #include "util/bit-flags-calculator.h"
74 #include "view/display-messages.h"
75 #include "wizard/wizard-messages.h"
76 #include "world/world-object.h"
80 * @param bow_ptr 弓のオブジェクト構造体参照ポインタ
81 * @param arrow_ptr 矢弾のオブジェクト構造体参照ポインタ
82 * @return スナイパーの射撃属性、弓矢の属性を考慮する。デフォルトはGF_PLAYER_SHOOT。
84 AttributeFlags shot_attribute(PlayerType *player_ptr, ItemEntity *bow_ptr, ItemEntity *arrow_ptr, SPELL_IDX snipe_type)
86 AttributeFlags attribute_flags{};
87 attribute_flags.set(AttributeType::PLAYER_SHOOT);
90 auto arrow_flags = object_flags(arrow_ptr);
91 auto bow_flags = object_flags(bow_ptr);
93 flags = bow_flags | arrow_flags;
95 static const struct snipe_convert_table_t {
97 AttributeType attribute;
98 } snipe_convert_table[] = {
99 { SP_LITE, AttributeType::LITE },
100 { SP_FIRE, AttributeType::FIRE },
101 { SP_COLD, AttributeType::COLD },
102 { SP_ELEC, AttributeType::ELEC },
103 { SP_KILL_WALL, AttributeType::KILL_WALL },
104 { SP_EVILNESS, AttributeType::HELL_FIRE },
105 { SP_HOLYNESS, AttributeType::HOLY_FIRE },
106 { SP_FINAL, AttributeType::MANA },
109 static const struct brand_convert_table_t {
111 AttributeType attribute;
112 } brand_convert_table[] = {
113 { TR_BRAND_ACID, AttributeType::ACID },
114 { TR_BRAND_FIRE, AttributeType::FIRE },
115 { TR_BRAND_ELEC, AttributeType::ELEC },
116 { TR_BRAND_COLD, AttributeType::COLD },
117 { TR_BRAND_POIS, AttributeType::POIS },
118 { TR_SLAY_GOOD, AttributeType::HELL_FIRE },
119 { TR_KILL_GOOD, AttributeType::HELL_FIRE },
120 { TR_SLAY_EVIL, AttributeType::HOLY_FIRE },
121 { TR_KILL_EVIL, AttributeType::HOLY_FIRE },
124 for (size_t i = 0; i < sizeof(snipe_convert_table) / sizeof(snipe_convert_table[0]); ++i) {
125 const struct snipe_convert_table_t *p = &snipe_convert_table[i];
127 if (snipe_type == p->snipe_type) {
128 attribute_flags.set(p->attribute);
132 for (size_t i = 0; i < sizeof(brand_convert_table) / sizeof(brand_convert_table[0]); ++i) {
133 const struct brand_convert_table_t *p = &brand_convert_table[i];
135 if (flags.has(p->brand_type)) {
136 attribute_flags.set(p->attribute);
140 if ((flags.has(TR_FORCE_WEAPON)) && (player_ptr->csp > (player_ptr->msp / 30))) {
141 attribute_flags.set(AttributeType::MANA);
144 return attribute_flags;
148 * @brief 矢弾を射撃した際のスレイ倍率をかけた結果を返す /
149 * Determines the odds of an object breaking when thrown at a monster
150 * @param bow_ptr 弓のオブジェクト構造体参照ポインタ
151 * @param arrow_ptr 矢弾のオブジェクト構造体参照ポインタ
152 * @param tdam 計算途中のダメージ量
153 * @param monster_ptr 目標モンスターの構造体参照ポインタ
154 * @return スレイ倍率をかけたダメージ量
156 static MULTIPLY calc_shot_damage_with_slay(
157 PlayerType *player_ptr, ItemEntity *bow_ptr, ItemEntity *arrow_ptr, int tdam, MonsterEntity *monster_ptr, SPELL_IDX snipe_type)
161 MonsterRaceInfo *race_ptr = &monraces_info[monster_ptr->r_idx];
164 auto arrow_flags = object_flags(arrow_ptr);
165 auto bow_flags = object_flags(bow_ptr);
167 flags = bow_flags | arrow_flags;
169 /* Some "weapons" and "ammo" do extra damage */
170 switch (arrow_ptr->bi_key.tval()) {
171 case ItemKindType::SHOT:
172 case ItemKindType::ARROW:
173 case ItemKindType::BOLT: {
174 if ((flags.has(TR_SLAY_ANIMAL)) && race_ptr->kind_flags.has(MonsterKindType::ANIMAL)) {
175 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
176 race_ptr->r_kind_flags.set(MonsterKindType::ANIMAL);
183 if ((flags.has(TR_KILL_ANIMAL)) && race_ptr->kind_flags.has(MonsterKindType::ANIMAL)) {
184 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
185 race_ptr->r_kind_flags.set(MonsterKindType::ANIMAL);
192 if ((flags.has(TR_SLAY_EVIL)) && race_ptr->kind_flags.has(MonsterKindType::EVIL)) {
193 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
194 race_ptr->r_kind_flags.set(MonsterKindType::EVIL);
201 if ((flags.has(TR_KILL_EVIL)) && race_ptr->kind_flags.has(MonsterKindType::EVIL)) {
202 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
203 race_ptr->r_kind_flags.set(MonsterKindType::EVIL);
210 if ((flags.has(TR_SLAY_GOOD)) && race_ptr->kind_flags.has(MonsterKindType::GOOD)) {
211 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
212 race_ptr->r_kind_flags.set(MonsterKindType::GOOD);
219 if ((flags.has(TR_KILL_GOOD)) && race_ptr->kind_flags.has(MonsterKindType::GOOD)) {
220 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
221 race_ptr->r_kind_flags.set(MonsterKindType::GOOD);
228 if ((flags.has(TR_SLAY_HUMAN)) && race_ptr->kind_flags.has(MonsterKindType::HUMAN)) {
229 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
230 race_ptr->r_kind_flags.set(MonsterKindType::HUMAN);
237 if ((flags.has(TR_KILL_HUMAN)) && race_ptr->kind_flags.has(MonsterKindType::HUMAN)) {
238 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
239 race_ptr->r_kind_flags.set(MonsterKindType::HUMAN);
246 if ((flags.has(TR_SLAY_UNDEAD)) && race_ptr->kind_flags.has(MonsterKindType::UNDEAD)) {
247 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
248 race_ptr->r_kind_flags.set(MonsterKindType::UNDEAD);
255 if ((flags.has(TR_KILL_UNDEAD)) && race_ptr->kind_flags.has(MonsterKindType::UNDEAD)) {
256 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
257 race_ptr->r_kind_flags.set(MonsterKindType::UNDEAD);
264 if ((flags.has(TR_SLAY_DEMON)) && race_ptr->kind_flags.has(MonsterKindType::DEMON)) {
265 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
266 race_ptr->r_kind_flags.set(MonsterKindType::DEMON);
273 if ((flags.has(TR_KILL_DEMON)) && race_ptr->kind_flags.has(MonsterKindType::DEMON)) {
274 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
275 race_ptr->r_kind_flags.set(MonsterKindType::DEMON);
282 if ((flags.has(TR_SLAY_ORC)) && race_ptr->kind_flags.has(MonsterKindType::ORC)) {
283 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
284 race_ptr->r_kind_flags.set(MonsterKindType::ORC);
291 if ((flags.has(TR_KILL_ORC)) && race_ptr->kind_flags.has(MonsterKindType::ORC)) {
292 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
293 race_ptr->r_kind_flags.set(MonsterKindType::ORC);
300 if ((flags.has(TR_SLAY_TROLL)) && race_ptr->kind_flags.has(MonsterKindType::TROLL)) {
301 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
302 race_ptr->r_kind_flags.set(MonsterKindType::TROLL);
310 if ((flags.has(TR_KILL_TROLL)) && race_ptr->kind_flags.has(MonsterKindType::TROLL)) {
311 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
312 race_ptr->r_kind_flags.set(MonsterKindType::TROLL);
319 if ((flags.has(TR_SLAY_GIANT)) && race_ptr->kind_flags.has(MonsterKindType::GIANT)) {
320 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
321 race_ptr->r_kind_flags.set(MonsterKindType::GIANT);
328 if ((flags.has(TR_KILL_GIANT)) && race_ptr->kind_flags.has(MonsterKindType::GIANT)) {
329 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
330 race_ptr->r_kind_flags.set(MonsterKindType::GIANT);
337 if ((flags.has(TR_SLAY_DRAGON)) && race_ptr->kind_flags.has(MonsterKindType::DRAGON)) {
338 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
339 race_ptr->r_kind_flags.set(MonsterKindType::DRAGON);
346 if ((flags.has(TR_KILL_DRAGON)) && race_ptr->kind_flags.has(MonsterKindType::DRAGON)) {
347 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
348 race_ptr->r_kind_flags.set(MonsterKindType::DRAGON);
354 auto can_eliminate_smaug = arrow_ptr->is_specific_artifact(FixedArtifactId::BARD_ARROW);
355 can_eliminate_smaug &= player_ptr->inventory_list[INVEN_BOW].is_specific_artifact(FixedArtifactId::BARD);
356 can_eliminate_smaug &= monster_ptr->r_idx == MonsterRaceId::SMAUG;
357 if (can_eliminate_smaug) {
362 if (flags.has(TR_BRAND_ACID)) {
363 /* Notice immunity */
364 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_ACID_MASK)) {
365 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
366 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_ACID_MASK);
375 if (flags.has(TR_BRAND_ELEC)) {
376 /* Notice immunity */
377 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_ELEC_MASK)) {
378 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
379 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_ELEC_MASK);
388 if (flags.has(TR_BRAND_FIRE)) {
389 /* Notice immunity */
390 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_FIRE_MASK)) {
391 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
392 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_FIRE_MASK);
395 /* Otherwise, take the damage */
397 if (race_ptr->resistance_flags.has(MonsterResistanceType::HURT_FIRE)) {
401 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
402 race_ptr->r_resistance_flags.set(MonsterResistanceType::HURT_FIRE);
404 } else if (mult < 17) {
410 if (flags.has(TR_BRAND_COLD)) {
411 /* Notice immunity */
412 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_COLD_MASK)) {
413 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
414 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_COLD_MASK);
417 /* Otherwise, take the damage */
419 if (race_ptr->resistance_flags.has(MonsterResistanceType::HURT_COLD)) {
423 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
424 race_ptr->r_resistance_flags.set(MonsterResistanceType::HURT_COLD);
426 } else if (mult < 17) {
432 if (flags.has(TR_BRAND_POIS)) {
433 /* Notice immunity */
434 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_POISON_MASK)) {
435 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
436 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_POISON_MASK);
439 /* Otherwise, take the damage */
447 if ((flags.has(TR_FORCE_WEAPON)) && (player_ptr->csp > (player_ptr->msp / 30))) {
448 player_ptr->csp -= (1 + (player_ptr->msp / 30));
449 set_bits(player_ptr->redraw, PR_MP);
461 mult = calc_snipe_damage_with_slay(player_ptr, mult, monster_ptr, snipe_type);
464 /* Return the total damage */
465 return tdam * mult / 10;
470 * Fire an object from the pack or floor.
471 * @param item 射撃するオブジェクトの所持ID
472 * @param bow_ptr 射撃武器のオブジェクト参照ポインタ
475 * You may only fire items that "match" your missile launcher.
476 * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
477 * See "calc_bonuses()" for more calculations and such.
478 * Note that "firing" a missile is MUCH better than "throwing" it.
479 * Note: "unseen" monsters are very hard to hit.
480 * Objects are more likely to break if they "attempt" to hit a monster.
481 * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
482 * The "extra shot" code works by decreasing the amount of energy
483 * required to make each shot, spreading the shots out over time.
484 * Note that when firing missiles, the launcher multiplier is applied
485 * after all the bonuses are added in, making multipliers very useful.
486 * Note that Bows of "Extra Might" get extra range and an extra bonus
487 * for the damage multiplier.
488 * Note that Bows of "Extra Shots" give an extra shot.
491 void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPELL_IDX snipe_type)
493 POSITION y, x, ny, nx, ty, tx, prev_y, prev_x;
498 AttributeFlags attribute_flags{};
499 attribute_flags.set(AttributeType::PLAYER_SHOOT);
501 auto hit_body = false;
502 auto stick_to = false;
504 /* Access the item (if in the pack) */
505 auto *floor_ptr = player_ptr->current_floor_ptr;
507 o_ptr = &player_ptr->inventory_list[item];
509 o_ptr = &floor_ptr->o_list[0 - item];
512 /* Sniper - Cannot shot a single arrow twice */
513 if ((snipe_type == SP_DOUBLE) && (o_ptr->number < 2)) {
514 snipe_type = SP_NONE;
517 const auto item_name = describe_flavor(player_ptr, o_ptr, OD_OMIT_PREFIX);
519 /* Use the proper number of shots */
520 auto thits = player_ptr->num_fire;
522 /* Use a base distance */
525 /* Base damage from thrown object plus launcher bonus */
526 auto tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
528 /* Actually "fire" the object */
529 const auto tval = j_ptr->bi_key.tval();
530 const auto median_skill_exp = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2;
531 const auto bonus = (player_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
532 const auto &weapon_exps = player_ptr->weapon_exp[tval];
533 constexpr auto bow_magnification = 200;
534 constexpr auto xbow_magnification = 400;
536 if (tval == ItemKindType::NONE) {
537 chance = (player_ptr->skill_thb + ((weapon_exps[0] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ);
539 const auto sval = j_ptr->bi_key.sval().value();
540 if (j_ptr->is_cross_bow()) {
541 chance = (player_ptr->skill_thb + (weapon_exps[sval] / xbow_magnification + bonus) * BTH_PLUS_ADJ);
543 chance = (player_ptr->skill_thb + ((weapon_exps[sval] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ);
547 PlayerEnergy(player_ptr).set_player_turn_energy(j_ptr->get_bow_energy());
548 auto tmul = j_ptr->get_arrow_magnification();
550 /* Get extra "power" from "extra might" */
551 if (player_ptr->xtra_might) {
555 tmul = tmul * (100 + (int)(adj_str_td[player_ptr->stat_index[A_STR]]) - 128);
557 /* Boost the damage */
561 auto sniper_data = PlayerClass(player_ptr).get_specific_data<sniper_data_type>();
562 auto sniper_concent = sniper_data ? sniper_data->concent : 0;
565 tdis = 13 + tmul / 80;
566 if (j_ptr->is_cross_bow()) {
567 tdis -= (5 - (sniper_concent + 1) / 2);
570 project_length = tdis + 1;
572 /* Get a direction (or cancel) */
574 if (!get_aim_dir(player_ptr, &dir)) {
575 PlayerEnergy(player_ptr).reset_player_turn();
577 if (snipe_type == SP_AWAY) {
578 snipe_type = SP_NONE;
581 /* need not to reset project_length (already did)*/
586 if (snipe_type != SP_NONE) {
590 /* Predict the "target" location */
591 tx = player_ptr->x + 99 * ddx[dir];
592 ty = player_ptr->y + 99 * ddy[dir];
594 /* Check for "target request" */
595 if ((dir == 5) && target_okay(player_ptr)) {
600 /* Get projection path length */
601 projection_path path_g(player_ptr, project_length, player_ptr->y, player_ptr->x, ty, tx, PROJECT_PATH | PROJECT_THRU);
602 tdis = path_g.path_num() - 1;
604 project_length = 0; /* reset to default */
606 /* Don't shoot at my feet */
607 if (tx == player_ptr->x && ty == player_ptr->y) {
608 PlayerEnergy(player_ptr).reset_player_turn();
610 /* project_length is already reset to 0 */
615 /* Take a (partial) turn */
616 PlayerEnergy(player_ptr).div_player_turn_energy(thits);
617 player_ptr->is_fired = true;
619 /* Sniper - Difficult to shot twice at 1 turn */
620 if (snipe_type == SP_DOUBLE) {
621 sniper_concent = (sniper_concent + 1) / 2;
624 /* Sniper - Repeat shooting when double shots */
625 for (auto i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++) {
626 /* Start at the player */
630 q_ptr->copy_from(o_ptr);
635 vary_item(player_ptr, item, -1);
638 handle_stuff(player_ptr);
643 /* The shot does not hit yet */
646 /* Travel until stopped */
647 for (auto cur_dis = 0; cur_dis <= tdis;) {
650 /* Hack -- Stop at the target */
651 if ((y == ty) && (x == tx)) {
655 /* Calculate the new location (see "project()") */
658 mmove2(&ny, &nx, player_ptr->y, player_ptr->x, ty, tx);
661 if (snipe_type == SP_KILL_WALL) {
662 g_ptr = &floor_ptr->grid_array[ny][nx];
664 if (g_ptr->cave_has_flag(TerrainCharacteristics::HURT_ROCK) && !g_ptr->m_idx) {
665 if (any_bits(g_ptr->info, (CAVE_MARK))) {
666 msg_print(_("岩が砕け散った。", "Wall rocks were shattered."));
668 /* Forget the wall */
669 reset_bits(g_ptr->info, (CAVE_MARK));
671 StatusRedrawingFlag::VIEW,
672 StatusRedrawingFlag::LITE,
673 StatusRedrawingFlag::FLOW,
674 StatusRedrawingFlag::MONSTER_LITE,
676 RedrawingFlagsUpdater::get_instance().set_flags(flags);
678 /* Destroy the wall */
679 cave_alter_feat(player_ptr, ny, nx, TerrainCharacteristics::HURT_ROCK);
686 /* Stopped by walls/doors */
687 if (!cave_has_flag_bold(floor_ptr, ny, nx, TerrainCharacteristics::PROJECT) && !floor_ptr->grid_array[ny][nx].m_idx) {
691 /* Advance the distance */
695 if (snipe_type == SP_LITE) {
696 set_bits(floor_ptr->grid_array[ny][nx].info, CAVE_GLOW);
697 note_spot(player_ptr, ny, nx);
698 lite_spot(player_ptr, ny, nx);
701 /* The player can see the (on screen) missile */
702 if (panel_contains(ny, nx) && player_can_see_bold(player_ptr, ny, nx)) {
703 const auto a = q_ptr->get_color();
704 const auto c = q_ptr->get_symbol();
706 /* Draw, Hilite, Fresh, Pause, Erase */
707 if (delay_factor > 0) {
708 print_rel(player_ptr, c, a, ny, nx);
709 move_cursor_relative(ny, nx);
711 term_xtra(TERM_XTRA_DELAY, delay_factor);
712 lite_spot(player_ptr, ny, nx);
717 /* The player cannot see the missile */
719 /* Pause anyway, for consistancy **/
720 if (delay_factor > 0) {
721 term_xtra(TERM_XTRA_DELAY, delay_factor);
726 if (snipe_type == SP_KILL_TRAP) {
727 constexpr auto flags = PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM;
728 project(player_ptr, 0, 0, ny, nx, 0, AttributeType::KILL_TRAP, flags);
732 if (snipe_type == SP_EVILNESS) {
733 reset_bits(floor_ptr->grid_array[ny][nx].info, (CAVE_GLOW | CAVE_MARK));
734 note_spot(player_ptr, ny, nx);
735 lite_spot(player_ptr, ny, nx);
741 /* Save the new location */
745 /* Monster here, Try to hit it */
746 if (floor_ptr->grid_array[y][x].m_idx) {
747 sound(SOUND_SHOOT_HIT);
748 grid_type *c_mon_ptr = &floor_ptr->grid_array[y][x];
750 auto *m_ptr = &floor_ptr->m_list[c_mon_ptr->m_idx];
751 auto *r_ptr = &monraces_info[m_ptr->r_idx];
753 /* Check the visibility */
754 auto visible = m_ptr->ml;
756 /* Note the collision */
759 if (m_ptr->is_asleep()) {
760 if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5)) {
761 chg_virtue(player_ptr, Virtue::COMPASSION, -1);
763 if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5)) {
764 chg_virtue(player_ptr, Virtue::HONOUR, -1);
768 if ((r_ptr->level + 10) > player_ptr->lev) {
769 PlayerSkill(player_ptr).gain_range_weapon_exp(j_ptr);
772 if (player_ptr->riding) {
773 PlayerSkill(player_ptr).gain_riding_skill_exp_on_range_attack();
776 /* Did we hit it (penalize range) */
777 if (test_hit_fire(player_ptr, chance - cur_dis, m_ptr, m_ptr->ml, item_name.data())) {
779 auto tdam = tdam_base; //!< @note 実際に与えるダメージ
780 auto base_dam = tdam; //!< @note 補正前の与えるダメージ(無傷、全ての耐性など)
782 /* Get extra damage from concentration */
783 tdam = boost_concentration_damage(player_ptr, tdam);
785 /* Handle unseen monster */
787 /* Invisible monster */
788 msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), item_name.data());
791 /* Handle visible monster */
793 /* Get "the monster" or "it" */
794 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
796 msg_format(_("%sが%sに命中した。", "The %s hits %s."), item_name.data(), m_name.data());
799 if (!player_ptr->effects()->hallucination()->is_hallucinated()) {
800 monster_race_track(player_ptr, m_ptr->ap_r_idx);
803 health_track(player_ptr, c_mon_ptr->m_idx);
807 if (snipe_type == SP_NEEDLE) {
808 const auto is_unique = r_ptr->kind_flags.has(MonsterKindType::UNIQUE);
809 const auto fatality = randint1(r_ptr->level / (3 + sniper_concent)) + (8 - sniper_concent);
810 if ((randint1(fatality) == 1) && !is_unique && none_bits(r_ptr->flags7, RF7_UNIQUE2)) {
811 /* Get "the monster" or "it" */
812 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
814 tdam = m_ptr->hp + 1;
816 msg_format(_("%sの急所に突き刺さった!", "Your shot hit a fatal spot of %s!"), m_name.data());
823 attribute_flags = shot_attribute(player_ptr, j_ptr, q_ptr, snipe_type);
824 /* Apply special damage */
825 tdam = calc_shot_damage_with_slay(player_ptr, j_ptr, q_ptr, tdam, m_ptr, snipe_type);
826 tdam = critical_shot(player_ptr, q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
828 /* No negative damage */
833 /* Modify the damage */
835 tdam = mon_damage_mod(player_ptr, m_ptr, tdam, false);
838 msg_format_wizard(player_ptr, CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"), tdam,
839 m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
842 if (snipe_type == SP_EXPLODE) {
843 uint16_t flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
845 sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
846 project(player_ptr, 0, ((sniper_concent + 1) / 2 + 1), ny, nx, base_dam, AttributeType::MISSILE, flg);
851 if (snipe_type == SP_HOLYNESS) {
852 set_bits(floor_ptr->grid_array[ny][nx].info, CAVE_GLOW);
853 note_spot(player_ptr, ny, nx);
854 lite_spot(player_ptr, ny, nx);
857 /* Hit the monster, check for death */
858 MonsterDamageProcessor mdp(player_ptr, c_mon_ptr->m_idx, tdam, &fear, attribute_flags);
859 if (mdp.mon_take_hit(extract_note_dies(m_ptr->get_real_r_idx()))) {
866 if (q_ptr->is_fixed_artifact() && (sniper_concent == 0)) {
867 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
870 msg_format(_("%sは%sに突き刺さった!", "%s^ is stuck in %s!"), item_name.data(), m_name.data());
873 if (const auto pain_message = MonsterPainDescriber(player_ptr, c_mon_ptr->m_idx).describe(tdam);
874 !pain_message.empty()) {
875 msg_print(pain_message);
878 /* Anger the monster */
880 anger_monster(player_ptr, m_ptr);
883 if (fear && m_ptr->ml) {
884 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
886 msg_format(_("%s^は恐怖して逃げ出した!", "%s^ flees in terror!"), m_name.data());
889 set_target(m_ptr, player_ptr->y, player_ptr->x);
892 if (snipe_type == SP_RUSH) {
893 int n = randint1(5) + 3;
894 MONSTER_IDX m_idx = c_mon_ptr->m_idx;
896 for (; cur_dis <= tdis;) {
904 /* Calculate the new location (see "project()") */
905 mmove2(&ny, &nx, player_ptr->y, player_ptr->x, ty, tx);
907 /* Stopped by wilderness boundary */
908 if (!in_bounds2(floor_ptr, ny, nx)) {
912 /* Stopped by walls/doors */
913 if (!player_can_enter(player_ptr, floor_ptr->grid_array[ny][nx].feat, 0)) {
917 /* Stopped by monsters */
918 if (!is_cave_empty_bold(player_ptr, ny, nx)) {
922 floor_ptr->grid_array[ny][nx].m_idx = m_idx;
923 floor_ptr->grid_array[oy][ox].m_idx = 0;
928 update_monster(player_ptr, m_idx, true);
930 if (delay_factor > 0) {
931 lite_spot(player_ptr, ny, nx);
932 lite_spot(player_ptr, oy, ox);
934 term_xtra(TERM_XTRA_DELAY, delay_factor);
947 if (snipe_type == SP_PIERCE && sniper_concent > 0) {
957 /* Chance of breakage (during attacks) */
958 auto j = (hit_body ? breakage_chance(player_ptr, q_ptr, PlayerClass(player_ptr).equals(PlayerClassType::ARCHER), snipe_type) : 0);
961 MONSTER_IDX m_idx = floor_ptr->grid_array[y][x].m_idx;
962 auto *m_ptr = &floor_ptr->m_list[m_idx];
963 OBJECT_IDX o_idx = o_pop(floor_ptr);
966 msg_format(_("%sはどこかへ行った。", "The %s went somewhere."), item_name.data());
967 if (q_ptr->is_fixed_artifact()) {
968 ArtifactsInfo::get_instance().get_artifact(j_ptr->fixed_artifact_idx).is_generated = false;
973 o_ptr = &floor_ptr->o_list[o_idx];
974 o_ptr->copy_from(q_ptr);
977 o_ptr->marked.reset(OmType::TOUCHED);
979 /* Forget location */
980 o_ptr->iy = o_ptr->ix = 0;
982 /* Memorize monster */
983 o_ptr->held_m_idx = m_idx;
986 m_ptr->hold_o_idx_list.add(floor_ptr, o_idx);
987 } else if (cave_has_flag_bold(floor_ptr, y, x, TerrainCharacteristics::PROJECT)) {
988 /* Drop (or break) near that location */
989 (void)drop_near(player_ptr, q_ptr, j, y, x);
991 /* Drop (or break) near that location */
992 (void)drop_near(player_ptr, q_ptr, j, prev_y, prev_x);
995 /* Sniper - Repeat shooting when double shots */
998 /* Sniper - Loose his/her concentration after any shot */
999 reset_concentration(player_ptr, false);
1003 * @brief プレイヤーからモンスターへの射撃命中判定
1004 * @param chance 基本命中値
1005 * @param monster_ptr モンスターの構造体参照ポインタ
1006 * @param vis 目標を視界に捕らえているならばTRUEを指定
1007 * @param item_name 石川五右衛門専用メッセージ:無効化した矢弾の名前
1008 * @return 命中と判定された場合TRUEを返す
1009 * @note 最低命中率5%、最大命中率95%
1011 bool test_hit_fire(PlayerType *player_ptr, int chance, MonsterEntity *m_ptr, int vis, std::string_view item_name)
1015 auto *r_ptr = &monraces_info[m_ptr->r_idx];
1017 /* Percentile dice */
1020 auto sniper_data = PlayerClass(player_ptr).get_specific_data<sniper_data_type>();
1021 auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1023 /* Snipers with high-concentration reduce instant miss percentage.*/
1024 k += sniper_concent;
1026 /* Hack -- Instant miss or hit */
1034 if (player_ptr->ppersonality == PERSONALITY_LAZY) {
1046 ac = ac * (8 - sniper_concent) / 8;
1048 if (m_ptr->r_idx == MonsterRaceId::GOEMON && !m_ptr->is_asleep()) {
1052 /* Invisible monsters are harder to hit */
1054 chance = (chance + 1) / 2;
1057 /* Power competes against armor */
1058 if (randint0(chance) < (ac * 3 / 4)) {
1059 if (m_ptr->r_idx == MonsterRaceId::GOEMON && !m_ptr->is_asleep()) {
1060 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
1061 msg_format(_("%sは%sを斬り捨てた!", "%s cuts down %s!"), m_name.data(), item_name.data());
1071 * @brief プレイヤーからモンスターへの射撃クリティカル判定
1072 * @param weight 矢弾の重量
1073 * @param plus_ammo 矢弾の命中修正
1074 * @param plus_bow 弓の命中修正
1075 * @param dam 現在算出中のダメージ値
1076 * @return クリティカル修正が入ったダメージ値
1078 int critical_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam)
1080 const auto &item = player_ptr->inventory_list[INVEN_BOW];
1081 const auto bonus = player_ptr->to_h_b + plus_ammo;
1082 const auto tval = item.bi_key.tval();
1083 const auto median_skill_exp = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2;
1084 const auto &weapon_exps = player_ptr->weapon_exp[tval];
1085 constexpr auto bow_magnification = 200;
1086 constexpr auto xbow_magnification = 400;
1088 if (tval == ItemKindType::NONE) {
1089 power = player_ptr->skill_thb + ((weapon_exps[0] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ;
1091 const auto sval = item.bi_key.sval().value();
1092 const auto weapon_exp = weapon_exps[sval];
1093 if (player_ptr->tval_ammo == ItemKindType::BOLT) {
1094 power = (player_ptr->skill_thb + (weapon_exp / xbow_magnification + bonus) * BTH_PLUS_ADJ);
1096 power = player_ptr->skill_thb + ((weapon_exp - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ;
1100 PlayerClass pc(player_ptr);
1101 const auto sniper_data = pc.get_specific_data<sniper_data_type>();
1102 const auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1104 /* Snipers can shot more critically with crossbows */
1105 power += ((power * sniper_concent) / 5);
1106 if (pc.equals(PlayerClassType::SNIPER) && (player_ptr->tval_ammo == ItemKindType::BOLT)) {
1110 /* Good bow makes more critical */
1111 power += plus_bow * 8 * (sniper_concent + 5);
1112 if (randint1(10000) > power) {
1116 const auto k = weight * randint1(500);
1118 msg_print(_("手ごたえがあった!", "It was a good hit!"));
1120 } else if (k < 1350) {
1121 msg_print(_("かなりの手ごたえがあった!", "It was a great hit!"));
1124 msg_print(_("会心の一撃だ!", "It was a superb hit!"));
1132 * @brief 射撃時クリティカルによるダメージ期待値修正計算(スナイパーの集中処理と武器経験値) / critical happens at i / 10000
1133 * @param player_ptr プレイヤーへの参照ポインタ
1134 * @param plus_ammo 矢弾のダメージ修正
1135 * @param plus_bow 弓のダメージ修正
1137 * @note 基本ダメージ量と重量はこの部位では計算に加わらない。
1139 int calc_crit_ratio_shot(PlayerType *player_ptr, int plus_ammo, int plus_bow)
1141 auto *j_ptr = &player_ptr->inventory_list[INVEN_BOW];
1143 /* Extract "shot" power */
1144 auto i = player_ptr->to_h_b + plus_ammo;
1145 const auto tval = j_ptr->bi_key.tval();
1146 const auto sval = j_ptr->bi_key.sval().value();
1147 if (player_ptr->tval_ammo == ItemKindType::BOLT) {
1148 i = (player_ptr->skill_thb + (player_ptr->weapon_exp[tval][sval] / 400 + i) * BTH_PLUS_ADJ);
1150 i = (player_ptr->skill_thb + ((player_ptr->weapon_exp[tval][sval] - (PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2)) / 200 + i) * BTH_PLUS_ADJ);
1153 PlayerClass pc(player_ptr);
1154 auto sniper_data = pc.get_specific_data<sniper_data_type>();
1155 auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1157 /* Snipers can shot more critically with crossbows */
1158 i += ((i * sniper_concent) / 5);
1159 if (pc.equals(PlayerClassType::SNIPER) && (player_ptr->tval_ammo == ItemKindType::BOLT)) {
1163 /* Good bow makes more critical */
1164 i += plus_bow * 8 * (sniper_concent + 5);
1174 * @brief 射撃時クリティカルによるダメージ期待値修正計算(重量依存部分) / critical happens at i / 10000
1175 * @param weight 武器の重量
1176 * @param plus_ammo 矢弾のダメージ修正
1177 * @param plus_bow 弓のダメージ修正
1178 * @param dam 基本ダメージ量
1181 int calc_expect_crit_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam)
1185 i = calc_crit_ratio_shot(player_ptr, plus_ammo, plus_bow);
1190 crit = std::min(500, 900 / weight);
1191 num += dam * 3 / 2 * crit;
1194 crit = std::min(500, 1350 / weight);
1196 num += dam * 2 * crit;
1201 num += dam * 3 * crit;
1207 num += (10000 - i) * dam;
1214 * @brief 攻撃時クリティカルによるダメージ期待値修正計算(重量と毒針処理) / critical happens at i / 10000
1215 * @param player_ptr プレイヤーへの参照ポインタ
1216 * @param weight 武器の重量
1217 * @param plus 武器のダメージ修正
1219 * @param meichuu 命中値
1220 * @param dokubari 毒針処理か否か
1221 * @param impact 強撃かどうか
1224 int calc_expect_crit(PlayerType *player_ptr, WEIGHT weight, int plus, int dam, int16_t meichuu, bool dokubari, bool impact)
1230 int i = (weight + (meichuu * 3 + plus * 5) + player_ptr->skill_thn);
1235 // 通常ダメージdam、武器重量weightでクリティカルが発生した時のクリティカルダメージ期待値
1236 auto calc_weight_expect_dam = [](int dam, WEIGHT weight) {
1238 for (int d = 1; d <= 650; ++d) {
1240 sum += std::get<0>(apply_critical_norm_damage(k, dam));
1248 for (int d = 1; d <= 650; ++d) {
1249 num += calc_weight_expect_dam(dam, weight + d);
1253 num += calc_weight_expect_dam(dam, weight);
1256 int pow = PlayerClass(player_ptr).equals(PlayerClassType::NINJA) ? 4444 : 5000;
1262 num += (pow - i) * dam;