OSDN Git Service

[Refactor] #40236 Separated do_cmd_knowledge_inventory() from cmd-dump.c to cmd-inven...
authorHourier <hourier@users.sourceforge.jp>
Mon, 20 Apr 2020 13:38:02 +0000 (22:38 +0900)
committerHourier <hourier@users.sourceforge.jp>
Mon, 20 Apr 2020 13:38:02 +0000 (22:38 +0900)
Hengband_vcs2017/Hengband/Hengband.vcxproj
Hengband_vcs2017/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/cmd/cmd-dump.c
src/cmd/cmd-inventory.c [new file with mode: 0644]
src/cmd/cmd-inventory.h [new file with mode: 0644]

index 7b4a4cb..f10fde7 100644 (file)
     <ClCompile Include="..\..\src\cmd\cmd-gameoption.c" />\r
     <ClCompile Include="..\..\src\cmd\cmd-help.c" />\r
     <ClCompile Include="..\..\src\cmd\cmd-hissatsu.c" />\r
+    <ClCompile Include="..\..\src\cmd\cmd-inventory.c" />\r
     <ClCompile Include="..\..\src\cmd\cmd-item.c" />\r
     <ClCompile Include="..\..\src\cmd\cmd-macro.c" />\r
     <ClCompile Include="..\..\src\cmd\cmd-magiceat.c" />\r
     <ClInclude Include="..\..\src\cmd\cmd-gameoption.h" />\r
     <ClInclude Include="..\..\src\cmd\cmd-help.h" />\r
     <ClInclude Include="..\..\src\cmd\cmd-hissatsu.h" />\r
+    <ClInclude Include="..\..\src\cmd\cmd-inventory.h" />\r
     <ClInclude Include="..\..\src\cmd\cmd-item.h" />\r
     <ClInclude Include="..\..\src\cmd\cmd-macro.h" />\r
     <ClInclude Include="..\..\src\cmd\cmd-magiceat.h" />\r
index f2c60fc..5afd048 100644 (file)
     <ClCompile Include="..\..\src\market\black-market.c">
       <Filter>market</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\cmd\cmd-inventory.c">
+      <Filter>cmd</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\gamevalue.h" />
     <ClInclude Include="..\..\src\market\black-market.h">
       <Filter>market</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\cmd\cmd-inventory.h">
+      <Filter>cmd</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 5ac6412..8b25979 100644 (file)
@@ -146,7 +146,8 @@ hengband_SOURCES = \
        cmd/cmd-diary.c cmd/cmd-diary.h cmd/cmd-dump.c cmd/cmd-dump.h \
        cmd/cmd-draw.c cmd/cmd-draw.h cmd/cmd-eat.c cmd/cmd-eat.h \
        cmd/cmd-gameoption.c cmd/cmd-gameoption.h cmd/cmd-help.c cmd/cmd-help.h \
-       cmd/cmd-hissatsu.c cmd/cmd-hissatsu.h cmd/cmd-item.c cmd/cmd-item.h \
+       cmd/cmd-hissatsu.c cmd/cmd-hissatsu.h \
+       cmd/cmd-inventory.c cmd/cmd-inventory.h cmd/cmd-item.c cmd/cmd-item.h \
        cmd/lighting-level-table.c cmd/lighting-level-table.h \
        cmd/cmd-magiceat.c cmd/cmd-magiceat.h cmd/cmd-mane.c cmd/cmd-mane.h \
        cmd/cmd-macro.c cmd/cmd-macro.h cmd/cmd-pet.c cmd/cmd-pet.h \
index 8070f55..abf2c82 100644 (file)
@@ -33,6 +33,7 @@
 #include "angband.h"
 #include "cmd/cmd-draw.h"
 #include "cmd/cmd-dump.h"
+#include "cmd/cmd-inventory.h"
 #include "cmd/lighting-level-table.h"
 #include "cmd/cmd-visuals.h"
 #include "term.h"
@@ -654,171 +655,6 @@ void do_cmd_load_screen(void)
        screen_load();
 }
 
