From 12beb3f30234bf418144719b925af79aea6c22d6 Mon Sep 17 00:00:00 2001 From: Hourier Date: Thu, 23 Apr 2020 22:11:35 +0900 Subject: [PATCH] [Refactor] #40236 Separated knowledge-artifacts.c/h from cmd-dump.c --- Hengband_vcs2017/Hengband/Hengband.vcxproj | 2 + Hengband_vcs2017/Hengband/Hengband.vcxproj.filters | 9 ++ src/Makefile.am | 4 +- src/cmd/cmd-dump.c | 96 +------------------- src/knowledge/knowledge-artifacts.c | 101 +++++++++++++++++++++ src/knowledge/knowledge-artifacts.h | 3 + 6 files changed, 121 insertions(+), 94 deletions(-) create mode 100644 src/knowledge/knowledge-artifacts.c create mode 100644 src/knowledge/knowledge-artifacts.h diff --git a/Hengband_vcs2017/Hengband/Hengband.vcxproj b/Hengband_vcs2017/Hengband/Hengband.vcxproj index bf6ea0e5e..6b9a89180 100644 --- a/Hengband_vcs2017/Hengband/Hengband.vcxproj +++ b/Hengband_vcs2017/Hengband/Hengband.vcxproj @@ -154,6 +154,7 @@ + @@ -280,6 +281,7 @@ + diff --git a/Hengband_vcs2017/Hengband/Hengband.vcxproj.filters b/Hengband_vcs2017/Hengband/Hengband.vcxproj.filters index 58b41c102..e6f22b8ba 100644 --- a/Hengband_vcs2017/Hengband/Hengband.vcxproj.filters +++ b/Hengband_vcs2017/Hengband/Hengband.vcxproj.filters @@ -598,6 +598,9 @@ cmd + + knowledge + @@ -1178,6 +1181,9 @@ cmd + + knowledge + @@ -1226,6 +1232,9 @@ {e8e836da-e12b-42cc-9c09-17432cb83432} + + {0e8eb37a-0944-4897-a2fd-e6097df5e5f8} + diff --git a/src/Makefile.am b/src/Makefile.am index 0a817588c..b7b332c63 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -148,6 +148,8 @@ hengband_SOURCES = \ z-form.c z-form.h z-rand.c z-rand.h z-term.c z-term.h z-util.c z-util.h \ z-virt.c z-virt.h \ \ + knowledge/knowledge-artifacts.c knowledge/knowledge-artifacts.h \ + \ cmd/dump-util.c cmd/dump-util.h cmd/feeling-table.c cmd/feeling-table.h \ cmd/monster-group-table.c cmd/monster-group-table.h \ cmd/diary-subtitle-table.c cmd/diary-subtitle-table.h \ @@ -180,7 +182,7 @@ EXTRA_DIST = \ CFLAGS += $(XFT_CFLAGS) LIBS += $(XFT_LIBS) COMPILE = $(srcdir)/gcc-wrap $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -Icmd -Icombat -Icore -Iio -Imarket -Imonster -Iplayer -Iview + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -Icmd -Icombat -Icore -Iio -Iknowledge -Imarket -Imonster -Iplayer -Iview install-exec-hook: if SET_GID diff --git a/src/cmd/cmd-dump.c b/src/cmd/cmd-dump.c index 8424e03fa..e6da88931 100644 --- a/src/cmd/cmd-dump.c +++ b/src/cmd/cmd-dump.c @@ -42,6 +42,9 @@ #include "core/show-file.h" #include "io/read-pref-file.h" #include "io/interpret-pref-file.h" + +#include "knowledge/knowledge-artifacts.h" + #include "autopick.h" #include "birth.h" #include "dungeon.h" @@ -566,99 +569,6 @@ static FEAT_IDX collect_features(FEAT_IDX *feat_idx, BIT_FLAGS8 mode) /* - * todo okay = 既知のアーティファクト? と思われるが確証がない - * 分かりやすい変数名へ変更求む&万が一未知である旨の配列なら負論理なのでゴソッと差し替えるべき - * Check the status of "artifacts" - * @param player_ptr プレーヤーへの参照ポインタ - * @return なし - */ -static void do_cmd_knowledge_artifacts(player_type *player_ptr) -{ - FILE *fff = NULL; - GAME_TEXT file_name[FILE_NAME_SIZE]; - if (!open_temporary_file(&fff, file_name)) return; - - ARTIFACT_IDX *who; - C_MAKE(who, max_a_idx, ARTIFACT_IDX); - bool *okay; - C_MAKE(okay, max_a_idx, bool); - - for (ARTIFACT_IDX k = 0; k < max_a_idx; k++) - { - artifact_type *a_ptr = &a_info[k]; - okay[k] = FALSE; - if (!a_ptr->name) continue; - if (!a_ptr->cur_num) continue; - - okay[k] = TRUE; - } - - for (POSITION y = 0; y < player_ptr->current_floor_ptr->height; y++) - { - for (POSITION x = 0; x < player_ptr->current_floor_ptr->width; x++) - { - grid_type *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x]; - OBJECT_IDX this_o_idx, next_o_idx = 0; - for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) - { - object_type *o_ptr; - o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx]; - next_o_idx = o_ptr->next_o_idx; - if (!object_is_fixed_artifact(o_ptr)) continue; - if (object_is_known(o_ptr)) continue; - - okay[o_ptr->name1] = FALSE; - } - } - } - - for (ARTIFACT_IDX i = 0; i < INVEN_TOTAL; i++) - { - object_type *o_ptr = &player_ptr->inventory_list[i]; - if (!o_ptr->k_idx) continue; - if (!object_is_fixed_artifact(o_ptr)) continue; - if (object_is_known(o_ptr)) continue; - - okay[o_ptr->name1] = FALSE; - } - - int n = 0; - for (ARTIFACT_IDX k = 0; k < max_a_idx; k++) - { - if (okay[k]) who[n++] = k; - } - - u16b why = 3; - ang_sort(who, &why, n, ang_sort_art_comp, ang_sort_art_swap); - for (ARTIFACT_IDX k = 0; k < n; k++) - { - artifact_type *a_ptr = &a_info[who[k]]; - GAME_TEXT base_name[MAX_NLEN]; - strcpy(base_name, _("未知の伝説のアイテム", "Unknown Artifact")); - ARTIFACT_IDX z = lookup_kind(a_ptr->tval, a_ptr->sval); - if (z) - { - object_type forge; - object_type *q_ptr; - q_ptr = &forge; - object_prep(q_ptr, z); - q_ptr->name1 = (byte)who[k]; - q_ptr->ident |= IDENT_STORE; - object_desc(player_ptr, base_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); - } - - fprintf(fff, _(" %s\n", " The %s\n"), base_name); - } - - C_KILL(who, max_a_idx, ARTIFACT_IDX); - C_KILL(okay, max_a_idx, bool); - my_fclose(fff); - (void)show_file(player_ptr, TRUE, file_name, _("既知の伝説のアイテム", "Artifacts Seen"), 0, 0); - fd_kill(file_name); -} - - -/* * Display known uniques * With "XTRA HACK UNIQHIST" (Originally from XAngband) */ diff --git a/src/knowledge/knowledge-artifacts.c b/src/knowledge/knowledge-artifacts.c new file mode 100644 index 000000000..94fd27bab --- /dev/null +++ b/src/knowledge/knowledge-artifacts.c @@ -0,0 +1,101 @@ +#include "angband.h" +#include "knowledge-artifacts.h" +#include "cmd/dump-util.h" +#include "artifact.h" +#include "sort.h" +#include "object-flavor.h" +#include "object-hook.h" +#include "objectkind.h" +#include "core/show-file.h" + +/* + * todo okay = 既知のアーティファクト? と思われるが確証がない + * 分かりやすい変数名へ変更求む&万が一未知である旨の配列なら負論理なのでゴソッと差し替えるべき + * Check the status of "artifacts" + * @param player_ptr プレーヤーへの参照ポインタ + * @return なし + */ +void do_cmd_knowledge_artifacts(player_type *player_ptr) +{ + FILE *fff = NULL; + GAME_TEXT file_name[FILE_NAME_SIZE]; + if (!open_temporary_file(&fff, file_name)) return; + + ARTIFACT_IDX *who; + C_MAKE(who, max_a_idx, ARTIFACT_IDX); + bool *okay; + C_MAKE(okay, max_a_idx, bool); + + for (ARTIFACT_IDX k = 0; k < max_a_idx; k++) + { + artifact_type *a_ptr = &a_info[k]; + okay[k] = FALSE; + if (!a_ptr->name) continue; + if (!a_ptr->cur_num) continue; + + okay[k] = TRUE; + } + + for (POSITION y = 0; y < player_ptr->current_floor_ptr->height; y++) + { + for (POSITION x = 0; x < player_ptr->current_floor_ptr->width; x++) + { + grid_type *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x]; + OBJECT_IDX this_o_idx, next_o_idx = 0; + for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) + { + object_type *o_ptr; + o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx]; + next_o_idx = o_ptr->next_o_idx; + if (!object_is_fixed_artifact(o_ptr)) continue; + if (object_is_known(o_ptr)) continue; + + okay[o_ptr->name1] = FALSE; + } + } + } + + for (ARTIFACT_IDX i = 0; i < INVEN_TOTAL; i++) + { + object_type *o_ptr = &player_ptr->inventory_list[i]; + if (!o_ptr->k_idx) continue; + if (!object_is_fixed_artifact(o_ptr)) continue; + if (object_is_known(o_ptr)) continue; + + okay[o_ptr->name1] = FALSE; + } + + int n = 0; + for (ARTIFACT_IDX k = 0; k < max_a_idx; k++) + { + if (okay[k]) who[n++] = k; + } + + u16b why = 3; + ang_sort(who, &why, n, ang_sort_art_comp, ang_sort_art_swap); + for (ARTIFACT_IDX k = 0; k < n; k++) + { + artifact_type *a_ptr = &a_info[who[k]]; + GAME_TEXT base_name[MAX_NLEN]; + strcpy(base_name, _("未知の伝説のアイテム", "Unknown Artifact")); + ARTIFACT_IDX z = lookup_kind(a_ptr->tval, a_ptr->sval); + if (z) + { + object_type forge; + object_type *q_ptr; + q_ptr = &forge; + object_prep(q_ptr, z); + q_ptr->name1 = (byte)who[k]; + q_ptr->ident |= IDENT_STORE; + object_desc(player_ptr, base_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); + } + + fprintf(fff, _(" %s\n", " The %s\n"), base_name); + } + + C_KILL(who, max_a_idx, ARTIFACT_IDX); + C_KILL(okay, max_a_idx, bool); + my_fclose(fff); + (void)show_file(player_ptr, TRUE, file_name, _("既知の伝説のアイテム", "Artifacts Seen"), 0, 0); + fd_kill(file_name); +} diff --git a/src/knowledge/knowledge-artifacts.h b/src/knowledge/knowledge-artifacts.h new file mode 100644 index 000000000..57b5f5178 --- /dev/null +++ b/src/knowledge/knowledge-artifacts.h @@ -0,0 +1,3 @@ +#pragma once + +void do_cmd_knowledge_artifacts(player_type *player_ptr); -- 2.11.0