OSDN Git Service

[Refactor] #40460 Separated ego-reader.c/h from dungeon-file.c/h
authorHourier <hourier@users.sourceforge.jp>
Sat, 6 Jun 2020 03:19:36 +0000 (12:19 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sat, 6 Jun 2020 03:19:36 +0000 (12:19 +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/ego-reader.c [new file with mode: 0644]
src/info-reader/ego-reader.h [new file with mode: 0644]
src/info-reader/kind-reader.h
src/main/init.c

index 7bc502f..0a27fb1 100644 (file)
     <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\ego-reader.c" />\r
     <ClCompile Include="..\..\src\info-reader\feature-info-tokens-table.c" />\r
     <ClCompile Include="..\..\src\info-reader\feature-reader.c" />\r
     <ClCompile Include="..\..\src\info-reader\info-reader-util.c" />\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\ego-reader.h" />\r
     <ClInclude Include="..\..\src\info-reader\feature-info-tokens-table.h" />\r
     <ClInclude Include="..\..\src\info-reader\feature-reader.h" />\r
     <ClInclude Include="..\..\src\info-reader\info-reader-util.h" />\r
index ac116fe..d9c495d 100644 (file)
     <ClCompile Include="..\..\src\info-reader\artifact-reader.c">
       <Filter>info-reader</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\info-reader\ego-reader.c">
+      <Filter>info-reader</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\cmd\cmd-basic.h">
     <ClInclude Include="..\..\src\info-reader\artifact-reader.h">
       <Filter>info-reader</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\info-reader\ego-reader.h">
+      <Filter>info-reader</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index b7d8d7e..8762780 100644 (file)
@@ -154,6 +154,7 @@ hengband_SOURCES = \
        \
        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/ego-reader.c info-reader/ego-reader.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 \
        info-reader/info-reader-util.c info-reader/info-reader-util.h \
index 4a862ba..b15eb06 100644 (file)
@@ -350,155 +350,6 @@ void retouch_f_info(angband_header *head)
 
 
 /*!
- * @brief テキストトークンを走査してフラグを一つ得る(エゴ用) /
- * Grab one flag in a ego-item_type from a textual string
- * @param e_ptr 保管先のエゴ構造体参照ポインタ
- * @param what 参照元の文字列ポインタ
- * @return エラーがあった場合1、エラーがない場合0を返す
- */
-static bool grab_one_ego_item_flag(ego_item_type *e_ptr, concptr what)
-{
-       for (int i = 0; i < TR_FLAG_MAX; i++)
-       {
-               if (streq(what, k_info_flags[i]))
-               {
-                       add_flag(e_ptr->flags, i);
-                       return 0;
-               }
-       }
-
-       if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
-               return 0;
-
-       msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
-       return 1;
-}
-
-
-/*!
- * @brief アイテムエゴ情報(e_info)のパース関数 /
- * Initialize the "e_info" array, by parsing an ascii "template" file
- * @param buf テキスト列
- * @param head ヘッダ構造体
- * @return エラーコード
- */
-errr parse_e_info(char *buf, angband_header *head)
-{
-       static ego_item_type *e_ptr = NULL;
-       error_idx = -1;
-       error_line = -1;
-       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;
-               e_ptr = &e_info[i];
-#ifdef JP
-               if (!add_name(&e_ptr->name, head, s)) return 7;
-#endif
-       }
-       else if (!e_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(&e_ptr->name, head, s)) return 7;
-       }
-#endif
-       else if (buf[0] == 'X')
-       {
-               int slot, rating;
-               if (2 != sscanf(buf + 2, "%d:%d",
-                       &slot, &rating)) return 1;
-
-               e_ptr->slot = (INVENTORY_IDX)slot;
-               e_ptr->rating = (PRICE)rating;
-       }
-       else if (buf[0] == 'W')
-       {
-               int level, rarity, pad2;
-               long cost;
-
-               if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
-                       &level, &rarity, &pad2, &cost)) return 1;
-
-               e_ptr->level = level;
-               e_ptr->rarity = (RARITY)rarity;
-               e_ptr->cost = cost;
-       }
-       else if (buf[0] == 'C')
-       {
-               int th, td, ta, pval;
-
-               if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
-                       &th, &td, &ta, &pval)) return 1;
-
-               e_ptr->max_to_h = (HIT_PROB)th;
-               e_ptr->max_to_d = (HIT_POINT)td;
-               e_ptr->max_to_a = (ARMOUR_CLASS)ta;
-               e_ptr->max_pval = (PARAMETER_VALUE)pval;
-       }
-       else if (buf[0] == 'U')
-       {
-               byte n;
-               n = grab_one_activation_flag(buf + 2);
-               if (n > 0)
-               {
-                       e_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_ego_item_flag(e_ptr, s)) return 5;
-
-                       s = t;
-               }
-       }
-       else
-       {
-               return 6;
-       }
-
-       return 0;
-}
-
-
-/*!
  * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
  * Grab one (basic) flag in a monster_race from a textual string
  * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
index 5abd72a..f1a207f 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_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);
 errr process_dungeon_file(player_type *player_ptr, concptr name, int ymin, int xmin, int ymax, int xmax);
diff --git a/src/info-reader/ego-reader.c b/src/info-reader/ego-reader.c
new file mode 100644 (file)
index 0000000..51dccd2
--- /dev/null
@@ -0,0 +1,137 @@
+#include "info-reader/ego-reader.h"
+#include "info-reader/kind-info-tokens-table.h"
+#include "object-enchant/object-ego.h"
+#include "object-enchant/tr-types.h"
+
+/*!
+ * @brief テキストトークンを走査してフラグを一つ得る(エゴ用) /
+ * Grab one flag in a ego-item_type from a textual string
+ * @param e_ptr 保管先のエゴ構造体参照ポインタ
+ * @param what 参照元の文字列ポインタ
+ * @return エラーがあった場合1、エラーがない場合0を返す
+ */
+static bool grab_one_ego_item_flag(ego_item_type *e_ptr, concptr what)
+{
+    for (int i = 0; i < TR_FLAG_MAX; i++) {
+        if (streq(what, k_info_flags[i])) {
+            add_flag(e_ptr->flags, i);
+            return 0;
+        }
+    }
+
+    if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
+        return 0;
+
+    msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
+    return 1;
+}
+
+/*!
+ * @brief アイテムエゴ情報(e_info)のパース関数 /
+ * Initialize the "e_info" array, by parsing an ascii "template" file
+ * @param buf テキスト列
+ * @param head ヘッダ構造体
+ * @return エラーコード
+ */
+errr parse_e_info(char *buf, angband_header *head)
+{
+    static ego_item_type *e_ptr = NULL;
+    error_idx = -1;
+    error_line = -1;
+    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;
+        e_ptr = &e_info[i];
+#ifdef JP
+        if (!add_name(&e_ptr->name, head, s))
+            return 7;
+#endif
+    } else if (!e_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(&e_ptr->name, head, s))
+            return 7;
+    }
+#endif
+    else if (buf[0] == 'X') {
+        int slot, rating;
+        if (2 != sscanf(buf + 2, "%d:%d", &slot, &rating))
+            return 1;
+
+        e_ptr->slot = (INVENTORY_IDX)slot;
+        e_ptr->rating = (PRICE)rating;
+    } else if (buf[0] == 'W') {
+        int level, rarity, pad2;
+        long cost;
+
+        if (4 != sscanf(buf + 2, "%d:%d:%d:%ld", &level, &rarity, &pad2, &cost))
+            return 1;
+
+        e_ptr->level = level;
+        e_ptr->rarity = (RARITY)rarity;
+        e_ptr->cost = cost;
+    } else if (buf[0] == 'C') {
+        int th, td, ta, pval;
+
+        if (4 != sscanf(buf + 2, "%d:%d:%d:%d", &th, &td, &ta, &pval))
+            return 1;
+
+        e_ptr->max_to_h = (HIT_PROB)th;
+        e_ptr->max_to_d = (HIT_POINT)td;
+        e_ptr->max_to_a = (ARMOUR_CLASS)ta;
+        e_ptr->max_pval = (PARAMETER_VALUE)pval;
+    } else if (buf[0] == 'U') {
+        byte n;
+        n = grab_one_activation_flag(buf + 2);
+        if (n > 0) {
+            e_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_ego_item_flag(e_ptr, s))
+                return 5;
+
+            s = t;
+        }
+    } else {
+        return 6;
+    }
+
+    return 0;
+}
diff --git a/src/info-reader/ego-reader.h b/src/info-reader/ego-reader.h
new file mode 100644 (file)
index 0000000..d518fb4
--- /dev/null
@@ -0,0 +1,6 @@
+#pragma once
+
+#include "system/angband.h"
+#include "info-reader/info-reader-util.h"
+
+errr parse_e_info(char *buf, angband_header *head);
index ad73109..774cd61 100644 (file)
@@ -1,6 +1,6 @@
 #pragma once
 
-#include "info-reader/info-reader-util.h"
 #include "system/angband.h"
+#include "info-reader/info-reader-util.h"
 
 errr parse_k_info(char *buf, angband_header *head);
index af17624..d3252bd 100644 (file)
@@ -40,6 +40,7 @@
 #include "grid/feature.h"
 #include "grid/trap.h"
 #include "info-reader/artifact-reader.h"
+#include "info-reader/ego-reader.h"
 #include "info-reader/feature-reader.h"
 #include "info-reader/kind-reader.h"
 #include "info-reader/parse-error-types.h"