-// todo なぜこんな中途半端なところに? defineも…
-concptr inven_res_label = _("                               酸電火冷毒光闇破轟獄因沌劣 盲怖乱痺透命感消復浮",
-       "                               AcElFiCoPoLiDkShSoNtNxCaDi BlFeCfFaSeHlEpSdRgLv");
-
-#define IM_FLAG_STR  _("*", "* ")
-#define HAS_FLAG_STR _("+", "+ ")
-#define NO_FLAG_STR  _("・", ". ")
-
-#define print_im_or_res_flag(IM, RES) \
-{ \
-       fputs(have_flag(flgs, (IM)) ? IM_FLAG_STR : \
-             (have_flag(flgs, (RES)) ? HAS_FLAG_STR : NO_FLAG_STR), fff); \
-}
-
-#define print_flag(TR) \
-{ \
-       fputs(have_flag(flgs, (TR)) ? HAS_FLAG_STR : NO_FLAG_STR, fff); \
-}
-
-
-static void do_cmd_knowledge_inven_aux(player_type *creature_ptr, FILE *fff, object_type *o_ptr, int *j, OBJECT_TYPE_VALUE tval, char *where)
-{
-       GAME_TEXT o_name[MAX_NLEN];
-       BIT_FLAGS flgs[TR_FLAG_SIZE];
-       if (!o_ptr->k_idx) return;
-       if (o_ptr->tval != tval) return;
-       if (!object_is_known(o_ptr)) return;
-
-       bool is_special_item_type = (object_is_wearable(o_ptr) && object_is_ego(o_ptr))
-               || ((tval == TV_AMULET) && (o_ptr->sval == SV_AMULET_RESISTANCE))
-               || ((tval == TV_RING) && (o_ptr->sval == SV_RING_LORDLY))
-               || ((tval == TV_SHIELD) && (o_ptr->sval == SV_DRAGON_SHIELD))
-               || ((tval == TV_HELM) && (o_ptr->sval == SV_DRAGON_HELM))
-               || ((tval == TV_GLOVES) && (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES))
-               || ((tval == TV_BOOTS) && (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE))
-               || object_is_artifact(o_ptr);
-       if (!is_special_item_type)
-       {
-               return;
-       }
-
-       int i = 0;
-       object_desc(creature_ptr, o_name, o_ptr, OD_NAME_ONLY);
-       while (o_name[i] && (i < 26))
-       {
-#ifdef JP
-               if (iskanji(o_name[i])) i++;
-#endif
-               i++;
-       }
-
-       if (i < 28)
-       {
-               while (i < 28)
-               {
-                       o_name[i] = ' '; i++;
-               }
-       }
-
-       o_name[i] = '\0';
-
-       fprintf(fff, "%s %s", where, o_name);
-
-       if (!OBJECT_IS_FULL_KNOWN(o_ptr))
-       {
-               fputs(_("-------不明--------------- -------不明---------\n",
-                       "-------unknown------------ -------unknown------\n"), fff);
-       }
-       else
-       {
-               object_flags_known(o_ptr, flgs);
-
-               print_im_or_res_flag(TR_IM_ACID, TR_RES_ACID);
-               print_im_or_res_flag(TR_IM_ELEC, TR_RES_ELEC);
-               print_im_or_res_flag(TR_IM_FIRE, TR_RES_FIRE);
-               print_im_or_res_flag(TR_IM_COLD, TR_RES_COLD);
-               print_flag(TR_RES_POIS);
-               print_flag(TR_RES_LITE);
-               print_flag(TR_RES_DARK);
-               print_flag(TR_RES_SHARDS);
-               print_flag(TR_RES_SOUND);
-               print_flag(TR_RES_NETHER);
-               print_flag(TR_RES_NEXUS);
-               print_flag(TR_RES_CHAOS);
-               print_flag(TR_RES_DISEN);
-
-               fputs(" ", fff);
-
-               print_flag(TR_RES_BLIND);
-               print_flag(TR_RES_FEAR);
-               print_flag(TR_RES_CONF);
-               print_flag(TR_FREE_ACT);
-               print_flag(TR_SEE_INVIS);
-               print_flag(TR_HOLD_EXP);
-               print_flag(TR_TELEPATHY);
-               print_flag(TR_SLOW_DIGEST);
-               print_flag(TR_REGEN);
-               print_flag(TR_LEVITATION);
-
-               fputc('\n', fff);
-       }
-
-       (*j)++;
-       if (*j == 9)
-       {
-               *j = 0;
-               fprintf(fff, "%s\n", inven_res_label);
-       }
-}
-
-/*
- * Display *ID* ed weapons/armors's resistances
- */
-static void do_cmd_knowledge_inven(player_type *creature_ptr)
-{
-       FILE *fff;
-       GAME_TEXT file_name[1024];
-       store_type *store_ptr;
-       OBJECT_TYPE_VALUE tval;
-       int j = 0;
-
-       char where[32];
-       fff = my_fopen_temp(file_name, 1024);
-       if (!fff)
-       {
-               msg_format(_("一時ファイル %s を作成できませんでした。", "Failed to create temporary file %s."), file_name);
-               msg_print(NULL);
-               return;
-       }
-
-       fprintf(fff, "%s\n", inven_res_label);
-       for (tval = TV_WEARABLE_BEGIN; tval <= TV_WEARABLE_END; tval++)
-       {
-               if (j != 0)
-               {
-                       for (; j < 9; j++) fputc('\n', fff);
-                       j = 0;
-                       fprintf(fff, "%s\n", inven_res_label);
-               }
-
-               strcpy(where, _("装", "E "));
-               for (int i = INVEN_RARM; i < INVEN_TOTAL; i++)
-               {
-                       do_cmd_knowledge_inven_aux(creature_ptr, fff, &creature_ptr->inventory_list[i], &j, tval, where);
-               }
-
-               strcpy(where, _("持", "I "));
-               for (int i = 0; i < INVEN_PACK; i++)
-               {
-                       do_cmd_knowledge_inven_aux(creature_ptr, fff, &creature_ptr->inventory_list[i], &j, tval, where);
-               }
-
-               store_ptr = &town_info[1].store[STORE_HOME];
-               strcpy(where, _("家", "H "));
-               for (int i = 0; i < store_ptr->stock_num; i++)
-               {
-                       do_cmd_knowledge_inven_aux(creature_ptr, fff, &store_ptr->stock[i], &j, tval, where);
-               }
-       }
-
-       my_fclose(fff);
-       (void)show_file(creature_ptr, TRUE, file_name, _("*鑑定*済み武器/防具の耐性リスト", "Resistances of *identified* equipment"), 0, 0);
-       fd_kill(file_name);
-}
-
 
 void do_cmd_save_screen_html_aux(char *filename, int message)
 {
@@ -3502,7 +3338,7 @@ void do_cmd_knowledge(player_type *creature_ptr)
                        do_cmd_knowledge_home(creature_ptr);
                        break;
                case '9': /* Resist list */
-                       do_cmd_knowledge_inven(creature_ptr);
+                       do_cmd_knowledge_inventory(creature_ptr);
                        break;
                case '0': /* Feature list */
                {
diff --git a/src/cmd/cmd-inventory.c b/src/cmd/cmd-inventory.c
new file mode 100644 (file)
index 0000000..7346aff
--- /dev/null
@@ -0,0 +1,191 @@
+#include "cmd/cmd-inventory.h"
+#include "object-flavor.h"
+#include "market/store-util.h"
+#include "floor-town.h"
+#include "object-hook.h"
+#include "objectkind.h"
+#include "core/show-file.h"
+
+static concptr inven_res_label = _(
+       "                               酸電火冷毒光闇破轟獄因沌劣 盲怖乱痺透命感消復浮",
+       "                               AcElFiCoPoLiDkShSoNtNxCaDi BlFeCfFaSeHlEpSdRgLv");
+
+#define IM_FLAG_STR  _("*", "* ")
+#define HAS_FLAG_STR _("+", "+ ")
+#define NO_FLAG_STR  _("・", ". ")
+
+// todo: 普通の関数に直す
+#define print_im_or_res_flag(IM, RES) \
+{ \
+       fputs(have_flag(flgs, (IM)) ? IM_FLAG_STR : \
+             (have_flag(flgs, (RES)) ? HAS_FLAG_STR : NO_FLAG_STR), fff); \
+}
+
+
+// todo: 普通の関数に直す
+#define print_flag(TR) \
+{ \
+       fputs(have_flag(flgs, (TR)) ? HAS_FLAG_STR : NO_FLAG_STR, fff); \
+}
+
+
+/*!
+ * @brief 
+ * @param creature_ptr
+ * @param fff
+ * @param o_ptr
+ * @param j
+ * @param tval
+ * @param where
+ * @return なし
+ */
+void do_cmd_knowledge_inventory_aux(player_type *creature_ptr, FILE *fff, object_type *o_ptr, int *j, OBJECT_TYPE_VALUE tval, char *where)
+{
+       if (o_ptr->k_idx == 0) return;
+       if (o_ptr->tval != tval) return;
+       if (!object_is_known(o_ptr)) return;
+
+       bool is_special_item_type = (object_is_wearable(o_ptr) && object_is_ego(o_ptr))
+               || ((tval == TV_AMULET) && (o_ptr->sval == SV_AMULET_RESISTANCE))
+               || ((tval == TV_RING) && (o_ptr->sval == SV_RING_LORDLY))
+               || ((tval == TV_SHIELD) && (o_ptr->sval == SV_DRAGON_SHIELD))
+               || ((tval == TV_HELM) && (o_ptr->sval == SV_DRAGON_HELM))
+               || ((tval == TV_GLOVES) && (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES))
+               || ((tval == TV_BOOTS) && (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE))
+               || object_is_artifact(o_ptr);
+       if (!is_special_item_type)
+       {
+               return;
+       }
+
+       int i = 0;
+       GAME_TEXT o_name[MAX_NLEN];
+       object_desc(creature_ptr, o_name, o_ptr, OD_NAME_ONLY);
+       while (o_name[i] && (i < 26))
+       {
+#ifdef JP
+               if (iskanji(o_name[i])) i++;
+#endif
+               i++;
+       }
+
+       if (i < 28)
+       {
+               while (i < 28)
+               {
+                       o_name[i] = ' '; i++;
+               }
+       }
+
+       o_name[i] = '\0';
+
+       fprintf(fff, "%s %s", where, o_name);
+
+       if (!OBJECT_IS_FULL_KNOWN(o_ptr))
+       {
+               fputs(_("-------不明--------------- -------不明---------\n",
+                       "-------unknown------------ -------unknown------\n"), fff);
+       }
+       else
+       {
+               BIT_FLAGS flgs[TR_FLAG_SIZE];
+               object_flags_known(o_ptr, flgs);
+
+               print_im_or_res_flag(TR_IM_ACID, TR_RES_ACID);
+               print_im_or_res_flag(TR_IM_ELEC, TR_RES_ELEC);
+               print_im_or_res_flag(TR_IM_FIRE, TR_RES_FIRE);
+               print_im_or_res_flag(TR_IM_COLD, TR_RES_COLD);
+               print_flag(TR_RES_POIS);
+               print_flag(TR_RES_LITE);
+               print_flag(TR_RES_DARK);
+               print_flag(TR_RES_SHARDS);
+               print_flag(TR_RES_SOUND);
+               print_flag(TR_RES_NETHER);
+               print_flag(TR_RES_NEXUS);
+               print_flag(TR_RES_CHAOS);
+               print_flag(TR_RES_DISEN);
+
+               fputs(" ", fff);
+
+               print_flag(TR_RES_BLIND);
+               print_flag(TR_RES_FEAR);
+               print_flag(TR_RES_CONF);
+               print_flag(TR_FREE_ACT);
+               print_flag(TR_SEE_INVIS);
+               print_flag(TR_HOLD_EXP);
+               print_flag(TR_TELEPATHY);
+               print_flag(TR_SLOW_DIGEST);
+               print_flag(TR_REGEN);
+               print_flag(TR_LEVITATION);
+
+               fputc('\n', fff);
+       }
+
+       (*j)++;
+       if (*j == 9)
+       {
+               *j = 0;
+               fprintf(fff, "%s\n", inven_res_label);
+       }
+}
+
+
+/*
+ * @brief Display *ID* ed weapons/armors's resistances
+ * @param creature_ptr プレーヤーへの参照ポインタ
+ * @return なし
+ */
+void do_cmd_knowledge_inventory(player_type *creature_ptr)
+{
+       FILE *fff;
+       GAME_TEXT file_name[1024];
+
+       char where[32];
+       fff = my_fopen_temp(file_name, 1024);
+       if (!fff)
+       {
+               msg_format(_("一時ファイル %s を作成できませんでした。", "Failed to create temporary file %s."), file_name);
+               msg_print(NULL);
+               return;
+       }
+
+       fprintf(fff, "%s\n", inven_res_label);
+       int j = 0;
+       for (OBJECT_TYPE_VALUE tval = TV_WEARABLE_BEGIN; tval <= TV_WEARABLE_END; tval++)
+       {
+               if (j != 0)
+               {
+                       for (; j < 9; j++)
+                       {
+                               fputc('\n', fff);
+                       }
+
+                       j = 0;
+                       fprintf(fff, "%s\n", inven_res_label);
+               }
+
+               strcpy(where, _("装", "E "));
+               for (int i = INVEN_RARM; i < INVEN_TOTAL; i++)
+               {
+                       do_cmd_knowledge_inventory_aux(creature_ptr, fff, &creature_ptr->inventory_list[i], &j, tval, where);
+               }
+
+               strcpy(where, _("持", "I "));
+               for (int i = 0; i < INVEN_PACK; i++)
+               {
+                       do_cmd_knowledge_inventory_aux(creature_ptr, fff, &creature_ptr->inventory_list[i], &j, tval, where);
+               }
+
+               store_type *store_ptr;
+               store_ptr = &town_info[1].store[STORE_HOME];
+               strcpy(where, _("家", "H "));
+               for (int i = 0; i < store_ptr->stock_num; i++)
+               {
+                       do_cmd_knowledge_inventory_aux(creature_ptr, fff, &store_ptr->stock[i], &j, tval, where);
+               }
+       }
+
+       my_fclose(fff);
+       (void)show_file(creature_ptr, TRUE, file_name, _("*鑑定*済み武器/防具の耐性リスト", "Resistances of *identified* equipment"), 0, 0);
+       fd_kill(file_name);
+}
diff --git a/src/cmd/cmd-inventory.h b/src/cmd/cmd-inventory.h
new file mode 100644 (file)
index 0000000..9f1e09b
--- /dev/null
@@ -0,0 +1,3 @@
+#include "angband.h"
+
+void do_cmd_knowledge_inventory(player_type *creature_ptr);