OSDN Git Service

[Refactor] #2775 ArtifactType に定義されていたtval/sval をBaseitemKey に差し替えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Mon, 14 Nov 2022 09:26:45 +0000 (18:26 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Mon, 14 Nov 2022 12:04:43 +0000 (21:04 +0900)
14 files changed:
src/artifact/fixed-art-generator.cpp
src/info-reader/artifact-reader.cpp
src/info-reader/general-parser.cpp
src/knowledge/knowledge-items.cpp
src/knowledge/knowledge-quests.cpp
src/object-hook/hook-quest.cpp
src/spell/spells-object.cpp
src/store/rumor.cpp
src/system/artifact-type-definition.cpp
src/system/artifact-type-definition.h
src/util/sort.cpp
src/wizard/fixed-artifacts-spoiler.cpp
src/wizard/wizard-item-modifier.cpp
src/wizard/wizard-special-process.cpp

index eef7aa1..96ae3b5 100644 (file)
@@ -259,14 +259,14 @@ bool create_named_art(PlayerType *player_ptr, FixedArtifactId a_idx, POSITION y,
         return false;
     }
 
-    auto i = lookup_baseitem_id({ a_ref.tval, a_ref.sval });
-    if (i == 0) {
+    auto bi_id = lookup_baseitem_id(a_ref.bi_key);
+    if (bi_id == 0) {
         return true;
     }
 
     ObjectType forge;
     auto q_ptr = &forge;
-    q_ptr->prep(i);
+    q_ptr->prep(bi_id);
     q_ptr->fixed_artifact_idx = a_idx;
     apply_artifact(player_ptr, q_ptr);
     if (drop_near(player_ptr, q_ptr, -1, y, x) == 0) {
@@ -316,11 +316,11 @@ bool make_artifact(PlayerType *player_ptr, ObjectType *o_ptr)
             continue;
         }
 
-        if (a_ref.tval != o_ptr->tval) {
+        if (a_ref.bi_key.tval() != o_ptr->tval) {
             continue;
         }
 
-        if (a_ref.sval != o_ptr->sval) {
+        if (a_ref.bi_key.sval() != o_ptr->sval) {
             continue;
         }
 
@@ -403,9 +403,9 @@ bool make_artifact_special(PlayerType *player_ptr, ObjectType *o_ptr)
          * @note INSTA_ART型固定アーティファクトのベースアイテムもチェック対象とする。
          * ベースアイテムの生成階層が足りない場合1/(不足階層*5)を満たさないと除外される。
          */
-        const auto k_idx = lookup_baseitem_id({ a_ref.tval, a_ref.sval });
-        if (baseitems_info[k_idx].level > floor_ptr->object_level) {
-            int d = (baseitems_info[k_idx].level - floor_ptr->object_level) * 5;
+        const auto bi_id = lookup_baseitem_id(a_ref.bi_key);
+        if (baseitems_info[bi_id].level > floor_ptr->object_level) {
+            int d = (baseitems_info[bi_id].level - floor_ptr->object_level) * 5;
             if (!one_in_(d)) {
                 continue;
             }
@@ -413,7 +413,7 @@ bool make_artifact_special(PlayerType *player_ptr, ObjectType *o_ptr)
 
         /*! @note 前述の条件を満たしたら、後のIDのアーティファクトはチェックせずすぐ確定し生成処理に移す /
          * Assign the template. Mega-Hack -- mark the item as an artifact. Hack: Some artifacts get random extra powers. Success. */
-        o_ptr->prep(k_idx);
+        o_ptr->prep(bi_id);
 
         o_ptr->fixed_artifact_idx = a_idx;
         return true;
index 19a4961..2228971 100644 (file)
@@ -117,8 +117,9 @@ errr parse_artifacts_info(std::string_view buf, angband_header *)
 
         const auto it = artifacts_info.rbegin();
         auto &a_ref = it->second;
-        info_set_value(a_ref.tval, tokens[1]);
-        info_set_value(a_ref.sval, tokens[2]);
+        const auto tval = i2enum<ItemKindType>(std::stoi(tokens[1], nullptr, 10));
+        const auto sval = std::stoi(tokens[2], nullptr, 10);
+        a_ref.bi_key = { tval, sval };
         info_set_value(a_ref.pval, tokens[3]);
         return PARSE_ERROR_NONE;
     }
index b258f86..f057374 100644 (file)
@@ -149,7 +149,7 @@ parse_error_type parse_line_feature(FloorType *floor_ptr, char *buf)
                 if (a_idx != FixedArtifactId::NONE) {
                     const auto &a_ref = artifacts_info.at(a_idx);
                     if (a_ref.gen_flags.has_not(ItemGenerationTraitType::INSTA_ART)) {
-                        letter[index].object = lookup_baseitem_id({ a_ref.tval, a_ref.sval });
+                        letter[index].object = lookup_baseitem_id(a_ref.bi_key);
                     }
                 }
             }
index ff72e0b..5dcdad1 100644 (file)
@@ -100,12 +100,12 @@ void do_cmd_knowledge_artifacts(PlayerType *player_ptr)
         const auto &a_ref = artifacts_info.at(a_idx);
         GAME_TEXT base_name[MAX_NLEN];
         strcpy(base_name, _("未知の伝説のアイテム", "Unknown Artifact"));
-        const auto z = lookup_baseitem_id({ a_ref.tval, a_ref.sval });
-        if (z != 0) {
+        const auto bi_id = lookup_baseitem_id(a_ref.bi_key);
+        if (bi_id != 0) {
             ObjectType forge;
             ObjectType *q_ptr;
             q_ptr = &forge;
-            q_ptr->prep(z);
+            q_ptr->prep(bi_id);
             q_ptr->fixed_artifact_idx = a_idx;
             q_ptr->ident |= IDENT_STORE;
             describe_flavor(player_ptr, base_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
index 28ad28f..d53d42f 100644 (file)
@@ -105,7 +105,7 @@ static void do_cmd_knowledge_quests_current(PlayerType *player_ptr, FILE *fff)
                         const auto &a_ref = artifacts_info.at(q_ref.reward_artifact_idx);
                         ObjectType forge;
                         auto *o_ptr = &forge;
-                        auto k_idx = lookup_baseitem_id({ a_ref.tval, a_ref.sval });
+                        auto k_idx = lookup_baseitem_id(a_ref.bi_key);
                         o_ptr->prep(k_idx);
                         o_ptr->fixed_artifact_idx = q_ref.reward_artifact_idx;
                         o_ptr->ident = IDENT_STORE;
index f31b4fd..916abf0 100644 (file)
@@ -63,5 +63,5 @@ bool object_is_quest_target(QuestId quest_idx, ObjectType *o_ptr)
         return false;
     }
 
-    return (o_ptr->tval == a_ref.tval) && (o_ptr->sval == a_ref.sval);
+    return (o_ptr->tval == a_ref.bi_key.tval()) && (o_ptr->sval == a_ref.bi_key.sval());
 }
index 0b95ec1..d8ba98c 100644 (file)
@@ -105,11 +105,11 @@ static std::optional<FixedArtifactId> sweep_amusement_artifact(const bool insta_
             continue;
         }
 
-        if (a_ref.tval != baseitems_info[k_idx].tval) {
+        if (a_ref.bi_key.tval() != baseitems_info[k_idx].tval) {
             continue;
         }
 
-        if (a_ref.sval != baseitems_info[k_idx].sval) {
+        if (a_ref.bi_key.sval() != baseitems_info[k_idx].sval) {
             continue;
         }
 
index c4cab69..62b6bd0 100644 (file)
@@ -111,7 +111,7 @@ void display_rumor(PlayerType *player_ptr, bool ex)
     if (category == "ARTIFACT") {
         const auto &artifact_name = tokens[1];
         const auto &[a_idx, a_ptr] = get_artifact_definition(artifact_name);
-        const auto k_idx = lookup_baseitem_id({ a_ptr->tval, a_ptr->sval });
+        const auto k_idx = lookup_baseitem_id(a_ptr->bi_key);
         ObjectType forge;
         auto *q_ptr = &forge;
         q_ptr->prep(k_idx);
index a1cdde3..51b3399 100644 (file)
@@ -1,5 +1,11 @@
 #include "system/artifact-type-definition.h"
 #include "artifact/fixed-art-types.h"
+#include "object/tval-types.h"
+
+ArtifactType::ArtifactType()
+    : bi_key(BaseitemKey(ItemKindType::NONE))
+{
+}
 
 std::map<FixedArtifactId, ArtifactType> artifacts_info;
 
index 36b7c19..46f16bd 100644 (file)
@@ -1,9 +1,9 @@
 #pragma once
 
-#include "system/angband.h"
-
 #include "object-enchant/tr-flags.h"
 #include "object-enchant/trg-types.h"
+#include "system/angband.h"
+#include "system/baseitem-info-definition.h"
 #include "system/object-type-definition.h"
 #include "util/flag-group.h"
 #include <map>
@@ -18,12 +18,11 @@ enum class FixedArtifactId : short;
 enum class RandomArtActType : short;
 class ArtifactType {
 public:
-    ArtifactType() = default;
+    ArtifactType();
 
     std::string name; /*!< アーティファクト名 / Name */
     std::string text; /*!< アーティファクト解説 / Text */
-    ItemKindType tval{}; /*!< ベースアイテム大項目ID / Artifact type */
-    OBJECT_SUBTYPE_VALUE sval{}; /*!< ベースアイテム小項目ID / Artifact sub type */
+    BaseitemKey bi_key;
     PARAMETER_VALUE pval{}; /*!< pval修正値 / Artifact extra info */
     HIT_PROB to_h{}; /*!< 命中ボーナス値 /  Bonus to hit */
     int to_d{}; /*!< ダメージボーナス値 / Bonus to damage */
index de799e1..63fe369 100644 (file)
@@ -270,8 +270,8 @@ bool ang_sort_art_comp(PlayerType *player_ptr, vptr u, vptr v, int a, int b)
     /* Sort by total kills */
     if (*why >= 3) {
         /* Extract total kills */
-        z1 = enum2i(artifacts_info.at(w1).tval);
-        z2 = enum2i(artifacts_info.at(w2).tval);
+        z1 = enum2i(artifacts_info.at(w1).bi_key.tval());
+        z2 = enum2i(artifacts_info.at(w2).bi_key.tval());
 
         /* Compare total kills */
         if (z1 < z2) {
@@ -286,8 +286,8 @@ bool ang_sort_art_comp(PlayerType *player_ptr, vptr u, vptr v, int a, int b)
     /* Sort by monster level */
     if (*why >= 2) {
         /* Extract levels */
-        z1 = artifacts_info.at(w1).sval;
-        z2 = artifacts_info.at(w2).sval;
+        z1 = artifacts_info.at(w1).bi_key.sval().value();
+        z2 = artifacts_info.at(w2).bi_key.sval().value();
 
         /* Compare levels */
         if (z1 < z2) {
index ee6797d..e0f1bba 100644 (file)
@@ -92,12 +92,12 @@ static bool make_fake_artifact(ObjectType *o_ptr, FixedArtifactId fixed_artifact
         return false;
     }
 
-    const auto i = lookup_baseitem_id({ a_ref.tval, a_ref.sval });
-    if (i == 0) {
+    const auto bi_id = lookup_baseitem_id(a_ref.bi_key);
+    if (bi_id == 0) {
         return false;
     }
 
-    o_ptr->prep(i);
+    o_ptr->prep(bi_id);
     o_ptr->fixed_artifact_idx = fixed_artifact_idx;
     o_ptr->pval = a_ref.pval;
     o_ptr->ac = a_ref.ac;
@@ -166,7 +166,7 @@ SpoilerOutputResultType spoil_fixed_artifact(concptr fname)
 
         for (auto tval : tval_list) {
             for (const auto &[a_idx, a_ref] : artifacts_info) {
-                if (a_ref.tval != tval) {
+                if (a_ref.bi_key.tval() != tval) {
                     continue;
                 }
 
index 415e421..2dcf9c6 100644 (file)
@@ -945,12 +945,12 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
                 continue;
             }
 
-            const auto k_idx = lookup_baseitem_id({ a_ref.tval, a_ref.sval });
-            if (!k_idx) {
+            const auto bi_id = lookup_baseitem_id(a_ref.bi_key);
+            if (bi_id == 0) {
                 continue;
             }
 
-            o_ptr->prep(k_idx);
+            o_ptr->prep(bi_id);
             o_ptr->fixed_artifact_idx = a_idx;
 
             describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
@@ -1038,16 +1038,17 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
         FixedArtifactId a_idx = FixedArtifactId::NONE;
         if (k_ptr->gen_flags.has(ItemGenerationTraitType::INSTA_ART)) {
             for (const auto &[a_idx_loop, a_ref_loop] : artifacts_info) {
-                if (a_idx_loop == FixedArtifactId::NONE || a_ref_loop.tval != k_ptr->tval || a_ref_loop.sval != k_ptr->sval) {
+                if (a_idx_loop == FixedArtifactId::NONE || a_ref_loop.bi_key.tval() != k_ptr->tval || a_ref_loop.bi_key.sval() != k_ptr->sval) {
                     continue;
                 }
+
                 a_idx = a_idx_loop;
                 break;
             }
         }
 
         if (a_idx != FixedArtifactId::NONE) {
-            auto &a_ref = artifacts_info.at(a_idx);
+            const auto &a_ref = artifacts_info.at(a_idx);
             if (must || (ok_art && !a_ref.is_generated)) {
                 (void)create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
             } else {
index 31b004a..3828f62 100644 (file)
@@ -231,15 +231,16 @@ static KIND_OBJECT_IDX wiz_create_itemtype()
 void wiz_create_item(PlayerType *player_ptr)
 {
     screen_save();
-    OBJECT_IDX k_idx = wiz_create_itemtype();
+    const auto bi_id = wiz_create_itemtype();
     screen_load();
-    if (!k_idx) {
+    if (bi_id == 0) {
         return;
     }
 
-    if (baseitems_info[k_idx].gen_flags.has(ItemGenerationTraitType::INSTA_ART)) {
+    const auto &baseitem = baseitems_info[bi_id];
+    if (baseitem.gen_flags.has(ItemGenerationTraitType::INSTA_ART)) {
         for (const auto &[a_idx, a_ref] : artifacts_info) {
-            if ((a_idx == FixedArtifactId::NONE) || (a_ref.tval != baseitems_info[k_idx].tval) || (a_ref.sval != baseitems_info[k_idx].sval)) {
+            if ((a_idx == FixedArtifactId::NONE) || (a_ref.bi_key.tval() != baseitem.tval) || (a_ref.bi_key.sval() != baseitem.sval)) {
                 continue;
             }
 
@@ -252,10 +253,9 @@ void wiz_create_item(PlayerType *player_ptr)
     ObjectType forge;
     ObjectType *q_ptr;
     q_ptr = &forge;
-    q_ptr->prep(k_idx);
+    q_ptr->prep(bi_id);
     ItemMagicApplier(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART).execute();
     (void)drop_near(player_ptr, q_ptr, -1, player_ptr->y, player_ptr->x);
-    msg_print("Allocated.");
 }
 
 /*!
@@ -268,12 +268,11 @@ static std::string wiz_make_named_artifact_desc(PlayerType *player_ptr, FixedArt
 {
     const auto &a_ref = artifacts_info.at(a_idx);
     ObjectType obj;
-    obj.prep(lookup_baseitem_id({ a_ref.tval, a_ref.sval }));
+    obj.prep(lookup_baseitem_id(a_ref.bi_key));
     obj.fixed_artifact_idx = a_idx;
     object_known(&obj);
     char buf[MAX_NLEN];
     describe_flavor(player_ptr, buf, &obj, OD_NAME_ONLY);
-
     return buf;
 }
 
@@ -346,11 +345,12 @@ static std::vector<FixedArtifactId> wiz_collect_group_a_idx(const grouper &group
     std::vector<FixedArtifactId> a_idx_list;
     for (auto tval : tval_list) {
         for (const auto &[a_idx, a_ref] : artifacts_info) {
-            if (a_ref.tval == tval) {
+            if (a_ref.bi_key.tval() == tval) {
                 a_idx_list.push_back(a_idx);
             }
         }
     }
+
     return a_idx_list;
 }
 
@@ -378,9 +378,11 @@ void wiz_create_named_art(PlayerType *player_ptr)
             return;
         default:
             if (auto idx = A2I(cmd); idx < group_artifact_list.size()) {
-                const auto a_idx_list = wiz_collect_group_a_idx(group_artifact_list[idx]);
+                const auto &a_idx_list = wiz_collect_group_a_idx(group_artifact_list[idx]);
                 create_a_idx = wiz_select_named_artifact(player_ptr, a_idx_list);
             }
+
+            break;
         }
     }