OSDN Git Service

[Refactor] #40399 Moved inven_carry() from obejct2.c/h to inventory-object.c/h
authorHourier <hourier@users.sourceforge.jp>
Mon, 1 Jun 2020 15:27:07 +0000 (00:27 +0900)
committerHourier <hourier@users.sourceforge.jp>
Mon, 1 Jun 2020 15:27:07 +0000 (00:27 +0900)
src/cmd-item/cmd-usestaff.c
src/combat/attack-chaos-effect.c
src/inventory/inventory-object.c
src/inventory/inventory-object.h
src/object/object2.c
src/object/object2.h
src/player/player-move.c

index b069725..d6e358e 100644 (file)
@@ -1,6 +1,7 @@
 #include "cmd-item/cmd-usestaff.h"
 #include "cmd/cmd-basic.h"
 #include "floor/floor.h"
+#include "inventory/inventory-object.h"
 #include "inventory/player-inventory.h"
 #include "main/sound-definitions-table.h"
 #include "object/item-use-flags.h"
index 3de0acd..001ad76 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "combat/attack-chaos-effect.h"
 #include "monster/monster-status.h"
+#include "inventory/inventory-object.h"
 #include "object/artifact.h"
 #include "object/object2.h"
 #include "object/object-flavor.h"
index dfa01fa..b98bf45 100644 (file)
@@ -1,5 +1,6 @@
 #include "inventory/inventory-object.h"
 #include "object/object-flavor.h"
+#include "object/object-mark-types.h"
 #include "object/object-value.h"
 #include "object/object2.h" // 暫定、相互参照している.
 #include "player/player-effects.h" // 暫定、相互参照している.
@@ -256,3 +257,85 @@ void reorder_pack(player_type *owner_ptr)
     if (flag)
         msg_print(_("ザックの中のアイテムを並べ直した。", "You reorder some items in your pack."));
 }
+
+/*!
+ * @brief オブジェクトをプレイヤーが拾って所持スロットに納めるメインルーチン /
+ * Add an item to the players inventory, and return the slot used.
+ * @param o_ptr 拾うオブジェクトの構造体参照ポインタ
+ * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
+ * @details
+ * If the new item can combine with an existing item in the inventory,\n
+ * it will do so, using "object_similar()" and "object_absorb()", else,\n
+ * the item will be placed into the "proper" location in the inventory.\n
+ *\n
+ * This function can be used to "over-fill" the player's pack, but only\n
+ * once, and such an action must trigger the "overflow" code immediately.\n
+ * Note that when the pack is being "over-filled", the new item must be\n
+ * placed into the "overflow" slot, and the "overflow" must take place\n
+ * before the pack is reordered, but (optionally) after the pack is\n
+ * combined.  This may be tricky.  See "dungeon.c" for info.\n
+ *\n
+ * Note that this code must remove any location/stack information\n
+ * from the object once it is placed into the inventory.\n
+ */
+s16b inven_carry(player_type *owner_ptr, object_type *o_ptr)
+{
+    INVENTORY_IDX i, j, k;
+    INVENTORY_IDX n = -1;
+
+    object_type *j_ptr;
+    for (j = 0; j < INVEN_PACK; j++) {
+        j_ptr = &owner_ptr->inventory_list[j];
+        if (!j_ptr->k_idx)
+            continue;
+
+        n = j;
+        if (object_similar(j_ptr, o_ptr)) {
+            object_absorb(j_ptr, o_ptr);
+
+            owner_ptr->total_weight += (o_ptr->number * o_ptr->weight);
+            owner_ptr->update |= (PU_BONUS);
+            owner_ptr->window |= (PW_INVEN);
+            return (j);
+        }
+    }
+
+    if (owner_ptr->inven_cnt > INVEN_PACK)
+        return -1;
+
+    for (j = 0; j <= INVEN_PACK; j++) {
+        j_ptr = &owner_ptr->inventory_list[j];
+        if (!j_ptr->k_idx)
+            break;
+    }
+
+    i = j;
+    if (i < INVEN_PACK) {
+        s32b o_value = object_value(o_ptr);
+        for (j = 0; j < INVEN_PACK; j++) {
+            if (object_sort_comp(o_ptr, o_value, &owner_ptr->inventory_list[j]))
+                break;
+        }
+
+        i = j;
+        for (k = n; k >= i; k--) {
+            object_copy(&owner_ptr->inventory_list[k + 1], &owner_ptr->inventory_list[k]);
+        }
+
+        object_wipe(&owner_ptr->inventory_list[i]);
+    }
+
+    object_copy(&owner_ptr->inventory_list[i], o_ptr);
+    j_ptr = &owner_ptr->inventory_list[i];
+    j_ptr->next_o_idx = 0;
+    j_ptr->held_m_idx = 0;
+    j_ptr->iy = j_ptr->ix = 0;
+    j_ptr->marked = OM_TOUCHED;
+
+    owner_ptr->total_weight += (j_ptr->number * j_ptr->weight);
+    owner_ptr->inven_cnt++;
+    owner_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
+    owner_ptr->window |= (PW_INVEN);
+
+    return i;
+}
index 43adf55..f20f98d 100644 (file)
@@ -8,3 +8,4 @@ void inven_item_optimize(player_type *owner_ptr, INVENTORY_IDX item);
 void drop_from_inventory(player_type *owner_type, INVENTORY_IDX item, ITEM_NUMBER amt);
 void combine_pack(player_type *owner_ptr);
 void reorder_pack(player_type *owner_ptr);
