OSDN Git Service

[Refactor] #40521 Separated check_item_tag() from get_item()
authorHourier <hourier@users.sourceforge.jp>
Sat, 4 Jul 2020 02:06:29 +0000 (11:06 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sat, 4 Jul 2020 02:07:24 +0000 (11:07 +0900)
src/inventory/floor-item-getter.c
src/inventory/item-getter.c

index 25b0d76..7953962 100644 (file)
 #include "view/display-sub-windows.h"
 
 /*!
+ * todo 適切な関数名をどうしても付けられなかったので暫定でauxとした
  * @brief 床上アイテムへにタグ付けがされているかの調査処理 (のはず)
  * @param owner_ptr プレーヤーへの参照ポインタ
  * @param fis_ptr 床上アイテムへの参照ポインタ
  * @param prev_tag 前回選択したアイテムのタグ (のはず)
  * @return プレイヤーによりアイテムが選択されたならTRUEを返す
  */
-static bool check_item_tag_floor(player_type *owner_ptr, fis_type *fis_ptr, char *prev_tag)
+static bool check_floor_item_tag_aux(player_type *owner_ptr, fis_type *fis_ptr, char *prev_tag)
 {
     if (!fis_ptr->floor || (*fis_ptr->cp >= 0))
         return FALSE;
@@ -72,7 +73,7 @@ static bool check_item_tag_floor(player_type *owner_ptr, fis_type *fis_ptr, char
  * @param prev_tag 前回選択したアイテムのタグ (のはず)
  * @return プレイヤーによりアイテムが選択されたならTRUEを返す
  */
-static bool get_item_tag_inventory(player_type *owner_ptr, fis_type *fis_ptr, char *prev_tag)
+static bool get_floor_item_tag_inventory(player_type *owner_ptr, fis_type *fis_ptr, char *prev_tag)
 {
     if ((*prev_tag == '\0') || !command_cmd)
         return FALSE;
@@ -97,13 +98,13 @@ static bool get_item_tag_inventory(player_type *owner_ptr, fis_type *fis_ptr, ch
  * @param prev_tag 前回選択したアイテムのタグ (のはず)
  * @return プレイヤーによりアイテムが選択されたならTRUEを返す
  */
-static bool check_item_tag_inventory(player_type *owner_ptr, fis_type *fis_ptr, char *prev_tag)
+static bool check_floor_item_tag_inventory(player_type *owner_ptr, fis_type *fis_ptr, char *prev_tag)
 {
     if ((!fis_ptr->inven || (*fis_ptr->cp < 0) || (*fis_ptr->cp >= INVEN_PACK))
         && (!fis_ptr->equip || (*fis_ptr->cp < INVEN_RARM) || (*fis_ptr->cp >= INVEN_TOTAL)))
         return FALSE;
 
-    if (get_item_tag_inventory(owner_ptr, fis_ptr, prev_tag))
+    if (get_floor_item_tag_inventory(owner_ptr, fis_ptr, prev_tag))
         return TRUE;
 
     if (get_item_okay(owner_ptr, *fis_ptr->cp, fis_ptr->tval)) {
@@ -117,13 +118,13 @@ static bool check_item_tag_inventory(player_type *owner_ptr, fis_type *fis_ptr,
 }
 
 /*!
- * @brief アイテムにタグ付けがされているかの調査処理 (のはず)
+ * @brief 床上アイテムにタグ付けがされているかの調査処理 (のはず)
  * @param owner_ptr プレーヤーへの参照ポインタ
  * @param fis_ptr 床上アイテムへの参照ポインタ
  * @param prev_tag 前回選択したアイテムのタグ (のはず)
  * @return プレイヤーによりアイテムが選択されたならTRUEを返す
  */
-static bool check_item_tag(player_type *owner_ptr, fis_type *fis_ptr, char *prev_tag)
+static bool check_floor_item_tag(player_type *owner_ptr, fis_type *fis_ptr, char *prev_tag)
 {
     if (!repeat_pull(fis_ptr->cp))
         return FALSE;
@@ -135,10 +136,10 @@ static bool check_item_tag(player_type *owner_ptr, fis_type *fis_ptr, char *prev
         return TRUE;
     }
 
-    if (check_item_tag_floor(owner_ptr, fis_ptr, prev_tag))
+    if (check_floor_item_tag_aux(owner_ptr, fis_ptr, prev_tag))
         return TRUE;
 
-    return check_item_tag_inventory(owner_ptr, fis_ptr, prev_tag);
+    return check_floor_item_tag_inventory(owner_ptr, fis_ptr, prev_tag);
 }
 
 /*!
@@ -197,7 +198,7 @@ bool get_item_floor(player_type *owner_ptr, COMMAND_CODE *cp, concptr pmt, concp
     fis_type tmp_fis;
     fis_type *fis_ptr = initialize_fis_type(&tmp_fis, cp, mode, tval);
     static char prev_tag = '\0';
-    if (check_item_tag(owner_ptr, fis_ptr, &prev_tag))
+    if (check_floor_item_tag(owner_ptr, fis_ptr, &prev_tag))
         return TRUE;
 
     msg_print(NULL);
index 4861bd0..5155abc 100644 (file)
@@ -41,6 +41,74 @@ static void check_item_selection_mode(item_selection_type *item_selection_ptr)
 }
 
 /*!
+ * @brief アイテムにタグ付けがされているかの調査処理 (のはず)
+ * @param owner_ptr プレーヤーへの参照ポインタ
+ * @param fis_ptr 床上アイテムへの参照ポインタ
+ * @param prev_tag 前回選択したアイテムのタグ (のはず)
+ * @return プレイヤーによりアイテムが選択されたならTRUEを返す
+ */
+static bool check_item_tag(player_type *owner_ptr, item_selection_type *item_selection_ptr, char *prev_tag)
+{
+    if (!repeat_pull(item_selection_ptr->cp))
+        return FALSE;
+
+    if (item_selection_ptr->mode & USE_FORCE && (*item_selection_ptr->cp == INVEN_FORCE)) {
+        item_selection_ptr->tval = 0;
+        item_tester_hook = NULL;
+        command_cmd = 0;
+        return TRUE;
+    }
+    
+    if (item_selection_ptr->floor && (*item_selection_ptr->cp < 0)) {
+        object_type *o_ptr;
+        item_selection_ptr->k = 0 - (*item_selection_ptr->cp);
+        o_ptr = &owner_ptr->current_floor_ptr->o_list[item_selection_ptr->k];
+        if (item_tester_okay(owner_ptr, o_ptr, item_selection_ptr->tval) || (item_selection_ptr->mode & USE_FULL)) {
+            item_selection_ptr->tval = 0;
+            item_tester_hook = NULL;
+            command_cmd = 0;
+            return TRUE;
+        }
+
+        return FALSE;
+    }
+    
+    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))) {
+        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)) /* Reject */
+                ;
+            else if ((item_selection_ptr->k < INVEN_RARM) ? !item_selection_ptr->inven : !item_selection_ptr->equip) /* Reject */
+                ;
+            else if (!get_item_okay(owner_ptr, item_selection_ptr->k, item_selection_ptr->tval)) /* Reject */
+                ;
+            else {
+                *item_selection_ptr->cp = item_selection_ptr->k;
+                item_selection_ptr->tval = 0;
+                item_tester_hook = NULL;
+                command_cmd = 0;
+                return TRUE;
+            }
+
+            *prev_tag = '\0';
+            return FALSE;
+        }
+        
+        if (get_item_okay(owner_ptr, *item_selection_ptr->cp, item_selection_ptr->tval)) {
+            item_selection_ptr->tval = 0;
+            item_tester_hook = NULL;
+            command_cmd = 0;
+            return TRUE;
+        }
+
+        return FALSE;
+    }
+
+    return FALSE;
+}
+
+/*!
  * @brief オブジェクト選択の汎用関数 / General function for the selection of item
  * Let the user select an item, save its "index"
  * @param owner_ptr プレーヤーへの参照ポインタ
@@ -53,54 +121,15 @@ static void check_item_selection_mode(item_selection_type *item_selection_ptr)
  */
 bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str, BIT_FLAGS mode, tval_type tval)
 {
-    static char prev_tag = '\0'; // TODO: repeat_pull の中だけポインタにする
+    static char prev_tag = '\0';
     if (easy_floor || use_menu)
         return get_item_floor(owner_ptr, cp, pmt, str, mode, tval);
 
     item_selection_type tmp_selection;
     item_selection_type *item_selection_ptr = initialize_item_selection_type(&tmp_selection, cp, mode, tval);
     check_item_selection_mode(item_selection_ptr);
-    if (repeat_pull(item_selection_ptr->cp)) {
-        if (item_selection_ptr->mode & USE_FORCE && (*item_selection_ptr->cp == INVEN_FORCE)) {
-            item_selection_ptr->tval = 0;
-            item_tester_hook = NULL;
-            command_cmd = 0;
-            return TRUE;
-        } else if (item_selection_ptr->floor && (*item_selection_ptr->cp < 0)) {
-            object_type *o_ptr;
-            item_selection_ptr->k = 0 - (*item_selection_ptr->cp);
-            o_ptr = &owner_ptr->current_floor_ptr->o_list[item_selection_ptr->k];
-            if (item_tester_okay(owner_ptr, o_ptr, item_selection_ptr->tval) || (item_selection_ptr->mode & USE_FULL)) {
-                item_selection_ptr->tval = 0;
-                item_tester_hook = NULL;
-                command_cmd = 0;
-                return TRUE;
-            }
-        } else 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))) {
-            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)) /* Reject */
-                    ;
-                else if ((item_selection_ptr->k < INVEN_RARM) ? !item_selection_ptr->inven : !item_selection_ptr->equip) /* Reject */
-                    ;
-                else if (!get_item_okay(owner_ptr, item_selection_ptr->k, item_selection_ptr->tval)) /* Reject */
-                    ;
-                else {
-                    *item_selection_ptr->cp = item_selection_ptr->k;
-                    item_selection_ptr->tval = 0;
-                    item_tester_hook = NULL;
-                    command_cmd = 0;
-                    return TRUE;
-                }
-
-                prev_tag = '\0';
-            } else if (get_item_okay(owner_ptr, *item_selection_ptr->cp, item_selection_ptr->tval)) {
-                item_selection_ptr->tval = 0;
-                item_tester_hook = NULL;
-                command_cmd = 0;
-                return TRUE;
-            }
-        }
-    }
+    if (check_item_tag(owner_ptr, item_selection_ptr, &prev_tag))
+        return TRUE;
 
     msg_print(NULL);
     item_selection_ptr->done = FALSE;