OSDN Git Service

[Refactor] #1752 PlayerClassTypeをenumからenum classへ変更した
[hengbandforosx/hengbandosx.git] / src / player-info / equipment-info.cpp
1 #include "player-info/equipment-info.h"
2 #include "inventory/inventory-slot-types.h"
3 #include "object-hook/hook-weapon.h"
4 #include "pet/pet-util.h"
5 #include "player-status/player-hand-types.h"
6 #include "system/object-type-definition.h"
7 #include "system/player-type-definition.h"
8 #include "util/bit-flags-calculator.h"
9
10 /*!
11  * @brief プレイヤーが現在右手/左手に武器を持っているか判定する /
12  * @param i 判定する手のID(右手:INVEN_MAIN_HAND 左手:INVEN_SUB_HAND)
13  * @return 持っているならばTRUE
14  */
15 bool has_melee_weapon(player_type *player_ptr, int slot)
16 {
17     const auto o_ptr = &player_ptr->inventory_list[slot];
18     return o_ptr->k_idx && o_ptr->is_melee_weapon();
19 }
20
21 /*!
22  * @brief プレイヤーの現在開いている手の状態を返す
23  * @param riding_control 乗馬中により片手を必要としている状態ならばTRUEを返す。
24  * @return 開いている手のビットフラグ
25  */
26 BIT_FLAGS16 empty_hands(player_type *player_ptr, bool riding_control)
27 {
28     BIT_FLAGS16 status = EMPTY_HAND_NONE;
29     if (!player_ptr->inventory_list[INVEN_MAIN_HAND].k_idx)
30         status |= EMPTY_HAND_MAIN;
31     if (!player_ptr->inventory_list[INVEN_SUB_HAND].k_idx)
32         status |= EMPTY_HAND_SUB;
33
34     if (riding_control && (status != EMPTY_HAND_NONE) && player_ptr->riding && none_bits(player_ptr->pet_extra_flags, PF_TWO_HANDS)) {
35         if (any_bits(status, EMPTY_HAND_SUB))
36             reset_bits(status, EMPTY_HAND_SUB);
37         else if (any_bits(status, EMPTY_HAND_MAIN))
38             reset_bits(status, EMPTY_HAND_MAIN);
39     }
40
41     return status;
42 }
43
44 bool can_two_hands_wielding(player_type *player_ptr)
45 {
46     return !player_ptr->riding || any_bits(player_ptr->pet_extra_flags, PF_TWO_HANDS);
47 }
48
49 /*!
50  * @brief プレイヤーが防具重量制限のある職業時にペナルティを受ける状態にあるかどうかを返す。
51  * @return ペナルティが適用されるならばTRUE。
52  */
53 bool heavy_armor(player_type *player_ptr)
54 {
55     if ((player_ptr->pclass != PlayerClassType::MONK) && (player_ptr->pclass != PlayerClassType::FORCETRAINER) && (player_ptr->pclass != PlayerClassType::NINJA))
56         return false;
57
58     WEIGHT monk_arm_wgt = 0;
59     if (player_ptr->inventory_list[INVEN_MAIN_HAND].tval > ItemKindType::SWORD)
60         monk_arm_wgt += player_ptr->inventory_list[INVEN_MAIN_HAND].weight;
61     if (player_ptr->inventory_list[INVEN_SUB_HAND].tval > ItemKindType::SWORD)
62         monk_arm_wgt += player_ptr->inventory_list[INVEN_SUB_HAND].weight;
63     monk_arm_wgt += player_ptr->inventory_list[INVEN_BODY].weight;
64     monk_arm_wgt += player_ptr->inventory_list[INVEN_HEAD].weight;
65     monk_arm_wgt += player_ptr->inventory_list[INVEN_OUTER].weight;
66     monk_arm_wgt += player_ptr->inventory_list[INVEN_ARMS].weight;
67     monk_arm_wgt += player_ptr->inventory_list[INVEN_FEET].weight;
68
69     return (monk_arm_wgt > (100 + (player_ptr->lev * 4)));
70 }