OSDN Git Service

Merge remote-tracking branch 'remotes/origin/For2.2.2-Fix-Hourier' into For2.2.2...
[hengband/hengband.git] / src / combat / attack-accuracy.c
1 #include "combat/attack-accuracy.h"
2 #include "inventory/inventory-slot-types.h"
3 #include "main/sound-definitions-table.h"
4 #include "main/sound-of-music.h"
5 #include "monster-race/monster-race.h"
6 #include "monster-race/race-flags-resistance.h"
7 #include "player/attack-defense-types.h"
8 #include "specific-object/death-scythe.h"
9 #include "sv-definition/sv-weapon-types.h"
10 #include "view/display-messages.h"
11
12 /*!
13  * @brief プレイヤーからモンスターへの打撃命中判定 /
14  * Determine if the player "hits" a monster (normal combat).
15  * @param chance 基本命中値
16  * @param ac モンスターのAC
17  * @param visible 目標を視界に捕らえているならばTRUEを指定
18  * @return 命中と判定された場合TRUEを返す
19  * @note Always miss 5%, always hit 5%, otherwise random.
20  */
21 bool test_hit_norm(player_type *attacker_ptr, HIT_RELIABILITY chance, ARMOUR_CLASS ac, bool visible)
22 {
23     if (!visible)
24         chance = (chance + 1) / 2;
25     return hit_chance(attacker_ptr, chance, ac) >= randint1(100);
26 }
27
28 /*!
29  * @brief モンスターへの命中率の計算
30  * @param player_ptr プレーヤーへの参照ポインタ
31  * @param to_h 命中値
32  * @param ac 敵AC
33  * @return 命中確率
34  */
35 PERCENTAGE hit_chance(player_type *attacker_ptr, HIT_RELIABILITY reli, ARMOUR_CLASS ac)
36 {
37     PERCENTAGE chance = 5, chance_left = 90;
38     if (reli <= 0)
39         return 5;
40     if (attacker_ptr->pseikaku == PERSONALITY_LAZY)
41         chance_left = (chance_left * 19 + 9) / 20;
42     chance += (100 - ((ac * 75) / reli)) * chance_left / 100;
43     if (chance < 5)
44         chance = 5;
45     return chance;
46 }
47
48 /*!
49  * @brief モンスター打撃の命中を判定する /
50  * Determine if a monster attack against the player succeeds.
51  * @param power 打撃属性毎の基本命中値
52  * @param level モンスターのレベル
53  * @param stun モンスターの朦朧値
54  * @return TRUEならば命中判定
55  * @details
56  * Always miss 5% of the time, Always hit 5% of the time.
57  * Otherwise, match monster power against player armor.
58  */
59 int check_hit_from_monster_to_player(player_type *target_ptr, int power, DEPTH level, int stun)
60 {
61     int k = randint0(100);
62     if (stun && one_in_(2))
63         return FALSE;
64     if (k < 10)
65         return (k < 5);
66     int i = (power + (level * 3));
67
68     int ac = target_ptr->ac + target_ptr->to_a;
69     if (target_ptr->special_attack & ATTACK_SUIKEN)
70         ac += (target_ptr->lev * 2);
71
72     if ((i > 0) && (randint1(i) > ((ac * 3) / 4)))
73         return TRUE;
74     return FALSE;
75 }
76
77 /*!
78  * @brief モンスターから敵モンスターへの命中判定
79  * @param power 打撃属性による基本命中値
80  * @param level 攻撃側モンスターのレベル
81  * @param ac 目標モンスターのAC
82  * @param stun 攻撃側モンスターが朦朧状態ならTRUEを返す
83  * @return 命中ならばTRUEを返す
84  */
85 int check_hit_from_monster_to_monster(int power, DEPTH level, ARMOUR_CLASS ac, int stun)
86 {
87     int k = randint0(100);
88     if (stun && one_in_(2))
89         return FALSE;
90     if (k < 10)
91         return (k < 5);
92     int i = (power + (level * 3));
93
94     if ((i > 0) && (randint1(i) > ((ac * 3) / 4)))
95         return TRUE;
96     return FALSE;
97 }
98
99 /*!
100  * @brief 攻撃が当たるかどうかを判定する
101  * @param attacker_ptr プレーヤーへの参照ポインタ
102  * @param pa_ptr 直接攻撃構造体への参照ポインタ
103  * @param chance 基本命中値
104  * @return なし
105  */
106 static bool decide_attack_hit(player_type *attacker_ptr, player_attack_type *pa_ptr, int chance)
107 {
108     bool success_hit = FALSE;
109     object_type *o_ptr = &attacker_ptr->inventory_list[INVEN_RARM + pa_ptr->hand];
110     monster_race *r_ptr = &r_info[pa_ptr->m_ptr->r_idx];
111     if (((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) || (pa_ptr->mode == HISSATSU_KYUSHO)) {
112         int n = 1;
113
114         if (attacker_ptr->right_hand_weapon && attacker_ptr->left_hand_weapon)
115             n *= 2;
116
117         if (pa_ptr->mode == HISSATSU_3DAN)
118             n *= 2;
119
120         success_hit = one_in_(n);
121     } else if ((attacker_ptr->pclass == CLASS_NINJA) && ((pa_ptr->backstab || pa_ptr->surprise_attack) && !(r_ptr->flagsr & RFR_RES_ALL)))
122         success_hit = TRUE;
123     else
124         success_hit = test_hit_norm(attacker_ptr, chance, r_ptr->ac, pa_ptr->m_ptr->ml);
125
126     if ((pa_ptr->mode == HISSATSU_MAJIN) && one_in_(2))
127         success_hit = FALSE;
128
129     return success_hit;
130 }
131
132 /*!
133  * @brief 直接攻撃の命中を処理するメインルーチン
134  * @param attacker_ptr プレーヤーへの参照ポインタ
135  * @param pa_ptr 直接攻撃構造体への参照ポインタ
136  * @param chance 基本命中値
137  * @return 当たればTRUE、外れればFALSE
138  */
139 bool process_attack_hit(player_type *attacker_ptr, player_attack_type *pa_ptr, int chance)
140 {
141     object_type *o_ptr = &attacker_ptr->inventory_list[INVEN_RARM + pa_ptr->hand];
142     if (decide_attack_hit(attacker_ptr, pa_ptr, chance))
143         return TRUE;
144
145     pa_ptr->backstab = FALSE; /* Clumsy! */
146     pa_ptr->surprise_attack = FALSE; /* Clumsy! */
147
148     if ((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE) && one_in_(3)) {
149         process_death_scythe_reflection(attacker_ptr, pa_ptr);
150     } else {
151         sound(SOUND_MISS);
152         msg_format(_("ミス! %sにかわされた。", "You miss %s."), pa_ptr->m_name);
153     }
154
155     return FALSE;
156 }