OSDN Git Service

[Refactor] object_is_orthodox_melee_weapons() を 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 "broken weapon"
13  * @param o_ptr オブジェクトの構造体の参照ポインタ。
14  * @return 修復対象になるならTRUEを返す。
15  */
16 bool object_is_broken_weapon(const object_type *o_ptr)
17 {
18     if (o_ptr->tval != TV_SWORD)
19         return false;
20
21     switch (o_ptr->sval) {
22     case SV_BROKEN_DAGGER:
23     case SV_BROKEN_SWORD:
24         return true;
25     }
26
27     return false;
28 }
29
30 /*!
31  * @brief オブジェクトが投射可能な武器かどうかを返す。
32  * @param o_ptr 判定するオブジェクトの構造体参照ポインタ
33  * @return 投射可能な武器ならばTRUE
34  */
35 bool object_is_boomerang(const object_type *o_ptr)
36 {
37     if ((o_ptr->tval == TV_DIGGING) || (o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM) || (o_ptr->tval == TV_HAFTED))
38         return true;
39
40     return false;
41 }
42
43 /*!
44  * @brief オブジェクトがどちらの手にも装備できる武器かどうかの判定
45  * @param o_ptr 判定するオブジェクトの構造体参照ポインタ
46  * @return 左右両方の手で装備できるならばTRUEを返す。
47  */
48 bool object_is_mochikae(const object_type *o_ptr)
49 {
50     /* Check for a usable slot */
51     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))
52         return true;
53
54     return false;
55 }
56
57 /*!
58  * @brief オブジェクトがプレイヤーの職業に応じた適正武器か否かを返す / Favorite weapons
59  * @param o_ptr 対象のオブジェクト構造体ポインタ
60  * @return オブジェクトが適正武器ならばTRUEを返す
61  */
62 bool object_is_favorite(player_type *player_ptr, const object_type *o_ptr)
63 {
64     /* Only melee weapons match */
65     if (!(o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)) {
66         return false;
67     }
68
69     /* Favorite weapons are varied depend on the class */
70     switch (player_ptr->pclass) {
71     case CLASS_PRIEST: {
72         TrFlags flgs;
73         object_flags_known(o_ptr, flgs);
74
75         if (!has_flag(flgs, TR_BLESSED) && !(o_ptr->tval == TV_HAFTED))
76             return false;
77         break;
78     }
79
80     case CLASS_MONK:
81     case CLASS_FORCETRAINER:
82         /* Icky to wield? */
83         if (!(s_info[player_ptr->pclass].w_max[o_ptr->tval - TV_WEAPON_BEGIN][o_ptr->sval]))
84             return false;
85         break;
86
87     case CLASS_BEASTMASTER:
88     case CLASS_CAVALRY: {
89         TrFlags flgs;
90         object_flags_known(o_ptr, flgs);
91
92         /* Is it known to be suitable to using while riding? */
93         if (!(has_flag(flgs, TR_RIDING)))
94             return false;
95
96         break;
97     }
98
99     case CLASS_SORCERER:
100         if (s_info[player_ptr->pclass].w_max[o_ptr->tval - TV_WEAPON_BEGIN][o_ptr->sval] < WEAPON_EXP_MASTER)
101             return false;
102         break;
103
104     case CLASS_NINJA:
105         /* Icky to wield? */
106         if (s_info[player_ptr->pclass].w_max[o_ptr->tval - TV_WEAPON_BEGIN][o_ptr->sval] <= WEAPON_EXP_BEGINNER)
107             return false;
108         break;
109
110     default:
111         /* All weapons are okay for non-special classes */
112         return true;
113     }
114
115     return true;
116 }
117
118 /*!
119  * @brief オブジェクトが強化不能武器であるかを返す / Poison needle can not be enchanted
120  * @param o_ptr 対象のオブジェクト構造体ポインタ
121  * @return 強化不能ならばTRUEを返す
122  */
123 bool object_refuse_enchant_weapon(const object_type *o_ptr)
124 {
125     if (o_ptr->tval == TV_SWORD && o_ptr->sval == SV_POISON_NEEDLE)
126         return true;
127
128     return false;
129 }
130
131 /*!
132  * @brief オブジェクトが強化可能武器であるかを返す /
133  * Check if an object is weapon (including bows and ammo) and allows enchantment
134  * @param o_ptr 対象のオブジェクト構造体ポインタ
135  * @return 強化可能ならばTRUEを返す
136  */
137 bool object_allow_enchant_weapon(const object_type *o_ptr)
138 {
139     if (o_ptr->is_weapon_ammo() && !object_refuse_enchant_weapon(o_ptr))
140         return true;
141
142     return false;
143 }
144
145 /*!
146  * @brief オブジェクトが強化可能な近接武器であるかを返す /
147  * Check if an object is melee weapon and allows enchantment
148  * @param o_ptr 対象のオブジェクト構造体ポインタ
149  * @return 強化可能な近接武器ならばTRUEを返す
150  */
151 bool object_allow_enchant_melee_weapon(const object_type *o_ptr)
152 {
153     if (o_ptr->is_melee_weapon() && !object_refuse_enchant_weapon(o_ptr))
154         return true;
155
156     return false;
157 }
158
159 /*!
160  * @brief オブジェクトが両手持ち可能な武器かを返す /
161  * Check if an object is melee weapon and allows wielding with two-hands
162  * @param o_ptr 対象のオブジェクト構造体ポインタ
163  * @return 両手持ち可能ならばTRUEを返す
164  */
165 bool object_allow_two_hands_wielding(const object_type *o_ptr)
166 {
167     if (o_ptr->is_melee_weapon() && ((o_ptr->weight > 99) || (o_ptr->tval == TV_POLEARM)))
168         return true;
169
170     return false;
171 }