OSDN Git Service

[Refactor] object_*_enchant_*() を 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 オブジェクトがプレイヤーの職業に応じた適正武器か否かを返す / Favorite weapons
13  * @param o_ptr 対象のオブジェクト構造体ポインタ
14  * @return オブジェクトが適正武器ならばTRUEを返す
15  */
16 bool object_is_favorite(player_type *player_ptr, const object_type *o_ptr)
17 {
18     /* Only melee weapons match */
19     if (!(o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)) {
20         return false;
21     }
22
23     /* Favorite weapons are varied depend on the class */
24     switch (player_ptr->pclass) {
25     case CLASS_PRIEST: {
26         TrFlags flgs;
27         object_flags_known(o_ptr, flgs);
28
29         if (!has_flag(flgs, TR_BLESSED) && !(o_ptr->tval == TV_HAFTED))
30             return false;
31         break;
32     }
33
34     case CLASS_MONK:
35     case CLASS_FORCETRAINER:
36         /* Icky to wield? */
37         if (!(s_info[player_ptr->pclass].w_max[o_ptr->tval - TV_WEAPON_BEGIN][o_ptr->sval]))
38             return false;
39         break;
40
41     case CLASS_BEASTMASTER:
42     case CLASS_CAVALRY: {
43         TrFlags flgs;
44         object_flags_known(o_ptr, flgs);
45
46         /* Is it known to be suitable to using while riding? */
47         if (!(has_flag(flgs, TR_RIDING)))
48             return false;
49
50         break;
51     }
52
53     case CLASS_SORCERER:
54         if (s_info[player_ptr->pclass].w_max[o_ptr->tval - TV_WEAPON_BEGIN][o_ptr->sval] < WEAPON_EXP_MASTER)
55             return false;
56         break;
57
58     case CLASS_NINJA:
59         /* Icky to wield? */
60         if (s_info[player_ptr->pclass].w_max[o_ptr->tval - TV_WEAPON_BEGIN][o_ptr->sval] <= WEAPON_EXP_BEGINNER)
61             return false;
62         break;
63
64     default:
65         /* All weapons are okay for non-special classes */
66         return true;
67     }
68
69     return true;
70 }
71
72 /*!
73  * @brief オブジェクトが両手持ち可能な武器かを返す /
74  * Check if an object is melee weapon and allows wielding with two-hands
75  * @param o_ptr 対象のオブジェクト構造体ポインタ
76  * @return 両手持ち可能ならばTRUEを返す
77  */
78 bool object_allow_two_hands_wielding(const object_type *o_ptr)
79 {
80     if (o_ptr->is_melee_weapon() && ((o_ptr->weight > 99) || (o_ptr->tval == TV_POLEARM)))
81         return true;
82
83     return false;
84 }