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-status-setter.h"
44 #include "monster/monster-status.h"
45 #include "monster/monster-update.h"
46 #include "object/object-broken.h"
47 #include "object/object-flags.h"
48 #include "object/object-info.h"
49 #include "object/object-mark-types.h"
50 #include "player-base/player-class.h"
51 #include "player-info/class-info.h"
52 #include "player-info/sniper-data-type.h"
53 #include "player-status/player-energy.h"
54 #include "player/player-personality-types.h"
55 #include "player/player-skill.h"
56 #include "player/player-status-table.h"
57 #include "sv-definition/sv-bow-types.h"
58 #include "system/artifact-type-definition.h"
59 #include "system/baseitem-info.h"
60 #include "system/floor-type-definition.h"
61 #include "system/grid-type-definition.h"
62 #include "system/item-entity.h"
63 #include "system/monster-entity.h"
64 #include "system/monster-race-info.h"
65 #include "system/player-type-definition.h"
66 #include "target/projection-path-calculator.h"
67 #include "target/target-checker.h"
68 #include "target/target-getter.h"
69 #include "timed-effect/player-hallucination.h"
70 #include "timed-effect/timed-effects.h"
71 #include "util/bit-flags-calculator.h"
72 #include "view/display-messages.h"
73 #include "wizard/wizard-messages.h"
74 #include "world/world-object.h"
78 * @param bow_ptr 弓のオブジェクト構造体参照ポインタ
79 * @param arrow_ptr 矢弾のオブジェクト構造体参照ポインタ
80 * @return スナイパーの射撃属性、弓矢の属性を考慮する。デフォルトはGF_PLAYER_SHOOT。
82 AttributeFlags shot_attribute(PlayerType *player_ptr, ItemEntity *bow_ptr, ItemEntity *arrow_ptr, SPELL_IDX snipe_type)
84 AttributeFlags attribute_flags{};
85 attribute_flags.set(AttributeType::PLAYER_SHOOT);
88 auto arrow_flags = object_flags(arrow_ptr);
89 auto bow_flags = object_flags(bow_ptr);
91 flags = bow_flags | arrow_flags;
93 static const struct snipe_convert_table_t {
95 AttributeType attribute;
96 } snipe_convert_table[] = {
97 { SP_LITE, AttributeType::LITE },
98 { SP_FIRE, AttributeType::FIRE },
99 { SP_COLD, AttributeType::COLD },
100 { SP_ELEC, AttributeType::ELEC },
101 { SP_KILL_WALL, AttributeType::KILL_WALL },
102 { SP_EVILNESS, AttributeType::HELL_FIRE },
103 { SP_HOLYNESS, AttributeType::HOLY_FIRE },
104 { SP_FINAL, AttributeType::MANA },
107 static const struct brand_convert_table_t {
109 AttributeType attribute;
110 } brand_convert_table[] = {
111 { TR_BRAND_ACID, AttributeType::ACID },
112 { TR_BRAND_FIRE, AttributeType::FIRE },
113 { TR_BRAND_ELEC, AttributeType::ELEC },
114 { TR_BRAND_COLD, AttributeType::COLD },
115 { TR_BRAND_POIS, AttributeType::POIS },
116 { TR_SLAY_GOOD, AttributeType::HELL_FIRE },
117 { TR_KILL_GOOD, AttributeType::HELL_FIRE },
118 { TR_SLAY_EVIL, AttributeType::HOLY_FIRE },
119 { TR_KILL_EVIL, AttributeType::HOLY_FIRE },
122 for (size_t i = 0; i < sizeof(snipe_convert_table) / sizeof(snipe_convert_table[0]); ++i) {
123 const struct snipe_convert_table_t *p = &snipe_convert_table[i];
125 if (snipe_type == p->snipe_type) {
126 attribute_flags.set(p->attribute);
130 for (size_t i = 0; i < sizeof(brand_convert_table) / sizeof(brand_convert_table[0]); ++i) {
131 const struct brand_convert_table_t *p = &brand_convert_table[i];
133 if (flags.has(p->brand_type)) {
134 attribute_flags.set(p->attribute);
138 if ((flags.has(TR_FORCE_WEAPON)) && (player_ptr->csp > (player_ptr->msp / 30))) {
139 attribute_flags.set(AttributeType::MANA);
142 return attribute_flags;
146 * @brief 矢弾を射撃した際のスレイ倍率をかけた結果を返す /
147 * Determines the odds of an object breaking when thrown at a monster
148 * @param bow_ptr 弓のオブジェクト構造体参照ポインタ
149 * @param arrow_ptr 矢弾のオブジェクト構造体参照ポインタ
150 * @param tdam 計算途中のダメージ量
151 * @param monster_ptr 目標モンスターの構造体参照ポインタ
152 * @return スレイ倍率をかけたダメージ量
154 static MULTIPLY calc_shot_damage_with_slay(
155 PlayerType *player_ptr, ItemEntity *bow_ptr, ItemEntity *arrow_ptr, int tdam, MonsterEntity *monster_ptr, SPELL_IDX snipe_type)
159 MonsterRaceInfo *race_ptr = &monraces_info[monster_ptr->r_idx];
162 auto arrow_flags = object_flags(arrow_ptr);
163 auto bow_flags = object_flags(bow_ptr);
165 flags = bow_flags | arrow_flags;
167 /* Some "weapons" and "ammo" do extra damage */
168 switch (arrow_ptr->bi_key.tval()) {
169 case ItemKindType::SHOT:
170 case ItemKindType::ARROW:
171 case ItemKindType::BOLT: {
172 if ((flags.has(TR_SLAY_ANIMAL)) && race_ptr->kind_flags.has(MonsterKindType::ANIMAL)) {
173 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
174 race_ptr->r_kind_flags.set(MonsterKindType::ANIMAL);
181 if ((flags.has(TR_KILL_ANIMAL)) && race_ptr->kind_flags.has(MonsterKindType::ANIMAL)) {
182 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
183 race_ptr->r_kind_flags.set(MonsterKindType::ANIMAL);
190 if ((flags.has(TR_SLAY_EVIL)) && race_ptr->kind_flags.has(MonsterKindType::EVIL)) {
191 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
192 race_ptr->r_kind_flags.set(MonsterKindType::EVIL);
199 if ((flags.has(TR_KILL_EVIL)) && race_ptr->kind_flags.has(MonsterKindType::EVIL)) {
200 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
201 race_ptr->r_kind_flags.set(MonsterKindType::EVIL);
208 if ((flags.has(TR_SLAY_GOOD)) && race_ptr->kind_flags.has(MonsterKindType::GOOD)) {
209 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
210 race_ptr->r_kind_flags.set(MonsterKindType::GOOD);
217 if ((flags.has(TR_KILL_GOOD)) && race_ptr->kind_flags.has(MonsterKindType::GOOD)) {
218 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
219 race_ptr->r_kind_flags.set(MonsterKindType::GOOD);
226 if ((flags.has(TR_SLAY_HUMAN)) && race_ptr->kind_flags.has(MonsterKindType::HUMAN)) {
227 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
228 race_ptr->r_kind_flags.set(MonsterKindType::HUMAN);
235 if ((flags.has(TR_KILL_HUMAN)) && race_ptr->kind_flags.has(MonsterKindType::HUMAN)) {
236 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
237 race_ptr->r_kind_flags.set(MonsterKindType::HUMAN);
244 if ((flags.has(TR_SLAY_UNDEAD)) && race_ptr->kind_flags.has(MonsterKindType::UNDEAD)) {
245 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
246 race_ptr->r_kind_flags.set(MonsterKindType::UNDEAD);
253 if ((flags.has(TR_KILL_UNDEAD)) && race_ptr->kind_flags.has(MonsterKindType::UNDEAD)) {
254 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
255 race_ptr->r_kind_flags.set(MonsterKindType::UNDEAD);
262 if ((flags.has(TR_SLAY_DEMON)) && race_ptr->kind_flags.has(MonsterKindType::DEMON)) {
263 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
264 race_ptr->r_kind_flags.set(MonsterKindType::DEMON);
271 if ((flags.has(TR_KILL_DEMON)) && race_ptr->kind_flags.has(MonsterKindType::DEMON)) {
272 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
273 race_ptr->r_kind_flags.set(MonsterKindType::DEMON);
280 if ((flags.has(TR_SLAY_ORC)) && race_ptr->kind_flags.has(MonsterKindType::ORC)) {
281 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
282 race_ptr->r_kind_flags.set(MonsterKindType::ORC);
289 if ((flags.has(TR_KILL_ORC)) && race_ptr->kind_flags.has(MonsterKindType::ORC)) {
290 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
291 race_ptr->r_kind_flags.set(MonsterKindType::ORC);
298 if ((flags.has(TR_SLAY_TROLL)) && race_ptr->kind_flags.has(MonsterKindType::TROLL)) {
299 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
300 race_ptr->r_kind_flags.set(MonsterKindType::TROLL);
308 if ((flags.has(TR_KILL_TROLL)) && race_ptr->kind_flags.has(MonsterKindType::TROLL)) {
309 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
310 race_ptr->r_kind_flags.set(MonsterKindType::TROLL);
317 if ((flags.has(TR_SLAY_GIANT)) && race_ptr->kind_flags.has(MonsterKindType::GIANT)) {
318 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
319 race_ptr->r_kind_flags.set(MonsterKindType::GIANT);
326 if ((flags.has(TR_KILL_GIANT)) && race_ptr->kind_flags.has(MonsterKindType::GIANT)) {
327 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
328 race_ptr->r_kind_flags.set(MonsterKindType::GIANT);
335 if ((flags.has(TR_SLAY_DRAGON)) && race_ptr->kind_flags.has(MonsterKindType::DRAGON)) {
336 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
337 race_ptr->r_kind_flags.set(MonsterKindType::DRAGON);
344 if ((flags.has(TR_KILL_DRAGON)) && race_ptr->kind_flags.has(MonsterKindType::DRAGON)) {
345 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
346 race_ptr->r_kind_flags.set(MonsterKindType::DRAGON);
352 auto can_eliminate_smaug = arrow_ptr->is_specific_artifact(FixedArtifactId::BARD_ARROW);
353 can_eliminate_smaug &= player_ptr->inventory_list[INVEN_BOW].is_specific_artifact(FixedArtifactId::BARD);
354 can_eliminate_smaug &= monster_ptr->r_idx == MonsterRaceId::SMAUG;
355 if (can_eliminate_smaug) {
360 if (flags.has(TR_BRAND_ACID)) {
361 /* Notice immunity */
362 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_ACID_MASK)) {
363 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
364 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_ACID_MASK);
373 if (flags.has(TR_BRAND_ELEC)) {
374 /* Notice immunity */
375 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_ELEC_MASK)) {
376 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
377 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_ELEC_MASK);
386 if (flags.has(TR_BRAND_FIRE)) {
387 /* Notice immunity */
388 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_FIRE_MASK)) {
389 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
390 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_FIRE_MASK);
393 /* Otherwise, take the damage */
395 if (race_ptr->resistance_flags.has(MonsterResistanceType::HURT_FIRE)) {
399 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
400 race_ptr->r_resistance_flags.set(MonsterResistanceType::HURT_FIRE);
402 } else if (mult < 17) {
408 if (flags.has(TR_BRAND_COLD)) {
409 /* Notice immunity */
410 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_COLD_MASK)) {
411 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
412 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_COLD_MASK);
415 /* Otherwise, take the damage */
417 if (race_ptr->resistance_flags.has(MonsterResistanceType::HURT_COLD)) {
421 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
422 race_ptr->r_resistance_flags.set(MonsterResistanceType::HURT_COLD);
424 } else if (mult < 17) {
430 if (flags.has(TR_BRAND_POIS)) {
431 /* Notice immunity */
432 if (race_ptr->resistance_flags.has_any_of(RFR_EFF_IM_POISON_MASK)) {
433 if (is_original_ap_and_seen(player_ptr, monster_ptr)) {
434 race_ptr->r_resistance_flags.set(race_ptr->resistance_flags & RFR_EFF_IM_POISON_MASK);
437 /* Otherwise, take the damage */
445 if ((flags.has(TR_FORCE_WEAPON)) && (player_ptr->csp > (player_ptr->msp / 30))) {
446 player_ptr->csp -= (1 + (player_ptr->msp / 30));
447 set_bits(player_ptr->redraw, PR_MANA);
459 mult = calc_snipe_damage_with_slay(player_ptr, mult, monster_ptr, snipe_type);
462 /* Return the total damage */
463 return tdam * mult / 10;
468 * Fire an object from the pack or floor.
469 * @param item 射撃するオブジェクトの所持ID
470 * @param bow_ptr 射撃武器のオブジェクト参照ポインタ
473 * You may only fire items that "match" your missile launcher.
474 * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
475 * See "calc_bonuses()" for more calculations and such.
476 * Note that "firing" a missile is MUCH better than "throwing" it.
477 * Note: "unseen" monsters are very hard to hit.
478 * Objects are more likely to break if they "attempt" to hit a monster.
479 * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
480 * The "extra shot" code works by decreasing the amount of energy
481 * required to make each shot, spreading the shots out over time.
482 * Note that when firing missiles, the launcher multiplier is applied
483 * after all the bonuses are added in, making multipliers very useful.
484 * Note that Bows of "Extra Might" get extra range and an extra bonus
485 * for the damage multiplier.
486 * Note that Bows of "Extra Shots" give an extra shot.
489 void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPELL_IDX snipe_type)
491 POSITION y, x, ny, nx, ty, tx, prev_y, prev_x;
496 AttributeFlags attribute_flags{};
497 attribute_flags.set(AttributeType::PLAYER_SHOOT);
499 auto hit_body = false;
500 auto stick_to = false;
502 /* Access the item (if in the pack) */
504 o_ptr = &player_ptr->inventory_list[item];
506 o_ptr = &player_ptr->current_floor_ptr->o_list[0 - item];
509 /* Sniper - Cannot shot a single arrow twice */
510 if ((snipe_type == SP_DOUBLE) && (o_ptr->number < 2)) {
511 snipe_type = SP_NONE;
514 GAME_TEXT o_name[MAX_NLEN];
515 describe_flavor(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
517 /* Use the proper number of shots */
518 auto thits = player_ptr->num_fire;
520 /* Use a base distance */
523 /* Base damage from thrown object plus launcher bonus */
524 auto tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
526 /* Actually "fire" the object */
527 const auto tval = j_ptr->bi_key.tval();
528 const auto median_skill_exp = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2;
529 const auto bonus = (player_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
530 const auto &weapon_exps = player_ptr->weapon_exp[tval];
531 constexpr auto bow_magnification = 200;
532 constexpr auto xbow_magnification = 400;
534 if (tval == ItemKindType::NONE) {
535 chance = (player_ptr->skill_thb + ((weapon_exps[0] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ);
537 const auto sval = j_ptr->bi_key.sval().value();
538 if (j_ptr->is_cross_bow()) {
539 chance = (player_ptr->skill_thb + (weapon_exps[sval] / xbow_magnification + bonus) * BTH_PLUS_ADJ);
541 chance = (player_ptr->skill_thb + ((weapon_exps[sval] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ);
545 PlayerEnergy(player_ptr).set_player_turn_energy(j_ptr->get_bow_energy());
546 auto tmul = j_ptr->get_arrow_magnification();
548 /* Get extra "power" from "extra might" */
549 if (player_ptr->xtra_might) {
553 tmul = tmul * (100 + (int)(adj_str_td[player_ptr->stat_index[A_STR]]) - 128);
555 /* Boost the damage */
559 auto sniper_data = PlayerClass(player_ptr).get_specific_data<sniper_data_type>();
560 auto sniper_concent = sniper_data ? sniper_data->concent : 0;
563 tdis = 13 + tmul / 80;
564 if (j_ptr->is_cross_bow()) {
565 tdis -= (5 - (sniper_concent + 1) / 2);
568 project_length = tdis + 1;
570 /* Get a direction (or cancel) */
572 if (!get_aim_dir(player_ptr, &dir)) {
573 PlayerEnergy(player_ptr).reset_player_turn();
575 if (snipe_type == SP_AWAY) {
576 snipe_type = SP_NONE;
579 /* need not to reset project_length (already did)*/
584 if (snipe_type != SP_NONE) {
588 /* Predict the "target" location */
589 tx = player_ptr->x + 99 * ddx[dir];
590 ty = player_ptr->y + 99 * ddy[dir];
592 /* Check for "target request" */
593 if ((dir == 5) && target_okay(player_ptr)) {
598 /* Get projection path length */
599 projection_path path_g(player_ptr, project_length, player_ptr->y, player_ptr->x, ty, tx, PROJECT_PATH | PROJECT_THRU);
600 tdis = path_g.path_num() - 1;
602 project_length = 0; /* reset to default */
604 /* Don't shoot at my feet */
605 if (tx == player_ptr->x && ty == player_ptr->y) {
606 PlayerEnergy(player_ptr).reset_player_turn();
608 /* project_length is already reset to 0 */
613 /* Take a (partial) turn */
614 PlayerEnergy(player_ptr).div_player_turn_energy(thits);
615 player_ptr->is_fired = true;
617 /* Sniper - Difficult to shot twice at 1 turn */
618 if (snipe_type == SP_DOUBLE) {
619 sniper_concent = (sniper_concent + 1) / 2;
622 /* Sniper - Repeat shooting when double shots */
623 for (auto i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++) {
624 /* Start at the player */
628 q_ptr->copy_from(o_ptr);
633 vary_item(player_ptr, item, -1);
636 handle_stuff(player_ptr);
641 /* The shot does not hit yet */
644 /* Travel until stopped */
645 for (auto cur_dis = 0; cur_dis <= tdis;) {
648 /* Hack -- Stop at the target */
649 if ((y == ty) && (x == tx)) {
653 /* Calculate the new location (see "project()") */
656 mmove2(&ny, &nx, player_ptr->y, player_ptr->x, ty, tx);
659 if (snipe_type == SP_KILL_WALL) {
660 g_ptr = &player_ptr->current_floor_ptr->grid_array[ny][nx];
662 if (g_ptr->cave_has_flag(TerrainCharacteristics::HURT_ROCK) && !g_ptr->m_idx) {
663 if (any_bits(g_ptr->info, (CAVE_MARK))) {
664 msg_print(_("岩が砕け散った。", "Wall rocks were shattered."));
666 /* Forget the wall */
667 reset_bits(g_ptr->info, (CAVE_MARK));
668 set_bits(player_ptr->update, PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
670 /* Destroy the wall */
671 cave_alter_feat(player_ptr, ny, nx, TerrainCharacteristics::HURT_ROCK);
678 /* Stopped by walls/doors */
679 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) {
683 /* Advance the distance */
687 if (snipe_type == SP_LITE) {
688 set_bits(player_ptr->current_floor_ptr->grid_array[ny][nx].info, CAVE_GLOW);
689 note_spot(player_ptr, ny, nx);
690 lite_spot(player_ptr, ny, nx);
693 /* The player can see the (on screen) missile */
694 if (panel_contains(ny, nx) && player_can_see_bold(player_ptr, ny, nx)) {
695 const auto a = q_ptr->get_color();
696 const auto c = q_ptr->get_symbol();
698 /* Draw, Hilite, Fresh, Pause, Erase */
699 if (delay_factor > 0) {
700 print_rel(player_ptr, c, a, ny, nx);
701 move_cursor_relative(ny, nx);
703 term_xtra(TERM_XTRA_DELAY, delay_factor);
704 lite_spot(player_ptr, ny, nx);
709 /* The player cannot see the missile */
711 /* Pause anyway, for consistancy **/
712 if (delay_factor > 0) {
713 term_xtra(TERM_XTRA_DELAY, delay_factor);
718 if (snipe_type == SP_KILL_TRAP) {
719 project(player_ptr, 0, 0, ny, nx, 0, AttributeType::KILL_TRAP, (PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM));
723 if (snipe_type == SP_EVILNESS) {
724 reset_bits(player_ptr->current_floor_ptr->grid_array[ny][nx].info, (CAVE_GLOW | CAVE_MARK));
725 note_spot(player_ptr, ny, nx);
726 lite_spot(player_ptr, ny, nx);
732 /* Save the new location */
736 /* Monster here, Try to hit it */
737 if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
738 sound(SOUND_SHOOT_HIT);
739 grid_type *c_mon_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
741 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[c_mon_ptr->m_idx];
742 auto *r_ptr = &monraces_info[m_ptr->r_idx];
744 /* Check the visibility */
745 auto visible = m_ptr->ml;
747 /* Note the collision */
750 if (m_ptr->is_asleep()) {
751 if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5)) {
752 chg_virtue(player_ptr, V_COMPASSION, -1);
754 if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5)) {
755 chg_virtue(player_ptr, V_HONOUR, -1);
759 if ((r_ptr->level + 10) > player_ptr->lev) {
760 PlayerSkill(player_ptr).gain_range_weapon_exp(j_ptr);
763 if (player_ptr->riding) {
764 PlayerSkill(player_ptr).gain_riding_skill_exp_on_range_attack();
767 /* Did we hit it (penalize range) */
768 if (test_hit_fire(player_ptr, chance - cur_dis, m_ptr, m_ptr->ml, o_name)) {
770 auto tdam = tdam_base; //!< @note 実際に与えるダメージ
771 auto base_dam = tdam; //!< @note 補正前の与えるダメージ(無傷、全ての耐性など)
773 /* Get extra damage from concentration */
774 tdam = boost_concentration_damage(player_ptr, tdam);
776 /* Handle unseen monster */
778 /* Invisible monster */
779 msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
782 /* Handle visible monster */
784 /* Get "the monster" or "it" */
785 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
787 msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name.data());
790 if (!player_ptr->effects()->hallucination()->is_hallucinated()) {
791 monster_race_track(player_ptr, m_ptr->ap_r_idx);
794 health_track(player_ptr, c_mon_ptr->m_idx);
798 if (snipe_type == SP_NEEDLE) {
799 const auto is_unique = r_ptr->kind_flags.has(MonsterKindType::UNIQUE);
800 const auto fatality = randint1(r_ptr->level / (3 + sniper_concent)) + (8 - sniper_concent);
801 if ((randint1(fatality) == 1) && !is_unique && none_bits(r_ptr->flags7, RF7_UNIQUE2)) {
802 /* Get "the monster" or "it" */
803 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
805 tdam = m_ptr->hp + 1;
807 msg_format(_("%sの急所に突き刺さった!", "Your shot hit a fatal spot of %s!"), m_name.data());
814 attribute_flags = shot_attribute(player_ptr, j_ptr, q_ptr, snipe_type);
815 /* Apply special damage */
816 tdam = calc_shot_damage_with_slay(player_ptr, j_ptr, q_ptr, tdam, m_ptr, snipe_type);
817 tdam = critical_shot(player_ptr, q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
819 /* No negative damage */
824 /* Modify the damage */
826 tdam = mon_damage_mod(player_ptr, m_ptr, tdam, false);
829 msg_format_wizard(player_ptr, CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"), tdam,
830 m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
833 if (snipe_type == SP_EXPLODE) {
834 uint16_t flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
836 sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
837 project(player_ptr, 0, ((sniper_concent + 1) / 2 + 1), ny, nx, base_dam, AttributeType::MISSILE, flg);
842 if (snipe_type == SP_HOLYNESS) {
843 set_bits(player_ptr->current_floor_ptr->grid_array[ny][nx].info, CAVE_GLOW);
844 note_spot(player_ptr, ny, nx);
845 lite_spot(player_ptr, ny, nx);
848 /* Hit the monster, check for death */
849 MonsterDamageProcessor mdp(player_ptr, c_mon_ptr->m_idx, tdam, &fear, attribute_flags);
850 if (mdp.mon_take_hit(extract_note_dies(m_ptr->get_real_r_idx()))) {
857 if (q_ptr->is_fixed_artifact() && (sniper_concent == 0)) {
858 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
861 msg_format(_("%sは%sに突き刺さった!", "%^s is stuck in %s!"), o_name, m_name.data());
864 message_pain(player_ptr, c_mon_ptr->m_idx, tdam);
866 /* Anger the monster */
868 anger_monster(player_ptr, m_ptr);
871 if (fear && m_ptr->ml) {
872 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
874 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name.data());
877 set_target(m_ptr, player_ptr->y, player_ptr->x);
880 if (snipe_type == SP_RUSH) {
881 int n = randint1(5) + 3;
882 MONSTER_IDX m_idx = c_mon_ptr->m_idx;
884 for (; cur_dis <= tdis;) {
892 /* Calculate the new location (see "project()") */
893 mmove2(&ny, &nx, player_ptr->y, player_ptr->x, ty, tx);
895 /* Stopped by wilderness boundary */
896 if (!in_bounds2(player_ptr->current_floor_ptr, ny, nx)) {
900 /* Stopped by walls/doors */
901 if (!player_can_enter(player_ptr, player_ptr->current_floor_ptr->grid_array[ny][nx].feat, 0)) {
905 /* Stopped by monsters */
906 if (!is_cave_empty_bold(player_ptr, ny, nx)) {
910 player_ptr->current_floor_ptr->grid_array[ny][nx].m_idx = m_idx;
911 player_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = 0;
916 update_monster(player_ptr, m_idx, true);
918 if (delay_factor > 0) {
919 lite_spot(player_ptr, ny, nx);
920 lite_spot(player_ptr, oy, ox);
922 term_xtra(TERM_XTRA_DELAY, delay_factor);
935 if (snipe_type == SP_PIERCE && sniper_concent > 0) {
945 /* Chance of breakage (during attacks) */
946 auto j = (hit_body ? breakage_chance(player_ptr, q_ptr, PlayerClass(player_ptr).equals(PlayerClassType::ARCHER), snipe_type) : 0);
949 MONSTER_IDX m_idx = player_ptr->current_floor_ptr->grid_array[y][x].m_idx;
950 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
951 OBJECT_IDX o_idx = o_pop(player_ptr->current_floor_ptr);
954 msg_format(_("%sはどこかへ行った。", "The %s went somewhere."), o_name);
955 if (q_ptr->is_fixed_artifact()) {
956 artifacts_info.at(j_ptr->fixed_artifact_idx).is_generated = false;
961 o_ptr = &player_ptr->current_floor_ptr->o_list[o_idx];
962 o_ptr->copy_from(q_ptr);
965 o_ptr->marked.reset(OmType::TOUCHED);
967 /* Forget location */
968 o_ptr->iy = o_ptr->ix = 0;
970 /* Memorize monster */
971 o_ptr->held_m_idx = m_idx;
974 m_ptr->hold_o_idx_list.add(player_ptr->current_floor_ptr, o_idx);
975 } else if (cave_has_flag_bold(player_ptr->current_floor_ptr, y, x, TerrainCharacteristics::PROJECT)) {
976 /* Drop (or break) near that location */
977 (void)drop_near(player_ptr, q_ptr, j, y, x);
979 /* Drop (or break) near that location */
980 (void)drop_near(player_ptr, q_ptr, j, prev_y, prev_x);
983 /* Sniper - Repeat shooting when double shots */
986 /* Sniper - Loose his/her concentration after any shot */
987 reset_concentration(player_ptr, false);
991 * @brief プレイヤーからモンスターへの射撃命中判定 /
992 * Determine if the player "hits" a monster (normal combat).
993 * @param chance 基本命中値
994 * @param monster_ptr モンスターの構造体参照ポインタ
995 * @param vis 目標を視界に捕らえているならばTRUEを指定
996 * @param o_name メッセージ表示時のモンスター名
997 * @return 命中と判定された場合TRUEを返す
998 * @note Always miss 5%, always hit 5%, otherwise random.
1000 bool test_hit_fire(PlayerType *player_ptr, int chance, MonsterEntity *m_ptr, int vis, char *o_name)
1004 auto *r_ptr = &monraces_info[m_ptr->r_idx];
1006 /* Percentile dice */
1009 auto sniper_data = PlayerClass(player_ptr).get_specific_data<sniper_data_type>();
1010 auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1012 /* Snipers with high-concentration reduce instant miss percentage.*/
1013 k += sniper_concent;
1015 /* Hack -- Instant miss or hit */
1023 if (player_ptr->ppersonality == PERSONALITY_LAZY) {
1035 ac = ac * (8 - sniper_concent) / 8;
1037 if (m_ptr->r_idx == MonsterRaceId::GOEMON && !m_ptr->is_asleep()) {
1041 /* Invisible monsters are harder to hit */
1043 chance = (chance + 1) / 2;
1046 /* Power competes against armor */
1047 if (randint0(chance) < (ac * 3 / 4)) {
1048 if (m_ptr->r_idx == MonsterRaceId::GOEMON && !m_ptr->is_asleep()) {
1049 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
1050 msg_format(_("%sは%sを斬り捨てた!", "%s cuts down %s!"), m_name.data(), o_name);
1060 * @brief プレイヤーからモンスターへの射撃クリティカル判定
1061 * @param weight 矢弾の重量
1062 * @param plus_ammo 矢弾の命中修正
1063 * @param plus_bow 弓の命中修正
1064 * @param dam 現在算出中のダメージ値
1065 * @return クリティカル修正が入ったダメージ値
1067 int critical_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam)
1069 const auto &item = player_ptr->inventory_list[INVEN_BOW];
1070 const auto bonus = player_ptr->to_h_b + plus_ammo;
1071 const auto tval = item.bi_key.tval();
1072 const auto median_skill_exp = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2;
1073 const auto &weapon_exps = player_ptr->weapon_exp[tval];
1074 constexpr auto bow_magnification = 200;
1075 constexpr auto xbow_magnification = 400;
1077 if (tval == ItemKindType::NONE) {
1078 power = player_ptr->skill_thb + ((weapon_exps[0] - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ;
1080 const auto sval = item.bi_key.sval().value();
1081 const auto weapon_exp = weapon_exps[sval];
1082 if (player_ptr->tval_ammo == ItemKindType::BOLT) {
1083 power = (player_ptr->skill_thb + (weapon_exp / xbow_magnification + bonus) * BTH_PLUS_ADJ);
1085 power = player_ptr->skill_thb + ((weapon_exp - median_skill_exp) / bow_magnification + bonus) * BTH_PLUS_ADJ;
1089 PlayerClass pc(player_ptr);
1090 const auto sniper_data = pc.get_specific_data<sniper_data_type>();
1091 const auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1093 /* Snipers can shot more critically with crossbows */
1094 power += ((power * sniper_concent) / 5);
1095 if (pc.equals(PlayerClassType::SNIPER) && (player_ptr->tval_ammo == ItemKindType::BOLT)) {
1099 /* Good bow makes more critical */
1100 power += plus_bow * 8 * (sniper_concent + 5);
1101 if (randint1(10000) > power) {
1105 const auto k = weight * randint1(500);
1107 msg_print(_("手ごたえがあった!", "It was a good hit!"));
1109 } else if (k < 1350) {
1110 msg_print(_("かなりの手ごたえがあった!", "It was a great hit!"));
1113 msg_print(_("会心の一撃だ!", "It was a superb hit!"));
1121 * @brief 射撃時クリティカルによるダメージ期待値修正計算(スナイパーの集中処理と武器経験値) / critical happens at i / 10000
1122 * @param player_ptr プレイヤーへの参照ポインタ
1123 * @param plus_ammo 矢弾のダメージ修正
1124 * @param plus_bow 弓のダメージ修正
1126 * @note 基本ダメージ量と重量はこの部位では計算に加わらない。
1128 int calc_crit_ratio_shot(PlayerType *player_ptr, int plus_ammo, int plus_bow)
1130 auto *j_ptr = &player_ptr->inventory_list[INVEN_BOW];
1132 /* Extract "shot" power */
1133 auto i = player_ptr->to_h_b + plus_ammo;
1134 const auto tval = j_ptr->bi_key.tval();
1135 const auto sval = j_ptr->bi_key.sval().value();
1136 if (player_ptr->tval_ammo == ItemKindType::BOLT) {
1137 i = (player_ptr->skill_thb + (player_ptr->weapon_exp[tval][sval] / 400 + i) * BTH_PLUS_ADJ);
1139 i = (player_ptr->skill_thb + ((player_ptr->weapon_exp[tval][sval] - (PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2)) / 200 + i) * BTH_PLUS_ADJ);
1142 PlayerClass pc(player_ptr);
1143 auto sniper_data = pc.get_specific_data<sniper_data_type>();
1144 auto sniper_concent = sniper_data ? sniper_data->concent : 0;
1146 /* Snipers can shot more critically with crossbows */
1147 i += ((i * sniper_concent) / 5);
1148 if (pc.equals(PlayerClassType::SNIPER) && (player_ptr->tval_ammo == ItemKindType::BOLT)) {
1152 /* Good bow makes more critical */
1153 i += plus_bow * 8 * (sniper_concent + 5);
1163 * @brief 射撃時クリティカルによるダメージ期待値修正計算(重量依存部分) / critical happens at i / 10000
1164 * @param weight 武器の重量
1165 * @param plus_ammo 矢弾のダメージ修正
1166 * @param plus_bow 弓のダメージ修正
1167 * @param dam 基本ダメージ量
1170 int calc_expect_crit_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam)
1174 i = calc_crit_ratio_shot(player_ptr, plus_ammo, plus_bow);
1179 crit = std::min(500, 900 / weight);
1180 num += dam * 3 / 2 * crit;
1183 crit = std::min(500, 1350 / weight);
1185 num += dam * 2 * crit;
1190 num += dam * 3 * crit;
1196 num += (10000 - i) * dam;
1203 * @brief 攻撃時クリティカルによるダメージ期待値修正計算(重量と毒針処理) / critical happens at i / 10000
1204 * @param player_ptr プレイヤーへの参照ポインタ
1205 * @param weight 武器の重量
1206 * @param plus 武器のダメージ修正
1208 * @param meichuu 命中値
1209 * @param dokubari 毒針処理か否か
1210 * @param impact 強撃かどうか
1213 int calc_expect_crit(PlayerType *player_ptr, WEIGHT weight, int plus, int dam, int16_t meichuu, bool dokubari, bool impact)
1219 int i = (weight + (meichuu * 3 + plus * 5) + player_ptr->skill_thn);
1224 // 通常ダメージdam、武器重量weightでクリティカルが発生した時のクリティカルダメージ期待値
1225 auto calc_weight_expect_dam = [](int dam, WEIGHT weight) {
1227 for (int d = 1; d <= 650; ++d) {
1229 sum += std::get<0>(apply_critical_norm_damage(k, dam));
1237 for (int d = 1; d <= 650; ++d) {
1238 num += calc_weight_expect_dam(dam, weight + d);
1242 num += calc_weight_expect_dam(dam, weight);
1245 int pow = PlayerClass(player_ptr).equals(PlayerClassType::NINJA) ? 4444 : 5000;
1251 num += (pow - i) * dam;