OSDN Git Service

[feature] ソースファイルをC++に対応
[hengbandforosx/hengbandosx.git] / src / inventory / item-getter.c
index 6b2e67f..e251693 100644 (file)
@@ -61,7 +61,7 @@ static bool check_item_tag_aux(player_type *owner_ptr, item_selection_type *item
     if (!item_tester_okay(owner_ptr, o_ptr, item_selection_ptr->tval) && ((item_selection_ptr->mode & USE_FULL) == 0))
         return FALSE;
 
-    item_selection_ptr->tval = 0;
+    item_selection_ptr->tval = TV_NONE;
     item_tester_hook = NULL;
     command_cmd = 0;
     return TRUE;
@@ -77,20 +77,29 @@ static bool check_item_tag_aux(player_type *owner_ptr, item_selection_type *item
 static bool check_item_tag_inventory(player_type *owner_ptr, item_selection_type *item_selection_ptr, char *prev_tag)
 {
     if ((!item_selection_ptr->inven || (*item_selection_ptr->cp < 0) || (*item_selection_ptr->cp >= INVEN_PACK))
-        && (!item_selection_ptr->equip || (*item_selection_ptr->cp < INVEN_RARM) || (*item_selection_ptr->cp >= INVEN_TOTAL)))
+        && (!item_selection_ptr->equip || (*item_selection_ptr->cp < INVEN_MAIN_HAND) || (*item_selection_ptr->cp >= INVEN_TOTAL)))
         return FALSE;
 
     if (*prev_tag && command_cmd) {
-        if (!get_tag(owner_ptr, &item_selection_ptr->k, *prev_tag, (*item_selection_ptr->cp >= INVEN_RARM) ? USE_EQUIP : USE_INVEN, item_selection_ptr->tval)
-                    || (item_selection_ptr->k < INVEN_RARM)
-                ? !item_selection_ptr->inven
-                : !item_selection_ptr->equip || !get_item_okay(owner_ptr, item_selection_ptr->k, item_selection_ptr->tval)) {
+
+        bool flag = FALSE;
+        item_use_flag use_flag = (*item_selection_ptr->cp >= INVEN_MAIN_HAND) ? USE_EQUIP : USE_INVEN;
+
+        flag |= !get_tag(owner_ptr, &item_selection_ptr->k, *prev_tag, use_flag, item_selection_ptr->tval);
+        flag |= !get_item_okay(owner_ptr, item_selection_ptr->k, item_selection_ptr->tval);
+
+        if (item_selection_ptr->k < INVEN_MAIN_HAND)
+            flag |= !item_selection_ptr->inven;
+        else
+            flag |= !item_selection_ptr->equip;
+
+        if (flag) {
             *prev_tag = '\0';
             return FALSE;
         }
 
         *item_selection_ptr->cp = item_selection_ptr->k;
-        item_selection_ptr->tval = 0;
+        item_selection_ptr->tval = TV_NONE;
         item_tester_hook = NULL;
         command_cmd = 0;
         return TRUE;
@@ -99,7 +108,7 @@ static bool check_item_tag_inventory(player_type *owner_ptr, item_selection_type
     if (!get_item_okay(owner_ptr, *item_selection_ptr->cp, item_selection_ptr->tval))
         return FALSE;
 
-    item_selection_ptr->tval = 0;
+    item_selection_ptr->tval = TV_NONE;
     item_tester_hook = NULL;
     command_cmd = 0;
     return TRUE;
@@ -118,7 +127,7 @@ static bool check_item_tag(player_type *owner_ptr, item_selection_type *item_sel
         return FALSE;
 
     if (item_selection_ptr->mode & USE_FORCE && (*item_selection_ptr->cp == INVEN_FORCE)) {
-        item_selection_ptr->tval = 0;
+        item_selection_ptr->tval = TV_NONE;
         item_tester_hook = NULL;
         command_cmd = 0;
         return TRUE;
@@ -167,12 +176,12 @@ static void test_equipment(player_type *owner_ptr, item_selection_type *item_sel
     if (!use_menu)
         return;
 
-    for (int j = INVEN_RARM; j < INVEN_TOTAL; j++)
-        if (select_ring_slot ? is_ring_slot(j)
+    for (int j = INVEN_MAIN_HAND; j < INVEN_TOTAL; j++)
+        if (owner_ptr->select_ring_slot ? is_ring_slot(j)
                              : item_tester_okay(owner_ptr, &owner_ptr->inventory_list[j], item_selection_ptr->tval) || (item_selection_ptr->mode & USE_FULL))
             item_selection_ptr->max_equip++;
 
-    if (have_two_handed_weapons(owner_ptr) && !(item_selection_ptr->mode & IGNORE_BOTHHAND_SLOT))
+    if (has_two_handed_weapons(owner_ptr) && !(item_selection_ptr->mode & IGNORE_BOTHHAND_SLOT))
         item_selection_ptr->max_equip++;
 }
 
@@ -211,7 +220,7 @@ bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str,
     while ((item_selection_ptr->i1 <= item_selection_ptr->i2) && (!get_item_okay(owner_ptr, item_selection_ptr->i2, item_selection_ptr->tval)))
         item_selection_ptr->i2--;
 
-    item_selection_ptr->e1 = INVEN_RARM;
+    item_selection_ptr->e1 = INVEN_MAIN_HAND;
     item_selection_ptr->e2 = INVEN_TOTAL - 1;
     test_equipment(owner_ptr, item_selection_ptr);
     while ((item_selection_ptr->e1 <= item_selection_ptr->e2) && (!get_item_okay(owner_ptr, item_selection_ptr->e1, item_selection_ptr->tval)))
@@ -220,12 +229,12 @@ bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str,
     while ((item_selection_ptr->e1 <= item_selection_ptr->e2) && (!get_item_okay(owner_ptr, item_selection_ptr->e2, item_selection_ptr->tval)))
         item_selection_ptr->e2--;
 
-    if (item_selection_ptr->equip && have_two_handed_weapons(owner_ptr) && !(item_selection_ptr->mode & IGNORE_BOTHHAND_SLOT)) {
-        if (have_right_hand_weapon(owner_ptr)) {
-            if (item_selection_ptr->e2 < INVEN_LARM)
-                item_selection_ptr->e2 = INVEN_LARM;
-        } else if (have_left_hand_weapon(owner_ptr))
-            item_selection_ptr->e1 = INVEN_RARM;
+    if (item_selection_ptr->equip && has_two_handed_weapons(owner_ptr) && !(item_selection_ptr->mode & IGNORE_BOTHHAND_SLOT)) {
+        if (can_attack_with_main_hand(owner_ptr)) {
+            if (item_selection_ptr->e2 < INVEN_SUB_HAND)
+                item_selection_ptr->e2 = INVEN_SUB_HAND;
+        } else if (can_attack_with_sub_hand(owner_ptr))
+            item_selection_ptr->e1 = INVEN_MAIN_HAND;
     }
 
     if (item_selection_ptr->floor) {
@@ -286,7 +295,7 @@ bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str,
             item_selection_ptr->toggle = !item_selection_ptr->toggle;
         }
 
-        owner_ptr->window |= (PW_INVEN | PW_EQUIP);
+        owner_ptr->window_flags |= (PW_INVEN | PW_EQUIP);
         handle_stuff(owner_ptr);
 
         if (!command_wrk) {
@@ -300,9 +309,10 @@ bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str,
         if (!command_wrk) {
             sprintf(item_selection_ptr->out_val, _("持ち物:", "Inven:"));
             if ((item_selection_ptr->i1 <= item_selection_ptr->i2) && !use_menu) {
-                sprintf(item_selection_ptr->tmp_val, _("%c-%c,'(',')',", " %c-%c,'(',')',"), index_to_label(item_selection_ptr->i1),
+                char tmp_val[80];
+                sprintf(tmp_val, _("%c-%c,'(',')',", " %c-%c,'(',')',"), index_to_label(item_selection_ptr->i1),
                     index_to_label(item_selection_ptr->i2));
-                strcat(item_selection_ptr->out_val, item_selection_ptr->tmp_val);
+                strcat(item_selection_ptr->out_val, tmp_val);
             }
 
             if (!command_see && !use_menu)
@@ -313,9 +323,10 @@ bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str,
         } else {
             sprintf(item_selection_ptr->out_val, _("装備品:", "Equip:"));
             if ((item_selection_ptr->e1 <= item_selection_ptr->e2) && !use_menu) {
-                sprintf(item_selection_ptr->tmp_val, _("%c-%c,'(',')',", " %c-%c,'(',')',"), index_to_label(item_selection_ptr->e1),
+                char tmp_val[80];
+                sprintf(tmp_val, _("%c-%c,'(',')',", " %c-%c,'(',')',"), index_to_label(item_selection_ptr->e1),
                     index_to_label(item_selection_ptr->e2));
-                strcat(item_selection_ptr->out_val, item_selection_ptr->tmp_val);
+                strcat(item_selection_ptr->out_val, tmp_val);
             }
 
             if (!command_see && !use_menu)
@@ -326,7 +337,7 @@ bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str,
         }
 
         if (item_selection_ptr->allow_floor)
-            strcat(item_selection_ptr->out_val, _(" '-'床上,", " - for item_selection_ptr->floor,"));
+            strcat(item_selection_ptr->out_val, _(" '-'床上,", " - for floor,"));
 
         if (item_selection_ptr->mode & USE_FORCE)
             strcat(item_selection_ptr->out_val, _(" 'w'練気術,", " w for the Force,"));
@@ -467,7 +478,8 @@ bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str,
                         continue;
 
                     item_selection_ptr->k = 0 - item_selection_ptr->this_o_idx;
-                    if (other_query_flag && !verify(owner_ptr, _("本当に", "Try"), item_selection_ptr->k) || !get_item_allow(owner_ptr, item_selection_ptr->k))
+                    if ((other_query_flag && !verify(owner_ptr, _("本当に", "Try"), item_selection_ptr->k))
+                        || !get_item_allow(owner_ptr, item_selection_ptr->k))
                         continue;
 
                     *item_selection_ptr->cp = item_selection_ptr->k;
@@ -498,7 +510,7 @@ bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str,
                 break;
             }
 
-            if ((item_selection_ptr->k < INVEN_RARM) ? !item_selection_ptr->inven : !item_selection_ptr->equip) {
+            if ((item_selection_ptr->k < INVEN_MAIN_HAND) ? !item_selection_ptr->inven : !item_selection_ptr->equip) {
                 bell();
                 break;
             }
@@ -533,7 +545,7 @@ bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str,
             bool not_found = FALSE;
             if (!get_tag(owner_ptr, &item_selection_ptr->k, item_selection_ptr->which, command_wrk ? USE_EQUIP : USE_INVEN, item_selection_ptr->tval)) {
                 not_found = TRUE;
-            } else if ((item_selection_ptr->k < INVEN_RARM) ? !item_selection_ptr->inven : !item_selection_ptr->equip) {
+            } else if ((item_selection_ptr->k < INVEN_MAIN_HAND) ? !item_selection_ptr->inven : !item_selection_ptr->equip) {
                 not_found = TRUE;
             } else if (!get_item_okay(owner_ptr, item_selection_ptr->k, item_selection_ptr->tval)) {
                 not_found = TRUE;
@@ -593,12 +605,12 @@ bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str,
         command_see = FALSE;
     }
 
-    item_selection_ptr->tval = 0;
+    item_selection_ptr->tval = TV_NONE;
     item_tester_hook = NULL;
     if (item_selection_ptr->toggle)
         toggle_inventory_equipment(owner_ptr);
 
-    owner_ptr->window |= (PW_INVEN | PW_EQUIP);
+    owner_ptr->window_flags |= (PW_INVEN | PW_EQUIP);
     handle_stuff(owner_ptr);
     prt("", 0, 0);
     if (item_selection_ptr->oops && str)