OSDN Git Service

Merge pull request #1461 from habu1010/feature/object-flags-change-interface
[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         auto flgs = object_flags_known(o_ptr);
27
28         if (!has_flag(flgs, TR_BLESSED) && !(o_ptr->tval == TV_HAFTED))
29             return false;
30         break;
31     }
32
33     case CLASS_MONK:
34     case CLASS_FORCETRAINER:
35         /* Icky to wield? */
36         if (!(s_info[player_ptr->pclass].w_max[o_ptr->tval - TV_WEAPON_BEGIN][o_ptr->sval]))
37             return false;
38         break;
39
40     case CLASS_BEASTMASTER:
41     case CLASS_CAVALRY: {
42         auto flgs = object_flags_known(o_ptr);
43
44         /* Is it known to be suitable to using while riding? */
45         if (!(has_flag(flgs, TR_RIDING)))
46             return false;
47
48         break;
49     }
50
51     case CLASS_SORCERER:
52         if (s_info[player_ptr->pclass].w_max[o_ptr->tval - TV_WEAPON_BEGIN][o_ptr->sval] < WEAPON_EXP_MASTER)
53             return false;
54         break;
55
56     case CLASS_NINJA:
57         /* Icky to wield? */
58         if (s_info[player_ptr->pclass].w_max[o_ptr->tval - TV_WEAPON_BEGIN][o_ptr->sval] <= WEAPON_EXP_BEGINNER)
59             return false;
60         break;
61
62     default:
63         /* All weapons are okay for non-special classes */
64         return true;
65     }
66
67     return true;
68 }