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 "target/projection-path-calculator.h"
68 #include "target/target-checker.h"
69 #include "target/target-getter.h"
70 #include "timed-effect/player-hallucination.h"
71 #include "timed-effect/timed-effects.h"
72 #include "util/bit-flags-calculator.h"
73 #include "view/display-messages.h"
74 #include "wizard/wizard-messages.h"
75 #include "world/world-object.h"
79 * @param bow_ptr 弓のオブジェクト構造体参照ポインタ
80 * @param arrow_ptr 矢弾のオブジェクト構造体参照ポインタ
81 * @return スナイパーの射撃属性、弓矢の属性を考慮する。デフォルトはGF_PLAYER_SHOOT。
83 AttributeFlags shot_attribute(PlayerType *player_ptr, ItemEntity *bow_ptr, ItemEntity *arrow_ptr, SPELL_IDX snipe_type)
85 AttributeFlags attribute_flags{};
86 attribute_flags.set(AttributeType::PLAYER_SHOOT);
89 auto arrow_flags = object_flags(arrow_ptr);
90 auto bow_flags = object_flags(bow_ptr);
92 flags = bow_flags | arrow_flags;
94 static const struct snipe_convert_table_t {
96 AttributeType attribute;
97 } snipe_convert_table[] = {
98 { SP_LITE, AttributeType::LITE },
99 { SP_FIRE, AttributeType::FIRE },
100 { SP_COLD, AttributeType::COLD },
101 { SP_ELEC, AttributeType::ELEC },
102 { SP_KILL_WALL, AttributeType::KILL_WALL },
103 { SP_EVILNESS, AttributeType::HELL_FIRE },
104 { SP_HOLYNESS, AttributeType::HOLY_FIRE },
105 { SP_FINAL, AttributeType::MANA },
108 static const struct brand_convert_table_t {
110 AttributeType attribute;
111 } brand_convert_table[] = {
112 { TR_BRAND_ACID, AttributeType::ACID },
113 { TR_BRAND_FIRE, AttributeType::FIRE },
114 { TR_BRAND_ELEC, AttributeType::ELEC },
115 { TR_BRAND_COLD, AttributeType::COLD },
116 { TR_BRAND_POIS, AttributeType::POIS },
117 { TR_SLAY_GOOD, AttributeType::HELL_FIRE },
118 { TR_KILL_GOOD, AttributeType::HELL_FIRE },
119 { TR_SLAY_EVIL, AttributeType::HOLY_FIRE },
120 { TR_KILL_EVIL, AttributeType::HOLY_FIRE },
123 for (size_t i = 0; i < sizeof(snipe_convert_table) / sizeof(snipe_convert_table[0]); ++i) {
124 const struct snipe_convert_table_t *p = &snipe_convert_table[i];
126 if (snipe_type == p->snipe_type) {
127 attribute_flags.set(p->attribute);
131 for (size_t i = 0; i < sizeof(brand_convert_table) / sizeof(brand_convert_table[0]); ++i) {
132 const struct brand_convert_table_t *p = &brand_convert_table[i];
134 if (flags.has(p->brand_type)) {
135 attribute_flags.set(p->attribute);
139 if ((flags.has(TR_FORCE_WEAPON)) && (player_ptr->csp > (player_ptr->msp / 30))) {
140 attribute_flags.set(AttributeType::MANA);
143 return attribute_flags;
147 * @brief 矢弾を射撃した際のスレイ倍率をかけた結果を返す /
148 * Determines the odds of an object breaking when thrown at a monster
149 * @param bow_ptr 弓のオブジェクト構造体参照ポインタ
150 * @param arrow_ptr 矢弾のオブジェクト構造体参照ポインタ
151 * @param tdam 計算途中のダメージ量
152 * @param monster_ptr 目標モンスターの構造体参照ポインタ
153 * @return スレイ倍率をかけたダメージ量
155 static MULTIPLY calc_shot_damage_with_slay(
156 PlayerType *player_ptr, ItemEntity *bow_ptr, ItemEntity *arrow_ptr, int tdam, MonsterEntity *monster_ptr, SPELL_IDX snipe_type)
160 MonsterRaceInfo *race_ptr = &monraces_info[monster_ptr->r_idx];
163 auto arrow_flags = object_flags(arrow_ptr);
164 auto bow_flags = object_flags(bow_ptr);
166 flags = bow_flags | arrow_flags;
168 /* Some "weapons" and "ammo" do extra damage */
169 switch (arrow_ptr->bi_key.tval()) {
170 case ItemKindType::SHOT:
171 case ItemKindType::ARROW:
172 case ItemKindType::BOLT: {
173 if ((flags.has(TR_SLAY_ANIMAL)) && race_ptr->kind_flags.has(MonsterKindType::ANIMAL)) {
174 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
175 race_ptr->r_kind_flags.set(MonsterKindType::ANIMAL);
182 if ((flags.has(TR_KILL_ANIMAL)) && race_ptr->kind_flags.has(MonsterKindType::ANIMAL)) {
183 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
184 race_ptr->r_kind_flags.set(MonsterKindType::ANIMAL);
191 if ((flags.has(TR_SLAY_EVIL)) && race_ptr->kind_flags.has(MonsterKindType::EVIL)) {
192 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
193 race_ptr->r_kind_flags.set(MonsterKindType::EVIL);
200 if ((flags.has(TR_KILL_EVIL)) && race_ptr->kind_flags.has(MonsterKindType::EVIL)) {
201 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
202 race_ptr->r_kind_flags.set(MonsterKindType::EVIL);
209 if ((flags.has(TR_SLAY_GOOD)) && race_ptr->kind_flags.has(MonsterKindType::GOOD)) {
210 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
211 race_ptr->r_kind_flags.set(MonsterKindType::GOOD);
218 if ((flags.has(TR_KILL_GOOD)) && race_ptr->kind_flags.has(MonsterKindType::GOOD)) {
219 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
220 race_ptr->r_kind_flags.set(MonsterKindType::GOOD);
227 if ((flags.has(TR_SLAY_HUMAN)) && race_ptr->kind_flags.has(MonsterKindType::HUMAN)) {
228 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
229 race_ptr->r_kind_flags.set(MonsterKindType::HUMAN);
236 if ((flags.has(TR_KILL_HUMAN)) && race_ptr->kind_flags.has(MonsterKindType::HUMAN)) {
237 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
238 race_ptr->r_kind_flags.set(MonsterKindType::HUMAN);
245 if ((flags.has(TR_SLAY_UNDEAD)) && race_ptr->kind_flags.has(MonsterKindType::UNDEAD)) {
246 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
247 race_ptr->r_kind_flags.set(MonsterKindType::UNDEAD);
254 if ((flags.has(TR_KILL_UNDEAD)) && race_ptr->kind_flags.has(MonsterKindType::UNDEAD)) {
255 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
256 race_ptr->r_kind_flags.set(MonsterKindType::UNDEAD);
263 if ((flags.has(TR_SLAY_DEMON)) && race_ptr->kind_flags.has(MonsterKindType::DEMON)) {
264 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
265 race_ptr->r_kind_flags.set(MonsterKindType::DEMON);
272 if ((flags.has(TR_KILL_DEMON)) && race_ptr->kind_flags.has(MonsterKindType::DEMON)) {
273 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
274 race_ptr->r_kind_flags.set(MonsterKindType::DEMON);
281 if ((flags.has(TR_SLAY_ORC)) && race_ptr->kind_flags.has(MonsterKindType::ORC)) {
282 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
283 race_ptr->r_kind_flags.set(MonsterKindType::ORC);
290 if ((flags.has(TR_KILL_ORC)) && race_ptr->kind_flags.has(MonsterKindType::ORC)) {
291 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
292 race_ptr->r_kind_flags.set(MonsterKindType::ORC);
299 if ((flags.has(TR_SLAY_TROLL)) && race_ptr->kind_flags.has(MonsterKindType::TROLL)) {
300 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
301 race_ptr->r_kind_flags.set(MonsterKindType::TROLL);
309 if ((flags.has(TR_KILL_TROLL)) && race_ptr->kind_flags.has(MonsterKindType::TROLL)) {
310 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
311 race_ptr->r_kind_flags.set(MonsterKindType::TROLL);
318 if ((flags.has(TR_SLAY_GIANT)) && race_ptr->kind_flags.has(MonsterKindType::GIANT)) {
319 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
320 race_ptr->r_kind_flags.set(MonsterKindType::GIANT);
327 if ((flags.has(TR_KILL_GIANT)) && race_ptr->kind_flags.has(MonsterKindType::GIANT)) {
328 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
329 race_ptr->r_kind_flags.set(MonsterKindType::GIANT);
336 if ((flags.has(TR_SLAY_DRAGON)) && race_ptr->kind_flags.has(MonsterKindType::DRAGON)) {
337 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
338 race_ptr->r_kind_flags.set(MonsterKindType::DRAGON);
345 if ((flags.has(TR_KILL_DRAGON)) && race_ptr->kind_flags.has(MonsterKindType::DRAGON)) {
346 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
347 race_ptr->r_kind_flags.set(MonsterKindType::DRAGON);
353 auto can_eliminate_smaug = arrow_ptr->is_specific_artifact(FixedArtifactId::BARD_ARROW);
354 can_eliminate_smaug &= player_ptr->inventory_list[INVEN_BOW].is_specific_artifact(FixedArtifactId::BARD);
355 can_eliminate_smaug &= monster_ptr->r_idx == MonsterRaceId::SMAUG;
356 if (can_eliminate_smaug) {
361 if (flags.has(TR_BRAND_ACID)) {
362 /* Notice immunity */
363 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_ACID_MASK)) {
364 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
365 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_ACID_MASK);
374 if (flags.has(TR_BRAND_ELEC)) {
375 /* Notice immunity */
376 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_ELEC_MASK)) {
377 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
378 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_ELEC_MASK);
387 if (flags.has(TR_BRAND_FIRE)) {
388 /* Notice immunity */
389 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_FIRE_MASK)) {
390 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
391 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_FIRE_MASK);
394 /* Otherwise, take the damage */
396 if (race_ptr->resistance_flags.has(MonsterResistanceType::HURT_FIRE)) {
400 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
401 race_ptr->r_resistance_flags.set(MonsterResistanceType::HURT_FIRE);
403 } else if (mult < 17) {
409 if (flags.has(TR_BRAND_COLD)) {
410 /* Notice immunity */
411 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_COLD_MASK)) {
412 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
413 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_COLD_MASK);
416 /* Otherwise, take the damage */
418 if (race_ptr->resistance_flags.has(MonsterResistanceType::HURT_COLD)) {
422 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
423 race_ptr->r_resistance_flags.set(MonsterResistanceType::HURT_COLD);
425 } else if (mult < 17) {
431 if (flags.has(TR_BRAND_POIS)) {
432 /* Notice immunity */
433 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_POISON_MASK)) {
434 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
435 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_POISON_MASK);
438 /* Otherwise, take the damage */
446 if ((flags.has(TR_FORCE_WEAPON)) && (player_ptr->csp > (player_ptr->msp / 30))) {
447 player_ptr->csp -= (1 + (player_ptr->msp / 30));
448 set_bits(player_ptr->redraw, PR_MANA);
460 mult = calc_snipe_damage_with_slay(player_ptr, mult, monster_ptr, snipe_type);
463 /* Return the total damage */
464 return tdam * mult / 10;
469 * Fire an object from the pack or floor.
470 * @param item 射撃するオブジェクトの所持ID
471 * @param bow_ptr 射撃武器のオブジェクト参照ポインタ
474 * You may only fire items that "match" your missile launcher.
475 * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
476 * See "calc_bonuses()" for more calculations and such.
477 * Note that "firing" a missile is MUCH better than "throwing" it.
478 * Note: "unseen" monsters are very hard to hit.
479 * Objects are more likely to break if they "attempt" to hit a monster.
480 * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
481 * The "extra shot" code works by decreasing the amount of energy
482 * required to make each shot, spreading the shots out over time.
483 * Note that when firing missiles, the launcher multiplier is applied
484 * after all the bonuses are added in, making multipliers very useful.
485 * Note that Bows of "Extra Might" get extra range and an extra bonus
486 * for the damage multiplier.
487 * Note that Bows of "Extra Shots" give an extra shot.
490 void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPELL_IDX snipe_type)
492 POSITION y, x, ny, nx, ty, tx, prev_y, prev_x;
497 AttributeFlags attribute_flags{};
498 attribute_flags.set(AttributeType::PLAYER_SHOOT);
500 auto hit_body = false;
501 auto stick_to = false;
503 /* Access the item (if in the pack) */
505 o_ptr = &player_ptr->inventory_list[item];
507 o_ptr = &player_ptr->current_floor_ptr->o_list[0 - item];
510 /* Sniper - Cannot shot a single arrow twice */
511 if ((snipe_type == SP_DOUBLE) && (o_ptr->number < 2)) {
512 snipe_type = SP_NONE;
515 GAME_TEXT o_name[MAX_NLEN];
516 describe_flavor(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
518 /* Use the proper number of shots */
519 auto thits = player_ptr->num_fire;
521 /* Use a base distance */
524 /* Base damage from thrown object plus launcher bonus */
525 auto tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
527 /* Actually "fire" the object */
528 const auto tval = j_ptr->bi_key.tval();
529 const auto median_skill_exp = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2;
530 const auto bonus = (player_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
531 const auto &weapon_exps = player_ptr->weapon_exp[tval];
532 constexpr auto bow_magnification = 200;
533 constexpr auto xbow_magnification = 400;
535 if (tval == ItemKindType::NONE) {
536 chance = (player_ptr->skill_thb + ((weapon_exps[0] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ);
538 const auto sval = j_ptr->bi_key.sval().value();
539 if (j_ptr->is_cross_bow()) {
540 chance = (player_ptr->skill_thb + (weapon_exps[sval] / xbow_magnification + bonus) * BTH_PLUS_ADJ);
542 chance = (player_ptr->skill_thb + ((weapon_exps[sval] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ);
546 PlayerEnergy(player_ptr).set_player_turn_energy(j_ptr->get_bow_energy());
547 auto tmul = j_ptr->get_arrow_magnification();
549 /* Get extra "power" from "extra might" */
550 if (player_ptr->xtra_might) {
554 tmul = tmul * (100 + (int)(adj_str_td[player_ptr->stat_index[A_STR]]) - 128);
556 /* Boost the damage */
560 auto sniper_data = PlayerClass(player_ptr).get_specific_data<sniper_data_type>();
561 auto sniper_concent = sniper_data ? sniper_data->concent : 0;
564 tdis = 13 + tmul / 80;
565 if (j_ptr->is_cross_bow()) {
566 tdis -= (5 - (sniper_concent + 1) / 2);
569 project_length = tdis + 1;
571 /* Get a direction (or cancel) */
573 if (!get_aim_dir(player_ptr, &dir)) {
574 PlayerEnergy(player_ptr).reset_player_turn();
576 if (snipe_type == SP_AWAY) {
577 snipe_type = SP_NONE;
580 /* need not to reset project_length (already did)*/
585 if (snipe_type != SP_NONE) {
589 /* Predict the "target" location */
590 tx = player_ptr->x + 99 * ddx[dir];
591 ty = player_ptr->y + 99 * ddy[dir];
593 /* Check for "target request" */
594 if ((dir == 5) && target_okay(player_ptr)) {
599 /* Get projection path length */
600 projection_path path_g(player_ptr, project_length, player_ptr->y, player_ptr->x, ty, tx, PROJECT_PATH | PROJECT_THRU);
601 tdis = path_g.path_num() - 1;
603 project_length = 0; /* reset to default */
605 /* Don't shoot at my feet */
606 if (tx == player_ptr->x && ty == player_ptr->y) {
607 PlayerEnergy(player_ptr).reset_player_turn();
609 /* project_length is already reset to 0 */
614 /* Take a (partial) turn */
615 PlayerEnergy(player_ptr).div_player_turn_energy(thits);
616 player_ptr->is_fired = true;
618 /* Sniper - Difficult to shot twice at 1 turn */
619 if (snipe_type == SP_DOUBLE) {
620 sniper_concent = (sniper_concent + 1) / 2;
623 /* Sniper - Repeat shooting when double shots */
624 for (auto i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++) {
625 /* Start at the player */
629 q_ptr->copy_from(o_ptr);
634 vary_item(player_ptr, item, -1);
637 handle_stuff(player_ptr);
642 /* The shot does not hit yet */
645 /* Travel until stopped */
646 for (auto cur_dis = 0; cur_dis <= tdis;) {
649 /* Hack -- Stop at the target */
650 if ((y == ty) && (x == tx)) {
654 /* Calculate the new location (see "project()") */
657 mmove2(&ny, &nx, player_ptr->y, player_ptr->x, ty, tx);
660 if (snipe_type == SP_KILL_WALL) {
661 g_ptr = &player_ptr->current_floor_ptr->grid_array[ny][nx];
663 if (g_ptr->cave_has_flag(TerrainCharacteristics::HURT_ROCK) && !g_ptr->m_idx) {
664 if (any_bits(g_ptr->info, (CAVE_MARK))) {
665 msg_print(_("岩が砕け散った。", "Wall rocks were shattered."));
667 /* Forget the wall */
668 reset_bits(g_ptr->info, (CAVE_MARK));
669 set_bits(player_ptr->update, PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
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(player_ptr->current_floor_ptr, ny, nx, TerrainCharacteristics::PROJECT) && !player_ptr->current_floor_ptr->grid_array[ny][nx].m_idx) {
684 /* Advance the distance */
688 if (snipe_type == SP_LITE) {
689 set_bits(player_ptr->current_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 project(player_ptr, 0, 0, ny, nx, 0, AttributeType::KILL_TRAP, (PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM));
724 if (snipe_type == SP_EVILNESS) {
725 reset_bits(player_ptr->current_floor_ptr->grid_array[ny][nx].info, (CAVE_GLOW | CAVE_MARK));
726 note_spot(player_ptr, ny, nx);
727 lite_spot(player_ptr, ny, nx);
733 /* Save the new location */
737 /* Monster here, Try to hit it */
738 if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
739 sound(SOUND_SHOOT_HIT);
740 grid_type *c_mon_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
742 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[c_mon_ptr->m_idx];
743 auto *r_ptr = &monraces_info[m_ptr->r_idx];
745 /* Check the visibility */
746 auto visible = m_ptr->ml;
748 /* Note the collision */
751 if (m_ptr->is_asleep()) {
752 if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5)) {
753 chg_virtue(player_ptr, V_COMPASSION, -1);
755 if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5)) {
756 chg_virtue(player_ptr, V_HONOUR, -1);
760 if ((r_ptr->level + 10) > player_ptr->lev) {
761 PlayerSkill(player_ptr).gain_range_weapon_exp(j_ptr);
764 if (player_ptr->riding) {
765 PlayerSkill(player_ptr).gain_riding_skill_exp_on_range_attack();
768 /* Did we hit it (penalize range) */
769 if (test_hit_fire(player_ptr, chance - cur_dis, m_ptr, m_ptr->ml, o_name)) {
771 auto tdam = tdam_base; //!< @note 実際に与えるダメージ
772 auto base_dam = tdam; //!< @note 補正前の与えるダメージ(無傷、全ての耐性など)
774 /* Get extra damage from concentration */
775 tdam = boost_concentration_damage(player_ptr, tdam);
777 /* Handle unseen monster */
779 /* Invisible monster */
780 msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
783 /* Handle visible monster */
785 /* Get "the monster" or "it" */
786 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
788 msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name.data());
791 if (!player_ptr->effects()->hallucination()->is_hallucinated()) {
792 monster_race_track(player_ptr, m_ptr->ap_r_idx);
795 health_track(player_ptr, c_mon_ptr->m_idx);
799 if (snipe_type == SP_NEEDLE) {
800 const auto is_unique = r_ptr->kind_flags.has(MonsterKindType::UNIQUE);
801 const auto fatality = randint1(r_ptr->level / (3 + sniper_concent)) + (8 - sniper_concent);
802 if ((randint1(fatality) == 1) && !is_unique && none_bits(r_ptr->flags7, RF7_UNIQUE2)) {
803 /* Get "the monster" or "it" */
804 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
806 tdam = m_ptr->hp + 1;
808 msg_format(_("%sの急所に突き刺さった!", "Your shot hit a fatal spot of %s!"), m_name.data());
815 attribute_flags = shot_attribute(player_ptr, j_ptr, q_ptr, snipe_type);
816 /* Apply special damage */
817 tdam = calc_shot_damage_with_slay(player_ptr, j_ptr, q_ptr, tdam, m_ptr, snipe_type);
818 tdam = critical_shot(player_ptr, q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
820 /* No negative damage */
825 /* Modify the damage */
827 tdam = mon_damage_mod(player_ptr, m_ptr, tdam, false);
830 msg_format_wizard(player_ptr, CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"), tdam,
831 m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
834 if (snipe_type == SP_EXPLODE) {
835 uint16_t flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
837 sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
838 project(player_ptr, 0, ((sniper_concent + 1) / 2 + 1), ny, nx, base_dam, AttributeType::MISSILE, flg);
843 if (snipe_type == SP_HOLYNESS) {
844 set_bits(player_ptr->current_floor_ptr->grid_array[ny][nx].info, CAVE_GLOW);
845 note_spot(player_ptr, ny, nx);
846 lite_spot(player_ptr, ny, nx);
849 /* Hit the monster, check for death */
850 MonsterDamageProcessor mdp(player_ptr, c_mon_ptr->m_idx, tdam, &fear, attribute_flags);
851 if (mdp.mon_take_hit(extract_note_dies(m_ptr->get_real_r_idx()))) {
858 if (q_ptr->is_fixed_artifact() && (sniper_concent == 0)) {
859 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
862 msg_format(_("%sは%sに突き刺さった!", "%s^ is stuck in %s!"), o_name, m_name.data());
865 if (const auto pain_message = MonsterPainDescriber(player_ptr, c_mon_ptr->m_idx).describe(tdam);
866 !pain_message.empty()) {
867 msg_print(pain_message);
870 /* Anger the monster */
872 anger_monster(player_ptr, m_ptr);
875 if (fear && m_ptr->ml) {
876 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
878 msg_format(_("%s^は恐怖して逃げ出した!", "%s^ flees in terror!"), m_name.data());
881 set_target(m_ptr, player_ptr->y, player_ptr->x);
884 if (snipe_type == SP_RUSH) {
885 int n = randint1(5) + 3;
886 MONSTER_IDX m_idx = c_mon_ptr->m_idx;
888 for (; cur_dis <= tdis;) {
896 /* Calculate the new location (see "project()") */
897 mmove2(&ny, &nx, player_ptr->y, player_ptr->x, ty, tx);
899 /* Stopped by wilderness boundary */
900 if (!in_bounds2(player_ptr->current_floor_ptr, ny, nx)) {
904 /* Stopped by walls/doors */
905 if (!player_can_enter(player_ptr, player_ptr->current_floor_ptr->grid_array[ny][nx].feat, 0)) {
909 /* Stopped by monsters */
910 if (!is_cave_empty_bold(player_ptr, ny, nx)) {
914 player_ptr->current_floor_ptr->grid_array[ny][nx].m_idx = m_idx;
915 player_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = 0;
920 update_monster(player_ptr, m_idx, true);
922 if (delay_factor > 0) {
923 lite_spot(player_ptr, ny, nx);
924 lite_spot(player_ptr, oy, ox);
926 term_xtra(TERM_XTRA_DELAY, delay_factor);
939 if (snipe_type == SP_PIERCE && sniper_concent > 0) {
949 /* Chance of breakage (during attacks) */
950 auto j = (hit_body ? breakage_chance(player_ptr, q_ptr, PlayerClass(player_ptr).equals(PlayerClassType::ARCHER), snipe_type) : 0);
953 MONSTER_IDX m_idx = player_ptr->current_floor_ptr->grid_array[y][x].m_idx;
954 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
955 OBJECT_IDX o_idx = o_pop(player_ptr->current_floor_ptr);
958 msg_format(_("%sはどこかへ行った。", "The %s went somewhere."), o_name);
959 if (q_ptr->is_fixed_artifact()) {
960 artifacts_info.at(j_ptr->fixed_artifact_idx).is_generated = false;
965 o_ptr = &player_ptr->current_floor_ptr->o_list[o_idx];
966 o_ptr->copy_from(q_ptr);
969 o_ptr->marked.reset(OmType::TOUCHED);
971 /* Forget location */
972 o_ptr->iy = o_ptr->ix = 0;
974 /* Memorize monster */
975 o_ptr->held_m_idx = m_idx;
978 m_ptr->hold_o_idx_list.add(player_ptr->current_floor_ptr, o_idx);
979 } else if (cave_has_flag_bold(player_ptr->current_floor_ptr, y, x, TerrainCharacteristics::PROJECT)) {
980 /* Drop (or break) near that location */
981 (void)drop_near(player_ptr, q_ptr, j, y, x);
983 /* Drop (or break) near that location */
984 (void)drop_near(player_ptr, q_ptr, j, prev_y, prev_x);
987 /* Sniper - Repeat shooting when double shots */
990 /* Sniper - Loose his/her concentration after any shot */
991 reset_concentration(player_ptr, false);
995 * @brief プレイヤーからモンスターへの射撃命中判定 /
996 * Determine if the player "hits" a monster (normal combat).
997 * @param chance 基本命中値
998 * @param monster_ptr モンスターの構造体参照ポインタ
999 * @param vis 目標を視界に捕らえているならばTRUEを指定
1000 * @param o_name メッセージ表示時のモンスター名
1001 * @return 命中と判定された場合TRUEを返す
1002 * @note Always miss 5%, always hit 5%, otherwise random.
1004 bool test_hit_fire(PlayerType *player_ptr, int chance, MonsterEntity *m_ptr, int vis, char *o_name)
1008 auto *r_ptr = &monraces_info[m_ptr->r_idx];
1010 /* Percentile dice */
1013 auto sniper_data = PlayerClass(player_ptr).get_specific_data<sniper_data_type>();
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(), o_name);
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<sniper_data_type>();
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<sniper_data_type>();
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;