OSDN Git Service

[Refactor] #40399 Separarted object-sort.c/h from object2.c/h
authorHourier <hourier@users.sourceforge.jp>
Wed, 3 Jun 2020 10:51:13 +0000 (19:51 +0900)
committerHourier <hourier@users.sourceforge.jp>
Wed, 3 Jun 2020 10:51:13 +0000 (19:51 +0900)
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/inventory/inventory-object.c
src/io/load.c
src/object/object2.c
src/object/object2.h
src/store/store.c
src/util/object-sort.c [new file with mode: 0644]
src/util/object-sort.h [new file with mode: 0644]

index 802e8fa..ea1a157 100644 (file)
     <ClCompile Include="..\..\src\spell\spells2.c" />\r
     <ClCompile Include="..\..\src\spell\spells3.c" />\r
     <ClCompile Include="..\..\src\io\uid-checker.c" />\r
+    <ClCompile Include="..\..\src\util\object-sort.c" />\r
     <ClCompile Include="..\..\src\view\display-birth.c" />\r
     <ClCompile Include="..\..\src\view\display-characteristic.c" />\r
     <ClCompile Include="..\..\src\view\display-fruit.c" />\r
     <ClInclude Include="..\..\src\combat\melee-postprocess.h" />\r
     <ClInclude Include="..\..\src\combat\shoot.h" />\r
     <ClInclude Include="..\..\src\core\show-file.h" />\r
+    <ClInclude Include="..\..\src\util\object-sort.h" />\r
     <ClInclude Include="..\..\src\view\display-birth.h" />\r
     <ClInclude Include="..\..\src\view\object-describer.h" />\r
     <ClInclude Include="..\..\src\world\world-object.h" />\r
index 857be39..4903bbd 100644 (file)
     <ClCompile Include="..\..\src\object\object-value-calc.c">
       <Filter>object</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\util\object-sort.c">
+      <Filter>util</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\cmd\cmd-basic.h">
     <ClInclude Include="..\..\src\object\object-value-calc.h">
       <Filter>object</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\util\object-sort.h">
+      <Filter>util</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 0585122..e1c134d 100644 (file)
@@ -422,6 +422,7 @@ hengband_SOURCES = \
        term/z-term.c term/z-term.h term/z-util.c term/z-util.h \
        term/z-virt.c term/z-virt.h \
        \
+       util/object-sort.c util/object-sort.h \
        util/util.c util/util.h \
        \
        view/display-characteristic.c view/display-characteristic.h \
index b7e4309..153d4f9 100644 (file)
@@ -7,6 +7,7 @@
 #include "object/object-value.h"
 #include "object/object2.h"
 #include "player/player-effects.h" // 暫定、相互参照している.
+#include "util/object-sort.h"
 #include "view/object-describer.h"
 
 void vary_item(player_type *owner_ptr, INVENTORY_IDX item, ITEM_NUMBER num)
index ee9eed9..fd4cf12 100644 (file)
@@ -91,6 +91,7 @@
 #include "store/store.h"
 #include "system/angband-version.h"
 #include "system/system-variables.h" // 暫定、init_flags の扱いを決めた上で消す.
+#include "util/object-sort.h"
 #include "util/util.h"
 #include "world/world-object.h"
 #include "world/world.h"
index b498b98..50d735f 100644 (file)
@@ -295,77 +295,3 @@ void object_absorb(object_type *o_ptr, object_type *j_ptr)
        }
 }
 