+s16b inven_carry(player_type *owner_ptr, object_type *o_ptr);
index d47073a..34ab146 100644 (file)
@@ -3343,91 +3343,6 @@ bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr)
 
 
 /*!
- * @brief オブジェクトをプレイヤーが拾って所持スロットに納めるメインルーチン /
- * Add an item to the players inventory, and return the slot used.
- * @param o_ptr 拾うオブジェクトの構造体参照ポインタ
- * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
- * @details
- * If the new item can combine with an existing item in the inventory,\n
- * it will do so, using "object_similar()" and "object_absorb()", else,\n
- * the item will be placed into the "proper" location in the inventory.\n
- *\n
- * This function can be used to "over-fill" the player's pack, but only\n
- * once, and such an action must trigger the "overflow" code immediately.\n
- * Note that when the pack is being "over-filled", the new item must be\n
- * placed into the "overflow" slot, and the "overflow" must take place\n
- * before the pack is reordered, but (optionally) after the pack is\n
- * combined.  This may be tricky.  See "dungeon.c" for info.\n
- *\n
- * Note that this code must remove any location/stack information\n
- * from the object once it is placed into the inventory.\n
- */
-s16b inven_carry(player_type *owner_ptr, object_type *o_ptr)
-{
-       INVENTORY_IDX i, j, k;
-       INVENTORY_IDX n = -1;
-
-       object_type *j_ptr;
-       for (j = 0; j < INVEN_PACK; j++)
-       {
-               j_ptr = &owner_ptr->inventory_list[j];
-               if (!j_ptr->k_idx) continue;
-
-               n = j;
-               if (object_similar(j_ptr, o_ptr))
-               {
-                       object_absorb(j_ptr, o_ptr);
-
-                       owner_ptr->total_weight += (o_ptr->number * o_ptr->weight);
-                       owner_ptr->update |= (PU_BONUS);
-                       owner_ptr->window |= (PW_INVEN);
-                       return (j);
-               }
-       }
-
-       if (owner_ptr->inven_cnt > INVEN_PACK) return -1;
-
-       for (j = 0; j <= INVEN_PACK; j++)
-       {
-               j_ptr = &owner_ptr->inventory_list[j];
-               if (!j_ptr->k_idx) break;
-       }
-
-       i = j;
-       if (i < INVEN_PACK)
-       {
-               s32b o_value = object_value(o_ptr);
-               for (j = 0; j < INVEN_PACK; j++)
-               {
-                       if (object_sort_comp(o_ptr, o_value, &owner_ptr->inventory_list[j])) break;
-               }
-
-               i = j;
-               for (k = n; k >= i; k--)
-               {
-                       object_copy(&owner_ptr->inventory_list[k + 1], &owner_ptr->inventory_list[k]);
-               }
-
-               object_wipe(&owner_ptr->inventory_list[i]);
-       }
-
-       object_copy(&owner_ptr->inventory_list[i], o_ptr);
-       j_ptr = &owner_ptr->inventory_list[i];
-       j_ptr->next_o_idx = 0;
-       j_ptr->held_m_idx = 0;
-       j_ptr->iy = j_ptr->ix = 0;
-       j_ptr->marked = OM_TOUCHED;
-
-       owner_ptr->total_weight += (j_ptr->number * j_ptr->weight);
-       owner_ptr->inven_cnt++;
-       owner_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
-       owner_ptr->window |= (PW_INVEN);
-
-       return i;
-}
-
-
-/*!
  * @brief 装備スロットからオブジェクトを外すメインルーチン /
  * Take off (some of) a non-cursed equipment item
  * @param owner_ptr プレーヤーへの参照ポインタ
index 9dcdd45..50196ce 100644 (file)
@@ -35,6 +35,5 @@ void floor_item_increase(floor_type *floor_ptr, INVENTORY_IDX item, ITEM_NUMBER
 void floor_item_optimize(player_type *owner_ptr, INVENTORY_IDX item);
 bool inven_carry_okay(object_type *o_ptr);
 bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr);
-s16b inven_carry(player_type *owner_ptr, object_type *o_ptr);
 INVENTORY_IDX inven_takeoff(player_type *owner_ptr, INVENTORY_IDX item, ITEM_NUMBER amt);
 void floor_item_describe(player_type *player_ptr, INVENTORY_IDX item); // 暫定、元々object2.c の内部からのみ呼ばれていた.
index 68bab08..44e369a 100644 (file)
 #include "grid/feature.h"
 #include "grid/grid.h"
 #include "grid/trap.h"
+#include "inventory/inventory-object.h"
 #include "inventory/player-inventory.h"
 #include "io/targeting.h"
 #include "main/sound-definitions-table.h"