OSDN Git Service

[Refactor] #40460 Separated artifact-reader.c/h from dungeon-file.c/h
authorHourier <hourier@users.sourceforge.jp>
Sat, 6 Jun 2020 03:16:39 +0000 (12:16 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sat, 6 Jun 2020 03:16:39 +0000 (12:16 +0900)
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/dungeon/dungeon-file.c
src/dungeon/dungeon-file.h
src/info-reader/artifact-reader.c [new file with mode: 0644]
src/info-reader/artifact-reader.h [new file with mode: 0644]
src/main/init.c

index 4792b55..7bc502f 100644 (file)
     <ClCompile Include="..\..\src\birth\quick-start.c" />\r
     <ClCompile Include="..\..\src\cmd-action\cmd-attack.c" />\r
     <ClCompile Include="..\..\src\cmd-io\cmd-menu-content-table.c" />\r
+    <ClCompile Include="..\..\src\info-reader\artifact-reader.c" />\r
     <ClCompile Include="..\..\src\info-reader\dungeon-info-tokens-table.c" />\r
     <ClCompile Include="..\..\src\info-reader\feature-info-tokens-table.c" />\r
     <ClCompile Include="..\..\src\info-reader\feature-reader.c" />\r
     <ClInclude Include="..\..\src\birth\quick-start.h" />\r
     <ClInclude Include="..\..\src\cmd-action\cmd-attack.h" />\r
     <ClInclude Include="..\..\src\cmd-io\cmd-menu-content-table.h" />\r
+    <ClInclude Include="..\..\src\info-reader\artifact-reader.h" />\r
     <ClInclude Include="..\..\src\info-reader\dungeon-info-tokens-table.h" />\r
     <ClInclude Include="..\..\src\info-reader\feature-info-tokens-table.h" />\r
     <ClInclude Include="..\..\src\info-reader\feature-reader.h" />\r
index fa93065..ac116fe 100644 (file)
     <ClCompile Include="..\..\src\info-reader\kind-reader.c">
       <Filter>info-reader</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\info-reader\artifact-reader.c">
+      <Filter>info-reader</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\cmd\cmd-basic.h">
     <ClInclude Include="..\..\src\info-reader\kind-reader.h">
       <Filter>info-reader</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\info-reader\artifact-reader.h">
+      <Filter>info-reader</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index eec05ac..b7d8d7e 100644 (file)
@@ -152,6 +152,7 @@ hengband_SOURCES = \
        grid/feature.c grid/feature.h \
        grid/grid.c grid/grid.h grid/trap.c grid/trap.h \
        \
+       info-reader/artifact-reader.c info-reader/artifact-reader.h \
        info-reader/dungeon-info-tokens-table.c info-reader/dungeon-info-tokens-table.h \
        info-reader/feature-info-tokens-table.c info-reader/feature-info-tokens-table.h \
        info-reader/feature-reader.c info-reader/feature-reader.h \
index 80bd743..4a862ba 100644 (file)
@@ -350,173 +350,7 @@ void retouch_f_info(angband_header *head)
 
 
 /*!
- * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
- * Grab one activation index flag
- * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
- * @param what 参照元の文字列ポインタ
- * @return エラーがあった場合1、エラーがない場合0を返す
- */
-static errr grab_one_artifact_flag(artifact_type *a_ptr, concptr what)
-{
-       for (int i = 0; i < TR_FLAG_MAX; i++)
-       {
-               if (streq(what, k_info_flags[i]))
-               {
-                       add_flag(a_ptr->flags, i);
-                       return 0;
-               }
-       }
-
-       if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
-               return 0;
-
-       msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
-       return 1;
-}
-
-
-/*!
- * @brief 固定アーティファクト情報(a_info)のパース関数 /
- * Initialize the "a_info" array, by parsing an ascii "template" file
- * @param buf テキスト列
- * @param head ヘッダ構造体
- * @return エラーコード
- */
-errr parse_a_info(char *buf, angband_header *head)
-{
-       static artifact_type *a_ptr = NULL;
-       char *s, *t;
-       if (buf[0] == 'N')
-       {
-               s = my_strchr(buf + 2, ':');
-               if (!s) return 1;
-
-               *s++ = '\0';
-#ifdef JP
-               if (!*s) return 1;
-#endif
-               int i = atoi(buf + 2);
-               if (i < error_idx) return 4;
-               if (i >= head->info_num) return 2;
-
-               error_idx = i;
-               a_ptr = &a_info[i];
-               add_flag(a_ptr->flags, TR_IGNORE_ACID);
-               add_flag(a_ptr->flags, TR_IGNORE_ELEC);
-               add_flag(a_ptr->flags, TR_IGNORE_FIRE);
-               add_flag(a_ptr->flags, TR_IGNORE_COLD);
-#ifdef JP
-               if (!add_name(&a_ptr->name, head, s)) return 7;
-#endif
-       }
-       else if (!a_ptr)
-       {
-               return 3;
-       }
-#ifdef JP
-       /* 英語名を読むルーチンを追加 */
-       /* 'E' から始まる行は英語名としている */
-       else if (buf[0] == 'E')
-       {
-               /* nothing to do */
-       }
-#else
-       else if (buf[0] == 'E')
-       {
-               s = buf + 2;
-               if (!add_name(&a_ptr->name, head, s)) return 7;
-       }
-#endif
-       else if (buf[0] == 'D')
-       {
-#ifdef JP
-               if (buf[2] == '$')
-                       return 0;
-               s = buf + 2;
-#else
-               if (buf[2] != '$')
-                       return 0;
-               s = buf + 3;
-#endif
-               if (!add_text(&a_ptr->text, head, s, TRUE)) return 7;
-       }
-       else if (buf[0] == 'I')
-       {
-               int tval, sval, pval;
-               if (3 != sscanf(buf + 2, "%d:%d:%d",
-                       &tval, &sval, &pval)) return 1;
-
-               a_ptr->tval = (tval_type)tval;
-               a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
-               a_ptr->pval = (PARAMETER_VALUE)pval;
-       }
-       else if (buf[0] == 'W')
-       {
-               int level, rarity, wgt;
-               long cost;
-               if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
-                       &level, &rarity, &wgt, &cost)) return 1;
-
-               a_ptr->level = (DEPTH)level;
-               a_ptr->rarity = (RARITY)rarity;
-               a_ptr->weight = (WEIGHT)wgt;
-               a_ptr->cost = (PRICE)cost;
-       }
-       else if (buf[0] == 'P')
-       {
-               int ac, hd1, hd2, th, td, ta;
-               if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
-                       &ac, &hd1, &hd2, &th, &td, &ta)) return 1;
-
-               a_ptr->ac = (ARMOUR_CLASS)ac;
-               a_ptr->dd = (DICE_NUMBER)hd1;
-               a_ptr->ds = (DICE_SID)hd2;
-               a_ptr->to_h = (HIT_PROB)th;
-               a_ptr->to_d = (HIT_POINT)td;
-               a_ptr->to_a = (ARMOUR_CLASS)ta;
-       }
-       else if (buf[0] == 'U')
-       {
-               byte n;
-               n = grab_one_activation_flag(buf + 2);
-               if (n > 0)
-               {
-                       a_ptr->act_idx = n;
-               }
-               else
-               {
-                       return 5;
-               }
-       }
-       else if (buf[0] == 'F')
-       {
-               for (s = buf + 2; *s; )
-               {
-                       /* loop */
-                       for (t = s; *t && (*t != ' ') && (*t != '|'); ++t);
-
-                       if (*t)
-                       {
-                               *t++ = '\0';
-                               while ((*t == ' ') || (*t == '|')) t++;
-                       }
-
-                       if (0 != grab_one_artifact_flag(a_ptr, s)) return 5;
-
-                       s = t;
-               }
-       }
-       else
-       {
-               return 6;
-       }
-
-       return 0;
-}
-
-
-/*!
- * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
+ * @brief テキストトークンを走査してフラグを一つ得る(エゴ用) /
  * Grab one flag in a ego-item_type from a textual string
  * @param e_ptr 保管先のエゴ構造体参照ポインタ
  * @param what 参照元の文字列ポインタ
index a7eaba6..5abd72a 100644 (file)
@@ -10,7 +10,6 @@ errr init_info_txt(FILE *fp, char *buf, angband_header *head, parse_info_txt_fun
 errr parse_s_info(char *buf, angband_header *head);
 errr parse_m_info(char *buf, angband_header *head);
 void retouch_f_info(angband_header *head);
-errr parse_a_info(char *buf, angband_header *head);
 errr parse_e_info(char *buf, angband_header *head);
 errr parse_r_info(char *buf, angband_header *head);
 errr parse_d_info(char *buf, angband_header *head);
diff --git a/src/info-reader/artifact-reader.c b/src/info-reader/artifact-reader.c
new file mode 100644 (file)
index 0000000..c79f200
--- /dev/null
@@ -0,0 +1,153 @@
+#include "info-reader/artifact-reader.h"
+#include "info-reader/kind-info-tokens-table.h"
+#include "object-enchant/artifact.h"
+#include "object-enchant/tr-types.h"
+
+/*!
+ * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
+ * Grab one activation index flag
+ * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
+ * @param what 参照元の文字列ポインタ
+ * @return エラーがあった場合1、エラーがない場合0を返す
+ */
+static errr grab_one_artifact_flag(artifact_type *a_ptr, concptr what)
+{
+    for (int i = 0; i < TR_FLAG_MAX; i++) {
+        if (streq(what, k_info_flags[i])) {
+            add_flag(a_ptr->flags, i);
+            return 0;
+        }
+    }
+
+    if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
+        return 0;
+
+    msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
+    return 1;
+}
+
+/*!
+ * @brief 固定アーティファクト情報(a_info)のパース関数 /
+ * Initialize the "a_info" array, by parsing an ascii "template" file
+ * @param buf テキスト列
+ * @param head ヘッダ構造体
+ * @return エラーコード
+ */
+errr parse_a_info(char *buf, angband_header *head)
+{
+    static artifact_type *a_ptr = NULL;
+    char *s, *t;
+    if (buf[0] == 'N') {
+        s = my_strchr(buf + 2, ':');
+        if (!s)
+            return 1;
+
+        *s++ = '\0';
+#ifdef JP
+        if (!*s)
+            return 1;
+#endif
+        int i = atoi(buf + 2);
+        if (i < error_idx)
+            return 4;
+        if (i >= head->info_num)
+            return 2;
+
+        error_idx = i;
+        a_ptr = &a_info[i];
+        add_flag(a_ptr->flags, TR_IGNORE_ACID);
+        add_flag(a_ptr->flags, TR_IGNORE_ELEC);
+        add_flag(a_ptr->flags, TR_IGNORE_FIRE);
+        add_flag(a_ptr->flags, TR_IGNORE_COLD);
+#ifdef JP
+        if (!add_name(&a_ptr->name, head, s))
+            return 7;
+#endif
+    } else if (!a_ptr) {
+        return 3;
+    }
+#ifdef JP
+    /* 英語名を読むルーチンを追加 */
+    /* 'E' から始まる行は英語名としている */
+    else if (buf[0] == 'E') {
+        /* nothing to do */
+    }
+#else
+    else if (buf[0] == 'E') {
+        s = buf + 2;
+        if (!add_name(&a_ptr->name, head, s))
+            return 7;
+    }
+#endif
+    else if (buf[0] == 'D') {
+#ifdef JP
+        if (buf[2] == '$')
+            return 0;
+        s = buf + 2;
+#else
+        if (buf[2] != '$')
+            return 0;
+        s = buf + 3;
+#endif
+        if (!add_text(&a_ptr->text, head, s, TRUE))
+            return 7;
+    } else if (buf[0] == 'I') {
+        int tval, sval, pval;
+        if (3 != sscanf(buf + 2, "%d:%d:%d", &tval, &sval, &pval))
+            return 1;
+
+        a_ptr->tval = (tval_type)tval;
+        a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
+        a_ptr->pval = (PARAMETER_VALUE)pval;
+    } else if (buf[0] == 'W') {
+        int level, rarity, wgt;
+        long cost;
+        if (4 != sscanf(buf + 2, "%d:%d:%d:%ld", &level, &rarity, &wgt, &cost))
+            return 1;
+
+        a_ptr->level = (DEPTH)level;
+        a_ptr->rarity = (RARITY)rarity;
+        a_ptr->weight = (WEIGHT)wgt;
+        a_ptr->cost = (PRICE)cost;
+    } else if (buf[0] == 'P') {
+        int ac, hd1, hd2, th, td, ta;
+        if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d", &ac, &hd1, &hd2, &th, &td, &ta))
+            return 1;
+
+        a_ptr->ac = (ARMOUR_CLASS)ac;
+        a_ptr->dd = (DICE_NUMBER)hd1;
+        a_ptr->ds = (DICE_SID)hd2;
+        a_ptr->to_h = (HIT_PROB)th;
+        a_ptr->to_d = (HIT_POINT)td;
+        a_ptr->to_a = (ARMOUR_CLASS)ta;
+    } else if (buf[0] == 'U') {
+        byte n;
+        n = grab_one_activation_flag(buf + 2);
+        if (n > 0) {
+            a_ptr->act_idx = n;
+        } else {
+            return 5;
+        }
+    } else if (buf[0] == 'F') {
+        for (s = buf + 2; *s;) {
+            /* loop */
+            for (t = s; *t && (*t != ' ') && (*t != '|'); ++t)
+                ;
+
+            if (*t) {
+                *t++ = '\0';
+                while ((*t == ' ') || (*t == '|'))
+                    t++;
+            }
+
+            if (0 != grab_one_artifact_flag(a_ptr, s))
+                return 5;
+
+            s = t;
+        }
+    } else {
+        return 6;
+    }
+
+    return 0;
+}
diff --git a/src/info-reader/artifact-reader.h b/src/info-reader/artifact-reader.h
new file mode 100644 (file)
index 0000000..cbbe903
--- /dev/null
@@ -0,0 +1,6 @@
+#pragma once
+
+#include "info-reader/info-reader-util.h"
+#include "system/angband.h"
+
+errr parse_a_info(char *buf, angband_header *head);
index 26cbf49..af17624 100644 (file)
@@ -39,6 +39,7 @@
 #include "floor/wild.h"
 #include "grid/feature.h"
 #include "grid/trap.h"
+#include "info-reader/artifact-reader.h"
 #include "info-reader/feature-reader.h"
 #include "info-reader/kind-reader.h"
 #include "info-reader/parse-error-types.h"