-
-/*!
- * @brief オブジェクトを定義された基準に従いソートするための関数 /
- * Check if we have space for an item in the pack without overflow
- * @param o_ptr 比較対象オブジェクトの構造体参照ポインタ1
- * @param o_value o_ptrのアイテム価値(手動であらかじめ代入する必要がある?)
- * @param j_ptr 比較対象オブジェクトの構造体参照ポインタ2
- * @return o_ptrの方が上位ならばTRUEを返す。
- */
-bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr)
-{
-       int o_type, j_type;
-       if (!j_ptr->k_idx) return TRUE;
-
-       if ((o_ptr->tval == REALM1_BOOK) &&
-               (j_ptr->tval != REALM1_BOOK)) return TRUE;
-       if ((j_ptr->tval == REALM1_BOOK) &&
-               (o_ptr->tval != REALM1_BOOK)) return FALSE;
-
-       if ((o_ptr->tval == REALM2_BOOK) &&
-               (j_ptr->tval != REALM2_BOOK)) return TRUE;
-       if ((j_ptr->tval == REALM2_BOOK) &&
-               (o_ptr->tval != REALM2_BOOK)) return FALSE;
-
-       if (o_ptr->tval > j_ptr->tval) return TRUE;
-       if (o_ptr->tval < j_ptr->tval) return FALSE;
-
-       if (!object_is_aware(o_ptr)) return FALSE;
-       if (!object_is_aware(j_ptr)) return TRUE;
-
-       if (o_ptr->sval < j_ptr->sval) return TRUE;
-       if (o_ptr->sval > j_ptr->sval) return FALSE;
-
-       if (!object_is_known(o_ptr)) return FALSE;
-       if (!object_is_known(j_ptr)) return TRUE;
-
-       if (object_is_fixed_artifact(o_ptr)) o_type = 3;
-       else if (o_ptr->art_name) o_type = 2;
-       else if (object_is_ego(o_ptr)) o_type = 1;
-       else o_type = 0;
-
-       if (object_is_fixed_artifact(j_ptr)) j_type = 3;
-       else if (j_ptr->art_name) j_type = 2;
-       else if (object_is_ego(j_ptr)) j_type = 1;
-       else j_type = 0;
-
-       if (o_type < j_type) return TRUE;
-       if (o_type > j_type) return FALSE;
-
-       switch (o_ptr->tval)
-       {
-       case TV_FIGURINE:
-       case TV_STATUE:
-       case TV_CORPSE:
-       case TV_CAPTURE:
-               if (r_info[o_ptr->pval].level < r_info[j_ptr->pval].level) return TRUE;
-               if ((r_info[o_ptr->pval].level == r_info[j_ptr->pval].level) && (o_ptr->pval < j_ptr->pval)) return TRUE;
-               return FALSE;
-
-       case TV_SHOT:
-       case TV_ARROW:
-       case TV_BOLT:
-               if (o_ptr->to_h + o_ptr->to_d < j_ptr->to_h + j_ptr->to_d) return TRUE;
-               if (o_ptr->to_h + o_ptr->to_d > j_ptr->to_h + j_ptr->to_d) return FALSE;
-               break;
-
-       case TV_ROD:
-               if (o_ptr->pval < j_ptr->pval) return TRUE;
-               if (o_ptr->pval > j_ptr->pval) return FALSE;
-               break;
-       }
-
-       return o_value > object_value(j_ptr);
-}
index f021309..8da6215 100644 (file)
@@ -12,4 +12,3 @@ void reduce_charges(object_type *o_ptr, int amt);
 int object_similar_part(object_type *o_ptr, object_type *j_ptr);
 bool object_similar(object_type *o_ptr, object_type *j_ptr);
 void object_absorb(object_type *o_ptr, object_type *j_ptr);
-bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr);
index 1b5ff10..cf91f15 100644 (file)
@@ -65,6 +65,7 @@
 #include "store/store-util.h"
 #include "system/angband.h"
 #include "term/gameterm.h"
+#include "util/object-sort.h"
 #include "util/util.h"
 #include "view/display-main-window.h"
 #include "view/object-describer.h"
