OSDN Git Service

[Refactor] #40467 Separated quest-loader.c/h from load.c
authorHourier <hourier@users.sourceforge.jp>
Sun, 5 Jul 2020 13:22:29 +0000 (22:22 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sun, 5 Jul 2020 13:22:29 +0000 (22:22 +0900)
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/savedata/load.c
src/savedata/quest-loader.c [new file with mode: 0644]
src/savedata/quest-loader.h [new file with mode: 0644]

index a47e105..7cd8b56 100644 (file)
     <ClCompile Include="..\..\src\combat\aura-counterattack.c" />\r
     <ClCompile Include="..\..\src\wizard\spoiler-table.c" />\r
     <ClCompile Include="..\..\src\wizard\tval-descriptions-table.c" />\r
+    <ClCompile Include="..\..\src\savedata\quest-loader.c" />\r
     <ClInclude Include="..\..\src\art-definition\art-accessory-types.h" />\r
     <ClInclude Include="..\..\src\art-definition\art-armor-types.h" />\r
     <ClInclude Include="..\..\src\art-definition\art-bow-types.h" />\r
     <ClInclude Include="..\..\src\locale\japanese.h" />\r
     <ClInclude Include="..\..\src\combat\aura-counterattack.h" />\r
     <ClInclude Include="..\..\src\wizard\tval-descriptions-table.h" />\r
+    <ClInclude Include="..\..\src\savedata\quest-loader.h" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\..\src\system\angband.h" />\r
index d846f70..c54b2b6 100644 (file)
     <ClCompile Include="..\..\src\savedata\floor-loader.c">
       <Filter>savedata</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\savedata\quest-loader.c">
+      <Filter>savedata</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\cmd\cmd-basic.h">
     <ClInclude Include="..\..\src\savedata\floor-loader.h">
       <Filter>savedata</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\savedata\quest-loader.h">
+      <Filter>savedata</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 86aace2..2c2e761 100644 (file)
@@ -534,6 +534,7 @@ hengband_SOURCES = \
        savedata/load-v1-3-0.c savedata/load-v1-3-0.h \
        savedata/load-v1-5-0.c savedata/load-v1-5-0.h \
        savedata/load-zangband.c savedata/load-zangband.h \
+       savedata/quest-loader.c savedata/quest-loader.h \
        savedata/load.c savedata/load.h \
        savedata/lore-loader.c savedata/lore-loader.h \
        savedata/option-loader.c savedata/option-loader.h \
index 174e935..e03ff94 100644 (file)
@@ -44,6 +44,7 @@
 #include "savedata/lore-loader.h"
 #include "savedata/load-zangband.h"
 #include "savedata/option-loader.h"
+#include "savedata/quest-loader.h"
 #include "savedata/player-info-loader.h"
 #include "savedata/store-loader.h"
 #include "savedata/world-loader.h"
@@ -137,135 +138,6 @@ static void rd_system_info(void)
 }
 
 /*!
- * @brief ランダムクエスト情報の読み込み
- * @param なし
- * @return なし
- * @details MAX_TRIES: ランダムクエストのモンスターを確定するために試行する回数 /
- * Maximum number of tries for selection of a proper quest monster
- */
-static void rd_unique_info(void)
-{
-    const int MAX_TRIES = 100;
-    for (int i = 0; i < max_r_idx; i++) {
-        monster_race *r_ptr = &r_info[i];
-        r_ptr->max_num = MAX_TRIES;
-        if (r_ptr->flags1 & RF1_UNIQUE)
-            r_ptr->max_num = 1;
-        else if (r_ptr->flags7 & RF7_NAZGUL)
-            r_ptr->max_num = MAX_NAZGUL_NUM;
-    }
-}
-
-static errr load_town(void)
-{
-    u16b max_towns_load;
-    rd_u16b(&max_towns_load);
-    if (max_towns_load <= max_towns)
-        return 0;
-
-    load_note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
-    return 23;
-}
-
-static errr load_quest_info(u16b *max_quests_load, byte *max_rquests_load)
-{
-    rd_u16b(max_quests_load);
-    if (z_older_than(11, 0, 7))
-        *max_rquests_load = 10;
-    else
-        rd_byte(max_rquests_load);
-
-    if (*max_quests_load <= max_q_idx)
-        return 0;
-
-    load_note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), *max_quests_load));
-    return 23;
-}
-
-static bool check_quest_index(int loading_quest_index)
-{
-    if (loading_quest_index < max_q_idx)
-        return FALSE;
-
-    strip_bytes(2);
-    strip_bytes(2);
-    return TRUE;
-}
-
-static void load_quest_completion(quest_type *q_ptr)
-{
-    rd_s16b(&q_ptr->status);
-    s16b tmp16s;
-    rd_s16b(&tmp16s);
-    q_ptr->level = tmp16s;
-
-    if (z_older_than(11, 0, 6))
-        q_ptr->complev = 0;
-    else {
-        byte tmp8u;
-        rd_byte(&tmp8u);
-        q_ptr->complev = tmp8u;
-    }
-
-    if (h_older_than(2, 1, 2, 2))
-        q_ptr->comptime = 0;
-    else
-        rd_u32b(&q_ptr->comptime);
-}
-
-static void load_quest_details(player_type *creature_ptr, quest_type *q_ptr, int loading_quest_index)
-{
-    s16b tmp16s;
-    rd_s16b(&tmp16s);
-    q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
-    rd_s16b(&tmp16s);
-    q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
-    rd_s16b(&q_ptr->type);
-
-    rd_s16b(&q_ptr->r_idx);
-    if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
-        determine_random_questor(creature_ptr, &quest[loading_quest_index]);
-
-    rd_s16b(&q_ptr->k_idx);
-    if (q_ptr->k_idx)
-        a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
-
-    byte tmp8u;
-    rd_byte(&tmp8u);
-    q_ptr->flags = tmp8u;
-}
-
-static void analyze_quests(player_type *creature_ptr, const u16b max_quests_load, const byte max_rquests_load)
-{
-    QUEST_IDX old_inside_quest = creature_ptr->current_floor_ptr->inside_quest;
-    for (int i = 0; i < max_quests_load; i++) {
-        if (check_quest_index(i))
-            continue;
-
-        quest_type *const q_ptr = &quest[i];
-        load_quest_completion(q_ptr);
-        bool is_quest_running = (q_ptr->status == QUEST_STATUS_TAKEN);
-        is_quest_running |= (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED));
-        is_quest_running |= (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load)));
-        if (!is_quest_running)
-            continue;
-
-        load_quest_details(creature_ptr, q_ptr, i);
-        if (z_older_than(10, 3, 11))
-            set_zangband_quest(creature_ptr, q_ptr, i, old_inside_quest);
-        else {
-            byte tmp8u;
-            rd_byte(&tmp8u);
-            q_ptr->dungeon = tmp8u;
-        }
-
-        if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
-            if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
-                r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
-    }
-}
-
-/*!
  * @brief 変愚蛮怒 v2.1.3で追加された街とクエストについて読み込む
  * @param creature_ptr プレーヤーへの参照ポインタ
  * @return エラーコード
diff --git a/src/savedata/quest-loader.c b/src/savedata/quest-loader.c
new file mode 100644 (file)
index 0000000..02dc663
--- /dev/null
@@ -0,0 +1,142 @@
+#include "savedata/quest-loader.h"
+#include "dungeon/quest.h"
+#include "floor/floor-town.h"
+#include "floor/floor.h"
+#include "monster-race/monster-race.h"
+#include "monster-race/race-flags1.h"
+#include "monster-race/race-flags7.h"
+#include "object-enchant/artifact.h"
+#include "object-enchant/trg-types.h"
+#include "savedata/angband-version-comparer.h"
+#include "savedata/load-util.h"
+#include "savedata/load-zangband.h"
+#include "system/system-variables.h"
+
+/*!
+ * @brief ランダムクエスト情報の読み込み
+ * @param なし
+ * @return なし
+ * @details MAX_TRIES: ランダムクエストのモンスターを確定するために試行する回数 /
+ * Maximum number of tries for selection of a proper quest monster
+ */
+void rd_unique_info(void)
+{
+    const int MAX_TRIES = 100;
+    for (int i = 0; i < max_r_idx; i++) {
+        monster_race *r_ptr = &r_info[i];
+        r_ptr->max_num = MAX_TRIES;
+        if (r_ptr->flags1 & RF1_UNIQUE)
+            r_ptr->max_num = 1;
+        else if (r_ptr->flags7 & RF7_NAZGUL)
+            r_ptr->max_num = MAX_NAZGUL_NUM;
+    }
+}
+
+errr load_town(void)
+{
+    u16b max_towns_load;
+    rd_u16b(&max_towns_load);
+    if (max_towns_load <= max_towns)
+        return 0;
+
+    load_note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
+    return 23;
+}
+
+errr load_quest_info(u16b *max_quests_load, byte *max_rquests_load)
+{
+    rd_u16b(max_quests_load);
+    if (z_older_than(11, 0, 7))
+        *max_rquests_load = 10;
+    else
+        rd_byte(max_rquests_load);
+
+    if (*max_quests_load <= max_q_idx)
+        return 0;
+
+    load_note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), *max_quests_load));
+    return 23;
+}
+
+static bool check_quest_index(int loading_quest_index)
+{
+    if (loading_quest_index < max_q_idx)
+        return FALSE;
+
+    strip_bytes(2);
+    strip_bytes(2);
+    return TRUE;
+}
+
+static void load_quest_completion(quest_type *q_ptr)
+{
+    rd_s16b(&q_ptr->status);
+    s16b tmp16s;
+    rd_s16b(&tmp16s);
+    q_ptr->level = tmp16s;
+
+    if (z_older_than(11, 0, 6))
+        q_ptr->complev = 0;
+    else {
+        byte tmp8u;
+        rd_byte(&tmp8u);
+        q_ptr->complev = tmp8u;
+    }
+
+    if (h_older_than(2, 1, 2, 2))
+        q_ptr->comptime = 0;
+    else
+        rd_u32b(&q_ptr->comptime);
+}
+
+static void load_quest_details(player_type *creature_ptr, quest_type *q_ptr, int loading_quest_index)
+{
+    s16b tmp16s;
+    rd_s16b(&tmp16s);
+    q_ptr->cur_num = (MONSTER_NUMBER)tmp16s;
+    rd_s16b(&tmp16s);
+    q_ptr->max_num = (MONSTER_NUMBER)tmp16s;
+    rd_s16b(&q_ptr->type);
+
+    rd_s16b(&q_ptr->r_idx);
+    if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
+        determine_random_questor(creature_ptr, &quest[loading_quest_index]);
+
+    rd_s16b(&q_ptr->k_idx);
+    if (q_ptr->k_idx)
+        a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
+
+    byte tmp8u;
+    rd_byte(&tmp8u);
+    q_ptr->flags = tmp8u;
+}
+
+void analyze_quests(player_type *creature_ptr, const u16b max_quests_load, const byte max_rquests_load)
+{
+    QUEST_IDX old_inside_quest = creature_ptr->current_floor_ptr->inside_quest;
+    for (int i = 0; i < max_quests_load; i++) {
+        if (check_quest_index(i))
+            continue;
+
+        quest_type *const q_ptr = &quest[i];
+        load_quest_completion(q_ptr);
+        bool is_quest_running = (q_ptr->status == QUEST_STATUS_TAKEN);
+        is_quest_running |= (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED));
+        is_quest_running |= (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load)));
+        if (!is_quest_running)
+            continue;
+
+        load_quest_details(creature_ptr, q_ptr, i);
+        if (z_older_than(10, 3, 11))
+            set_zangband_quest(creature_ptr, q_ptr, i, old_inside_quest);
+        else {
+            byte tmp8u;
+            rd_byte(&tmp8u);
+            q_ptr->dungeon = tmp8u;
+        }
+
+        if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
+            if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
+                r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
+    }
+}
diff --git a/src/savedata/quest-loader.h b/src/savedata/quest-loader.h
new file mode 100644 (file)
index 0000000..b6b86c4
--- /dev/null
@@ -0,0 +1,8 @@
+#pragma once
+
+#include "system/angband.h"
+
+errr load_town(void);
+errr load_quest_info(u16b *max_quests_load, byte *max_rquests_load);
+void analyze_quests(player_type *creature_ptr, const u16b max_quests_load, const byte max_rquests_load);
+void rd_unique_info(void);