From 064e4877ede0ac146edb8af37f4cb3bafb33add4 Mon Sep 17 00:00:00 2001 From: Hourier Date: Sun, 5 Jul 2020 22:22:29 +0900 Subject: [PATCH] [Refactor] #40467 Separated quest-loader.c/h from load.c --- Hengband/Hengband/Hengband.vcxproj | 2 + Hengband/Hengband/Hengband.vcxproj.filters | 6 ++ src/Makefile.am | 1 + src/savedata/load.c | 130 +------------------------- src/savedata/quest-loader.c | 142 +++++++++++++++++++++++++++++ src/savedata/quest-loader.h | 8 ++ 6 files changed, 160 insertions(+), 129 deletions(-) create mode 100644 src/savedata/quest-loader.c create mode 100644 src/savedata/quest-loader.h diff --git a/Hengband/Hengband/Hengband.vcxproj b/Hengband/Hengband/Hengband.vcxproj index a47e10509..7cd8b56d0 100644 --- a/Hengband/Hengband/Hengband.vcxproj +++ b/Hengband/Hengband/Hengband.vcxproj @@ -612,6 +612,7 @@ + @@ -1259,6 +1260,7 @@ + diff --git a/Hengband/Hengband/Hengband.vcxproj.filters b/Hengband/Hengband/Hengband.vcxproj.filters index d846f7086..c54b2b6b5 100644 --- a/Hengband/Hengband/Hengband.vcxproj.filters +++ b/Hengband/Hengband/Hengband.vcxproj.filters @@ -1661,6 +1661,9 @@ savedata + + savedata + @@ -3628,6 +3631,9 @@ savedata + + savedata + diff --git a/src/Makefile.am b/src/Makefile.am index 86aace2bd..2c2e761cb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/savedata/load.c b/src/savedata/load.c index 174e935d6..e03ff94e3 100644 --- a/src/savedata/load.c +++ b/src/savedata/load.c @@ -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 index 000000000..02dc6637a --- /dev/null +++ b/src/savedata/quest-loader.c @@ -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 index 000000000..b6b86c419 --- /dev/null +++ b/src/savedata/quest-loader.h @@ -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); -- 2.11.0