OSDN Git Service

[Refactor] struct player_type を class PlayerType に置換。
[hengbandforosx/hengbandosx.git] / src / action / weapon-shield.cpp
1 /*!
2  * @file weapon-shield.cpp
3  * @brief 手装備持ち替え処理実装
4  */
5
6 #include "action/weapon-shield.h"
7 #include "flavor/flavor-describer.h"
8 #include "game-option/birth-options.h"
9 #include "inventory/inventory-object.h"
10 #include "inventory/inventory-slot-types.h"
11 #include "object-hook/hook-weapon.h"
12 #include "player-info/equipment-info.h"
13 #include "player-status/player-hand-types.h"
14 #include "system/object-type-definition.h"
15 #include "system/player-type-definition.h"
16 #include "view/display-messages.h"
17
18 /*!
19  * @brief 持ち替え処理
20  * @param player_ptr プレイヤーへの参照ポインタ
21  * @param item 持ち替えを行いたい装備部位ID
22  */
23 void verify_equip_slot(PlayerType *player_ptr, INVENTORY_IDX item)
24 {
25     object_type *o_ptr, *new_o_ptr;
26     GAME_TEXT o_name[MAX_NLEN];
27
28     if (item == INVEN_MAIN_HAND) {
29         if (!has_melee_weapon(player_ptr, INVEN_SUB_HAND))
30             return;
31
32         o_ptr = &player_ptr->inventory_list[INVEN_SUB_HAND];
33         describe_flavor(player_ptr, o_name, o_ptr, 0);
34
35         if (o_ptr->is_cursed()) {
36             if (o_ptr->allow_two_hands_wielding() && can_two_hands_wielding(player_ptr))
37                 msg_format(_("%sを両手で構えた。", "You are wielding %s with both hands."), o_name);
38             return;
39         }
40
41         new_o_ptr = &player_ptr->inventory_list[INVEN_MAIN_HAND];
42         new_o_ptr->copy_from(o_ptr);
43         inven_item_increase(player_ptr, INVEN_SUB_HAND, -((int)o_ptr->number));
44         inven_item_optimize(player_ptr, INVEN_SUB_HAND);
45         if (o_ptr->allow_two_hands_wielding() && can_two_hands_wielding(player_ptr))
46             msg_format(_("%sを両手で構えた。", "You are wielding %s with both hands."), o_name);
47         else
48             msg_format(_("%sを%sで構えた。", "You are wielding %s in your %s hand."), o_name, (left_hander ? _("左手", "left") : _("右手", "right")));
49         return;
50     }
51
52     if (item != INVEN_SUB_HAND)
53         return;
54
55     o_ptr = &player_ptr->inventory_list[INVEN_MAIN_HAND];
56     if (o_ptr->k_idx)
57         describe_flavor(player_ptr, o_name, o_ptr, 0);
58
59     if (has_melee_weapon(player_ptr, INVEN_MAIN_HAND)) {
60         if (o_ptr->allow_two_hands_wielding() && can_two_hands_wielding(player_ptr))
61             msg_format(_("%sを両手で構えた。", "You are wielding %s with both hands."), o_name);
62
63         return;
64     }
65
66     if ((empty_hands(player_ptr, false) & EMPTY_HAND_MAIN) || o_ptr->is_cursed())
67         return;
68
69     new_o_ptr = &player_ptr->inventory_list[INVEN_SUB_HAND];
70     new_o_ptr->copy_from(o_ptr);
71     inven_item_increase(player_ptr, INVEN_MAIN_HAND, -((int)o_ptr->number));
72     inven_item_optimize(player_ptr, INVEN_MAIN_HAND);
73     msg_format(_("%sを持ち替えた。", "You switched hand of %s."), o_name);
74 }