OSDN Git Service

[Refactor] object_is_wearable() を object_type のメンバ関数化
[hengbandforosx/hengbandosx.git] / src / object-hook / hook-weapon.cpp
1 #include "object-hook/hook-weapon.h"
2 #include "object-enchant/tr-types.h"
3 #include "object-hook/hook-armor.h"
4 #include "object/object-flags.h"
5 #include "player/player-skill.h"
6 #include "sv-definition/sv-weapon-types.h"
7 #include "system/object-type-definition.h"
8 #include "system/player-type-definition.h"
9 #include "util/bit-flags-calculator.h"
10
11 /*!
12  * @brief 武器匠の「武器」鑑定対象になるかを判定する。/ Hook to specify "weapon"
13  * @param o_ptr オブジェクトの構造体の参照ポインタ。
14  * @return 対象になるならTRUEを返す。
15  */
16 bool object_is_orthodox_melee_weapons(const object_type *o_ptr)
17 {
18     switch (o_ptr->tval) {
19     case TV_HAFTED:
20     case TV_POLEARM:
21     case TV_DIGGING: {
22         return true;
23     }
24     case TV_SWORD: {
25         if (o_ptr->sval != SV_POISON_NEEDLE)
26             return true;
27     }
28
29     default:
30         break;
31     }
32
33     return false;
34 }
35
36 /*!
37  * @brief 修復対象となる壊れた武器かを判定する。 / Hook to specify "broken weapon"
38  * @param o_ptr オブジェクトの構造体の参照ポインタ。
39  * @return 修復対象になるならTRUEを返す。
40  */
41 bool object_is_broken_weapon(const object_type *o_ptr)
42 {
43     if (o_ptr->tval != TV_SWORD)
44         return false;
45
46     switch (o_ptr->sval) {
47     case SV_BROKEN_DAGGER:
48     case SV_BROKEN_SWORD:
49         return true;
50     }
51
52     return false;
53 }
54
55 /*!
56  * @brief オブジェクトが投射可能な武器かどうかを返す。
57  * @param o_ptr 判定するオブジェクトの構造体参照ポインタ
58  * @return 投射可能な武器ならばTRUE
59  */
60 bool object_is_boomerang(const object_type *o_ptr)
61 {
62     if ((o_ptr->tval == TV_DIGGING) || (o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM) || (o_ptr->tval == TV_HAFTED))
63         return true;
64
65     return false;
66 }
67
68 /*!
69  * @brief オブジェクトがどちらの手にも装備できる武器かどうかの判定
70  * @param o_ptr 判定するオブジェクトの構造体参照ポインタ
71  * @return 左右両方の手で装備できるならばTRUEを返す。
72  */
73 bool object_is_mochikae(const object_type *o_ptr)
74 {
75     /* Check for a usable slot */
76     if (((o_ptr->tval >= TV_DIGGING) && (o_ptr->tval <= TV_SWORD)) || (o_ptr->tval == TV_SHIELD) || (o_ptr->tval == TV_CAPTURE) || (o_ptr->tval == TV_CARD))
77         return true;
78
79     return false;
80 }
81
82 /*!
83  * @brief オブジェクトがプレイヤーの職業に応じた適正武器か否かを返す / Favorite weapons
84  * @param o_ptr 対象のオブジェクト構造体ポインタ
85  * @return オブジェクトが適正武器ならばTRUEを返す
86  */
87 bool object_is_favorite(player_type *player_ptr, const object_type *o_ptr)
88 {
89     /* Only melee weapons match */
90     if (!(o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)) {
91         return false;
92     }
93
94     /* Favorite weapons are varied depend on the class */
95     switch (player_ptr->pclass) {
96     case CLASS_PRIEST: {
97         TrFlags flgs;
98         object_flags_known(o_ptr, flgs);
99
100         if (!has_flag(flgs, TR_BLESSED) && !(o_ptr->tval == TV_HAFTED))
101             return false;
102         break;
103     }
104
105     case CLASS_MONK:
106     case CLASS_FORCETRAINER:
107         /* Icky to wield? */
108         if (!(s_info[player_ptr->pclass].w_max[o_ptr->tval - TV_WEAPON_BEGIN][o_ptr->sval]))
109             return false;
110         break;
111
112     case CLASS_BEASTMASTER:
113     case CLASS_CAVALRY: {
114         TrFlags flgs;
115         object_flags_known(o_ptr, flgs);
116
117         /* Is it known to be suitable to using while riding? */
118         if (!(has_flag(flgs, TR_RIDING)))
119             return false;
120
121         break;
122     }
123
124     case CLASS_SORCERER:
125         if (s_info[player_ptr->pclass].w_max[o_ptr->tval - TV_WEAPON_BEGIN][o_ptr->sval] < WEAPON_EXP_MASTER)
126             return false;
127         break;
128
129     case CLASS_NINJA:
130         /* Icky to wield? */
131         if (s_info[player_ptr->pclass].w_max[o_ptr->tval - TV_WEAPON_BEGIN][o_ptr->sval] <= WEAPON_EXP_BEGINNER)
132             return false;
133         break;
134
135     default:
136         /* All weapons are okay for non-special classes */
137         return true;
138     }
139
140     return true;
141 }
142
143 /*!
144  * @brief オブジェクトが装備品であるかを返す(object_type::is_wearableに矢弾を含む) / Equipment including all wearable objects and ammo
145  * @param o_ptr 対象のオブジェクト構造体ポインタ
146  * @return 装備品ならばTRUEを返す
147  */
148 bool object_is_equipment(const object_type *o_ptr)
149 {
150     if (TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END)
151         return true;
152
153     return false;
154 }
155
156 /*!
157  * @brief オブジェクトが強化不能武器であるかを返す / Poison needle can not be enchanted
158  * @param o_ptr 対象のオブジェクト構造体ポインタ
159  * @return 強化不能ならばTRUEを返す
160  */
161 bool object_refuse_enchant_weapon(const object_type *o_ptr)
162 {
163     if (o_ptr->tval == TV_SWORD && o_ptr->sval == SV_POISON_NEEDLE)
164         return true;
165
166     return false;
167 }
168
169 /*!
170  * @brief オブジェクトが強化可能武器であるかを返す /
171  * Check if an object is weapon (including bows and ammo) and allows enchantment
172  * @param o_ptr 対象のオブジェクト構造体ポインタ
173  * @return 強化可能ならばTRUEを返す
174  */
175 bool object_allow_enchant_weapon(const object_type *o_ptr)
176 {
177     if (o_ptr->is_weapon_ammo() && !object_refuse_enchant_weapon(o_ptr))
178         return true;
179
180     return false;
181 }
182
183 /*!
184  * @brief オブジェクトが強化可能な近接武器であるかを返す /
185  * Check if an object is melee weapon and allows enchantment
186  * @param o_ptr 対象のオブジェクト構造体ポインタ
187  * @return 強化可能な近接武器ならばTRUEを返す
188  */
189 bool object_allow_enchant_melee_weapon(const object_type *o_ptr)
190 {
191     if (o_ptr->is_melee_weapon() && !object_refuse_enchant_weapon(o_ptr))
192         return true;
193
194     return false;
195 }
196
197 /*!
198  * @brief オブジェクトが両手持ち可能な武器かを返す /
199  * Check if an object is melee weapon and allows wielding with two-hands
200  * @param o_ptr 対象のオブジェクト構造体ポインタ
201  * @return 両手持ち可能ならばTRUEを返す
202  */
203 bool object_allow_two_hands_wielding(const object_type *o_ptr)
204 {
205     if (o_ptr->is_melee_weapon() && ((o_ptr->weight > 99) || (o_ptr->tval == TV_POLEARM)))
206         return true;
207
208     return false;
209 }