diff --git a/src/util/object-sort.c b/src/util/object-sort.c
new file mode 100644 (file)
index 0000000..2308a0a
--- /dev/null
@@ -0,0 +1,108 @@
+/*!
+ * @brief オブジェクトのソート処理
+ * @date 2020/06/03
+ * @author Hourier
+ */
+
+#include "util/object-sort.h"
+#include "object/object-hook.h"
+#include "object/object-value.h"
+#include "perception/object-perception.h"
+
+/*!
+ * @brief オブジェクトを定義された基準に従いソートするための関数 /
+ * Check if we have space for an item in the pack without overflow
+ * @param o_ptr 比較対象オブジェクトの構造体参照ポインタ1
+ * @param o_value o_ptrのアイテム価値(手動であらかじめ代入する必要がある?)
+ * @param j_ptr 比較対象オブジェクトの構造体参照ポインタ2
+ * @return o_ptrの方が上位ならばTRUEを返す。
+ */
+bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr)
+{
+    int o_type, j_type;
+    if (!j_ptr->k_idx)
+        return TRUE;
+
+    if ((o_ptr->tval == REALM1_BOOK) && (j_ptr->tval != REALM1_BOOK))
+        return TRUE;
+    if ((j_ptr->tval == REALM1_BOOK) && (o_ptr->tval != REALM1_BOOK))
+        return FALSE;
+
+    if ((o_ptr->tval == REALM2_BOOK) && (j_ptr->tval != REALM2_BOOK))
+        return TRUE;
+    if ((j_ptr->tval == REALM2_BOOK) && (o_ptr->tval != REALM2_BOOK))
+        return FALSE;
+
+    if (o_ptr->tval > j_ptr->tval)
+        return TRUE;
+    if (o_ptr->tval < j_ptr->tval)
+        return FALSE;
+
+    if (!object_is_aware(o_ptr))
+        return FALSE;
+    if (!object_is_aware(j_ptr))
+        return TRUE;
+
+    if (o_ptr->sval < j_ptr->sval)
+        return TRUE;
+    if (o_ptr->sval > j_ptr->sval)
+        return FALSE;
+
+    if (!object_is_known(o_ptr))
+        return FALSE;
+    if (!object_is_known(j_ptr))
+        return TRUE;
+
+    if (object_is_fixed_artifact(o_ptr))
+        o_type = 3;
+    else if (o_ptr->art_name)
+        o_type = 2;
+    else if (object_is_ego(o_ptr))
+        o_type = 1;
+    else
+        o_type = 0;
+
+    if (object_is_fixed_artifact(j_ptr))
+        j_type = 3;
+    else if (j_ptr->art_name)
+        j_type = 2;
+    else if (object_is_ego(j_ptr))
+        j_type = 1;
+    else
+        j_type = 0;
+
+    if (o_type < j_type)
+        return TRUE;
+    if (o_type > j_type)
+        return FALSE;
+
+    switch (o_ptr->tval) {
+    case TV_FIGURINE:
+    case TV_STATUE:
+    case TV_CORPSE:
+    case TV_CAPTURE:
+        if (r_info[o_ptr->pval].level < r_info[j_ptr->pval].level)
+            return TRUE;
+        if ((r_info[o_ptr->pval].level == r_info[j_ptr->pval].level) && (o_ptr->pval < j_ptr->pval))
+            return TRUE;
+        return FALSE;
+
+    case TV_SHOT:
+    case TV_ARROW:
+    case TV_BOLT:
+        if (o_ptr->to_h + o_ptr->to_d < j_ptr->to_h + j_ptr->to_d)
+            return TRUE;
+        if (o_ptr->to_h + o_ptr->to_d > j_ptr->to_h + j_ptr->to_d)
+            return FALSE;
+        break;
+
+    case TV_ROD:
+        if (o_ptr->pval < j_ptr->pval)
+            return TRUE;
+        if (o_ptr->pval > j_ptr->pval)
+            return FALSE;
+        break;
+    }
+
+    return o_value > object_value(j_ptr);
+}
diff --git a/src/util/object-sort.h b/src/util/object-sort.h
new file mode 100644 (file)
index 0000000..44ffd79
--- /dev/null
@@ -0,0 +1,5 @@
+#pragma once
+
+#include "system/angband.h"
+
+bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr);