OSDN Git Service

[Refactor] #2617 a_info を、FixedArtifactType をキーとするmapに変更した
authorHourier <66951241+Hourier@users.noreply.github.com>
Sun, 11 Sep 2022 14:18:29 +0000 (23:18 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Mon, 12 Sep 2022 08:18:11 +0000 (17:18 +0900)
42 files changed:
src/action/activation-execution.cpp
src/artifact/artifact-info.cpp
src/artifact/fixed-art-generator.cpp
src/birth/game-play-initializer.cpp
src/combat/shoot.cpp
src/dungeon/quest.cpp
src/flavor/flavor-util.cpp
src/flavor/named-item-describer.cpp
src/floor/fixed-map-generator.cpp
src/floor/floor-changer.cpp
src/floor/floor-leaver.cpp
src/floor/floor-object.cpp
src/floor/floor-streams.cpp
src/floor/floor-util.cpp
src/grid/object-placer.cpp
src/info-reader/artifact-reader.cpp
src/info-reader/general-parser.cpp
src/knowledge/knowledge-items.cpp
src/knowledge/knowledge-quests.cpp
src/load/item/item-loader-base.cpp
src/load/old/load-v1-5-0.cpp
src/load/quest-loader.cpp
src/monster-floor/monster-death.cpp
src/monster-floor/special-death-switcher.cpp
src/object-hook/hook-quest.cpp
src/object/object-flags.cpp
src/object/object-value-calc.cpp
src/object/object-value.cpp
src/perception/identification.cpp
src/racial/racial-android.cpp
src/save/save.cpp
src/specific-object/bloody-moon.cpp
src/spell-kind/spells-floor.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/artifact-analyzer.cpp
src/wizard/fixed-artifacts-spoiler.cpp
src/wizard/wizard-item-modifier.cpp
src/wizard/wizard-special-process.cpp

index fc88ef9..7dc3c5f 100644 (file)
@@ -55,7 +55,7 @@
 static void decide_activation_level(ae_type *ae_ptr)
 {
     if (ae_ptr->o_ptr->is_fixed_artifact()) {
-        ae_ptr->lev = a_info[enum2i(ae_ptr->o_ptr->fixed_artifact_idx)].level;
+        ae_ptr->lev = a_info.at(ae_ptr->o_ptr->fixed_artifact_idx).level;
         return;
     }
 
index be0afcd..b13b9ac 100644 (file)
@@ -28,9 +28,9 @@ RandomArtActType activation_index(const ObjectType *o_ptr)
         return act_idx.value();
     }
 
-    const auto fixed_art_id = enum2i(o_ptr->fixed_artifact_idx);
-    if (o_ptr->is_fixed_artifact() && a_info[fixed_art_id].flags.has(TR_ACTIVATE)) {
-        return a_info[fixed_art_id].act_idx;
+    const auto &fixed_artifact = a_info.at(o_ptr->fixed_artifact_idx);
+    if (o_ptr->is_fixed_artifact() && fixed_artifact.flags.has(TR_ACTIVATE)) {
+        return fixed_artifact.act_idx;
     }
 
     if (o_ptr->is_ego() && e_info[o_ptr->ego_idx].flags.has(TR_ACTIVATE)) {
index b14b971..e7efa72 100644 (file)
@@ -225,7 +225,7 @@ static void invest_curse_to_fixed_artifact(const ArtifactType &a_ref, ObjectType
  */
 std::unique_ptr<ArtifactType> apply_artifact(PlayerType *player_ptr, ObjectType *o_ptr)
 {
-    auto a_ptr = std::make_unique<ArtifactType>(a_info[enum2i(o_ptr->fixed_artifact_idx)]);
+    auto a_ptr = std::make_unique<ArtifactType>(a_info.at(o_ptr->fixed_artifact_idx));
     o_ptr->pval = a_ptr->pval;
     o_ptr->ac = a_ptr->ac;
     o_ptr->dd = a_ptr->dd;
@@ -256,7 +256,7 @@ std::unique_ptr<ArtifactType> apply_artifact(PlayerType *player_ptr, ObjectType
  */
 bool create_named_art(PlayerType *player_ptr, FixedArtifactId a_idx, POSITION y, POSITION x)
 {
-    auto a_ptr = &a_info[enum2i(a_idx)];
+    auto a_ptr = &a_info.at(a_idx);
     if (a_ptr->name.empty()) {
         return false;
     }
@@ -298,7 +298,7 @@ bool make_artifact(PlayerType *player_ptr, ObjectType *o_ptr)
         return false;
     }
 
-    for (const auto &a_ref : a_info) {
+    for (const auto &[a_idx, a_ref] : a_info) {
         if (a_ref.name.empty()) {
             continue;
         }
@@ -334,7 +334,7 @@ bool make_artifact(PlayerType *player_ptr, ObjectType *o_ptr)
             continue;
         }
 
-        o_ptr->fixed_artifact_idx = a_ref.idx;
+        o_ptr->fixed_artifact_idx = a_idx;
         return true;
     }
 
@@ -369,7 +369,7 @@ bool make_artifact_special(PlayerType *player_ptr, ObjectType *o_ptr)
     }
 
     /*! @note 全固定アーティファクト中からIDの若い順に生成対象とその確率を走査する / Check the artifact list (just the "specials") */
-    for (const auto &a_ref : a_info) {
+    for (const auto &[a_idx, a_ref] : a_info) {
         /*! @note アーティファクト名が空の不正なデータは除外する / Skip "empty" artifacts */
         if (a_ref.name.empty()) {
             continue;
@@ -386,8 +386,7 @@ bool make_artifact_special(PlayerType *player_ptr, ObjectType *o_ptr)
             continue;
         }
 
-        /*! @note アーティファクト生成階が現在に対して足りない場合は高確率で1/(不足階層*2)を満たさないと生成リストに加えられない /
-         *  XXX XXX Enforce minimum "depth" (loosely) */
+        /*! @note アーティファクト生成階が現在に対して足りない場合は高確率で1/(不足階層*2)を満たさないと生成リストに加えられない */
         if (a_ref.level > floor_ptr->object_level) {
             /* @note  / Acquire the "out-of-depth factor". Roll for out-of-depth creation. */
             int d = (a_ref.level - floor_ptr->object_level) * 2;
@@ -401,9 +400,10 @@ bool make_artifact_special(PlayerType *player_ptr, ObjectType *o_ptr)
             continue;
         }
 
-        /*! @note INSTA_ART型固定アーティファクトのベースアイテムもチェック対象とする。ベースアイテムの生成階層が足りない場合1/(不足階層*5)
-         * を満たさないと除外される。 / Find the base object. XXX XXX Enforce minimum "object" level (loosely). Acquire the "out-of-depth factor". Roll for
-         * out-of-depth creation. */
+        /*!
+         * @note INSTA_ART型固定アーティファクトのベースアイテムもチェック対象とする。
+         * ベースアイテムの生成階層が足りない場合1/(不足階層*5)を満たさないと除外される。
+         */
         k_idx = lookup_kind(a_ref.tval, a_ref.sval);
         if (k_info[k_idx].level > floor_ptr->object_level) {
             int d = (k_info[k_idx].level - floor_ptr->object_level) * 5;
@@ -416,7 +416,7 @@ bool make_artifact_special(PlayerType *player_ptr, ObjectType *o_ptr)
          * 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->fixed_artifact_idx = a_ref.idx;
+        o_ptr->fixed_artifact_idx = a_idx;
         return true;
     }
 
index 4906025..7cb5f67 100644 (file)
@@ -77,7 +77,7 @@ void player_wipe_without_name(PlayerType *player_ptr)
         (&player_ptr->inventory_list[i])->wipe();
     }
 
-    for (auto &a_ref : a_info) {
+    for (auto &[a_idx, a_ref] : a_info) {
         a_ref.is_generated = false;
     }
 
index ff019b7..2774618 100644 (file)
@@ -955,8 +955,7 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ObjectType *j_ptr, SPE
             if (!o_idx) {
                 msg_format(_("%sはどこかへ行った。", "The %s went somewhere."), o_name);
                 if (q_ptr->is_fixed_artifact()) {
-                    const auto fixed_artifact_idx = enum2i(j_ptr->fixed_artifact_idx);
-                    a_info[fixed_artifact_idx].is_generated = false;
+                    a_info.at(j_ptr->fixed_artifact_idx).is_generated = false;
                 }
                 return;
             }
index 591c0d6..3eda674 100644 (file)
@@ -411,7 +411,7 @@ void leave_quest_check(PlayerType *player_ptr)
         quest_list[QuestId::TOWER1].complev = player_ptr->lev;
         break;
     case QuestKindType::FIND_ARTIFACT:
-        a_info[enum2i(q_ptr->reward_artifact_idx)].gen_flags.reset(ItemGenerationTraitType::QUESTITEM);
+        a_info.at(q_ptr->reward_artifact_idx).gen_flags.reset(ItemGenerationTraitType::QUESTITEM);
         break;
     case QuestKindType::RANDOM:
         r_info[q_ptr->r_idx].flags1 &= ~(RF1_QUESTOR);
index 6f0424d..7706677 100644 (file)
@@ -197,8 +197,8 @@ char *get_ability_abbreviation(char *short_flavor, ObjectType *o_ptr, bool kanji
         flgs.reset(k_ptr->flags);
 
         if (o_ptr->is_fixed_artifact()) {
-            auto *a_ptr = &a_info[enum2i(o_ptr->fixed_artifact_idx)];
-            flgs.reset(a_ptr->flags);
+            const auto &a_ref = a_info.at(o_ptr->fixed_artifact_idx);
+            flgs.reset(a_ref.flags);
         }
 
         if (o_ptr->is_ego()) {
index 2f613f6..31f3fae 100644 (file)
@@ -59,8 +59,9 @@ static void set_base_name(flavor_type *flavor_ptr)
         return;
     }
 
-    const auto fixed_art_id = enum2i(flavor_ptr->o_ptr->fixed_artifact_idx);
-    flavor_ptr->basenm = (flavor_ptr->known && flavor_ptr->o_ptr->is_fixed_artifact() && !any_bits(flavor_ptr->mode, OD_BASE_NAME)) ? a_info[fixed_art_id].name.c_str() : flavor_ptr->kindname;
+    const auto fixed_art_id = flavor_ptr->o_ptr->fixed_artifact_idx;
+    const auto is_known_artifact = flavor_ptr->known && flavor_ptr->o_ptr->is_fixed_artifact() && none_bits(flavor_ptr->mode, OD_BASE_NAME);
+    flavor_ptr->basenm = is_known_artifact ? a_info.at(fixed_art_id).name.c_str() : flavor_ptr->kindname;
 }
 
 #ifdef JP
@@ -122,10 +123,10 @@ static void describe_artifact_ja(flavor_type *flavor_ptr)
     }
 
     if (flavor_ptr->o_ptr->is_fixed_artifact() && flavor_ptr->tr_flags.has_not(TR_FULL_NAME)) {
-        auto *a_ptr = &a_info[enum2i(flavor_ptr->o_ptr->fixed_artifact_idx)];
+        const auto &a_ref = a_info.at(flavor_ptr->o_ptr->fixed_artifact_idx);
         /* '『' から始まらない伝説のアイテムの名前は最初に付加する */
-        if (a_ptr->name.find("『", 0, 2) != 0) {
-            flavor_ptr->t = object_desc_str(flavor_ptr->t, a_ptr->name.c_str());
+        if (a_ref.name.find("『", 0, 2) != 0) {
+            flavor_ptr->t = object_desc_str(flavor_ptr->t, a_ref.name.c_str());
         }
 
         return;
@@ -215,9 +216,9 @@ static void describe_artifact_body_ja(flavor_type *flavor_ptr)
     }
 
     if (flavor_ptr->o_ptr->is_fixed_artifact()) {
-        auto *a_ptr = &a_info[enum2i(flavor_ptr->o_ptr->fixed_artifact_idx)];
-        if (a_ptr->name.find("『", 0, 2) == 0) {
-            flavor_ptr->t = object_desc_str(flavor_ptr->t, a_ptr->name.c_str());
+        const auto &a_ref = a_info.at(flavor_ptr->o_ptr->fixed_artifact_idx);
+        if (a_ref.name.find("『", 0, 2) == 0) {
+            flavor_ptr->t = object_desc_str(flavor_ptr->t, a_ref.name.c_str());
         }
 
         return;
@@ -250,10 +251,10 @@ static void describe_vowel(flavor_type *flavor_ptr)
 }
 
 /*!
- * @brief 0個、1個、2個以上の時に個数を書き分ける処理 / Process to write the number when there are 0, 1, or 2 or more.
- * @param flavor_ptr アイテム表記への参照ポインタ / Reference pointer to item's flavor
- * @return 1個ならFALSE、0または2個以上ならTRUE / If the number of items is 1, then FALE is returned, and if 0 or 2 or more, then TRUE is returned
- * @details 1個なら後続処理実行 / If the number of items is 1, then the continuous process will be run.
+ * @brief Process to write the number of items when there are 0, 1, or 2 or more.
+ * @param flavor_ptr Reference pointer to item's flavor
+ * @return If the number of items is 1, then FALE is returned, and if 0 or 2 or more, then TRUE is returned
+ * @details If the number of items is 1, then the continuous process will be run.
  */
 static bool describe_prefix_en(flavor_type *flavor_ptr)
 {
@@ -283,7 +284,9 @@ static void describe_artifact_prefix_en(flavor_type *flavor_ptr)
     }
 
     const auto corpse_r_idx = i2enum<MonsterRaceId>(flavor_ptr->o_ptr->pval);
-    if ((flavor_ptr->known && flavor_ptr->o_ptr->is_artifact()) || ((flavor_ptr->o_ptr->tval == ItemKindType::CORPSE) && r_info[corpse_r_idx].kind_flags.has(MonsterKindType::UNIQUE))) {
+    auto is_unique_corpse = flavor_ptr->o_ptr->tval == ItemKindType::CORPSE;
+    is_unique_corpse &= r_info[corpse_r_idx].kind_flags.has(MonsterKindType::UNIQUE);
+    if ((flavor_ptr->known && flavor_ptr->o_ptr->is_artifact()) || is_unique_corpse) {
         flavor_ptr->t = object_desc_str(flavor_ptr->t, "The ");
         return;
     }
@@ -320,9 +323,9 @@ static void describe_artifact_body_en(flavor_type *flavor_ptr)
     }
 
     if (flavor_ptr->o_ptr->is_fixed_artifact()) {
-        auto *a_ptr = &a_info[enum2i(flavor_ptr->o_ptr->fixed_artifact_idx)];
+        const auto &a_ref = a_info.at(flavor_ptr->o_ptr->fixed_artifact_idx);
         flavor_ptr->t = object_desc_chr(flavor_ptr->t, ' ');
-        flavor_ptr->t = object_desc_str(flavor_ptr->t, a_ptr->name.c_str());
+        flavor_ptr->t = object_desc_str(flavor_ptr->t, a_ref.name.c_str());
         return;
     }
 
index 427d25d..3bba6e5 100644 (file)
@@ -81,9 +81,9 @@ static void generate_artifact(PlayerType *player_ptr, qtwg_type *qtwg_ptr, const
         return;
     }
 
-    const auto int_artifact_index = enum2i(artifact_index);
-    if (!a_info[int_artifact_index].is_generated && create_named_art(player_ptr, artifact_index, *qtwg_ptr->y, *qtwg_ptr->x)) {
-        a_info[int_artifact_index].is_generated = true;
+    auto &fixed_artifact = a_info.at(artifact_index);
+    if (!fixed_artifact.is_generated && create_named_art(player_ptr, artifact_index, *qtwg_ptr->y, *qtwg_ptr->x)) {
+        fixed_artifact.is_generated = true;
         return;
     }
 
@@ -208,9 +208,6 @@ static bool parse_qtw_QQ(quest_type *q_ptr, char **zz, int num)
         return true;
     }
 
-    monster_race *r_ptr;
-    ArtifactType *a_ptr;
-
     if (num < 9) {
         return true;
     }
@@ -221,20 +218,30 @@ static bool parse_qtw_QQ(quest_type *q_ptr, char **zz, int num)
     q_ptr->max_num = (MONSTER_NUMBER)atoi(zz[5]);
     q_ptr->level = (DEPTH)atoi(zz[6]);
     q_ptr->r_idx = i2enum<MonsterRaceId>(atoi(zz[7]));
-    q_ptr->reward_artifact_idx = i2enum<FixedArtifactId>(atoi(zz[8]));
+    const auto a_idx = i2enum<FixedArtifactId>(atoi(zz[8]));
+    q_ptr->reward_artifact_idx = a_idx;
     q_ptr->dungeon = (DUNGEON_IDX)atoi(zz[9]);
 
     if (num > 10) {
         q_ptr->flags = atoi(zz[10]);
     }
 
-    r_ptr = &r_info[q_ptr->r_idx];
-    if (r_ptr->kind_flags.has(MonsterKindType::UNIQUE)) {
-        r_ptr->flags1 |= RF1_QUESTOR;
+    auto &r_ref = r_info[q_ptr->r_idx];
+    if (r_ref.kind_flags.has(MonsterKindType::UNIQUE)) {
+        r_ref.flags1 |= RF1_QUESTOR;
+    }
+
+    if (a_idx == FixedArtifactId::NONE) {
+        return true;
+    }
+
+    // @note 半分デッドコード。reward_artifact_idx が定義されているクエストが1つもない.
+    if (const auto it = a_info.find(a_idx); it == a_info.end()) {
+        return true;
     }
 
-    a_ptr = &a_info[enum2i(q_ptr->reward_artifact_idx)];
-    a_ptr->gen_flags.set(ItemGenerationTraitType::QUESTITEM);
+    auto &a_ref = a_info.at(q_ptr->reward_artifact_idx);
+    a_ref.gen_flags.set(ItemGenerationTraitType::QUESTITEM);
     return true;
 }
 
@@ -259,7 +266,7 @@ static bool parse_qtw_QR(quest_type *q_ptr, char **zz, int num)
             continue;
         }
 
-        if (a_info[enum2i(a_idx)].is_generated) {
+        if (a_info.at(a_idx).is_generated) {
             continue;
         }
 
@@ -271,7 +278,7 @@ static bool parse_qtw_QR(quest_type *q_ptr, char **zz, int num)
 
     if (reward_idx != FixedArtifactId::NONE) {
         q_ptr->reward_artifact_idx = reward_idx;
-        a_info[enum2i(reward_idx)].gen_flags.set(ItemGenerationTraitType::QUESTITEM);
+        a_info.at(reward_idx).gen_flags.set(ItemGenerationTraitType::QUESTITEM);
     } else {
         q_ptr->type = QuestKindType::KILL_ALL;
     }
index be39c25..2f173e6 100644 (file)
@@ -195,7 +195,7 @@ static void update_unique_artifact(floor_type *floor_ptr, int16_t cur_floor_id)
         }
 
         if (o_ptr->is_fixed_artifact()) {
-            a_info[enum2i(o_ptr->fixed_artifact_idx)].floor_id = cur_floor_id;
+            a_info.at(o_ptr->fixed_artifact_idx).floor_id = cur_floor_id;
         }
     }
 }
@@ -296,9 +296,9 @@ static void new_floor_allocation(PlayerType *player_ptr, saved_floor_type *sf_pt
             continue;
         }
 
-        const auto fixed_artifact_idx = enum2i(o_ptr->fixed_artifact_idx);
-        if (a_info[fixed_artifact_idx].floor_id == new_floor_id) {
-            a_info[fixed_artifact_idx].is_generated = true;
+        auto &fixed_artifact = a_info.at(o_ptr->fixed_artifact_idx);
+        if (fixed_artifact.floor_id == new_floor_id) {
+            fixed_artifact.is_generated = true;
         } else {
             delete_object_idx(player_ptr, i);
         }
index 7250e7a..af85de8 100644 (file)
@@ -296,7 +296,7 @@ static void preserve_info(PlayerType *player_ptr)
         }
 
         if (o_ptr->is_fixed_artifact()) {
-            a_info[enum2i(o_ptr->fixed_artifact_idx)].floor_id = 0;
+            a_info.at(o_ptr->fixed_artifact_idx).floor_id = 0;
         }
     }
 }
index 63bfc8e..64ca9b8 100644 (file)
@@ -485,8 +485,7 @@ OBJECT_IDX drop_near(PlayerType *player_ptr, ObjectType *j_ptr, PERCENTAGE chanc
 
             if (preserve_mode) {
                 if (j_ptr->is_fixed_artifact() && !j_ptr->is_known()) {
-                    const auto fixed_artifact_idx = enum2i(j_ptr->fixed_artifact_idx);
-                    a_info[fixed_artifact_idx].is_generated = false;
+                    a_info.at(j_ptr->fixed_artifact_idx).is_generated = false;
                 }
             }
 
@@ -539,8 +538,7 @@ OBJECT_IDX drop_near(PlayerType *player_ptr, ObjectType *j_ptr, PERCENTAGE chanc
         }
 
         if (j_ptr->is_fixed_artifact()) {
-            const auto fixed_artifact_idx = enum2i(j_ptr->fixed_artifact_idx);
-            a_info[fixed_artifact_idx].is_generated = false;
+            a_info.at(j_ptr->fixed_artifact_idx).is_generated = false;
         }
 
         return 0;
index b3ca8b2..d23ea15 100644 (file)
@@ -353,7 +353,7 @@ void build_streamer(PlayerType *player_ptr, FEAT_IDX feat, int chance)
 
                     /* Hack -- Preserve unknown artifacts */
                     if (o_ptr->is_fixed_artifact()) {
-                        a_info[enum2i(o_ptr->fixed_artifact_idx)].is_generated = false;
+                        a_info.at(o_ptr->fixed_artifact_idx).is_generated = false;
 
                         if (cheat_peek) {
                             GAME_TEXT o_name[MAX_NLEN];
index 38a5edb..c608c48 100644 (file)
@@ -131,7 +131,7 @@ void wipe_o_list(floor_type *floor_ptr)
 
         if (!w_ptr->character_dungeon || preserve_mode) {
             if (o_ptr->is_fixed_artifact() && !o_ptr->is_known()) {
-                a_info[enum2i(o_ptr->fixed_artifact_idx)].is_generated = false;
+                a_info.at(o_ptr->fixed_artifact_idx).is_generated = false;
             }
         }
 
index 5a76ee4..dc4bbe3 100644 (file)
@@ -90,8 +90,7 @@ void place_object(PlayerType *player_ptr, POSITION y, POSITION x, BIT_FLAGS mode
     OBJECT_IDX o_idx = o_pop(floor_ptr);
     if (o_idx == 0) {
         if (q_ptr->is_fixed_artifact()) {
-            const auto fixed_artifact_idx = enum2i(q_ptr->fixed_artifact_idx);
-            a_info[fixed_artifact_idx].is_generated = false;
+            a_info.at(q_ptr->fixed_artifact_idx).is_generated = false;
         }
 
         return;
index 393097c..becfda9 100644 (file)
@@ -1,4 +1,5 @@
 #include "info-reader/artifact-reader.h"
+#include "artifact/fixed-art-types.h"
 #include "artifact/random-art-effects.h"
 #include "info-reader/info-reader-util.h"
 #include "info-reader/kind-info-tokens-table.h"
@@ -38,6 +39,7 @@ static bool grab_one_artifact_flag(ArtifactType *a_ptr, std::string_view what)
  * @param buf テキスト列
  * @param head ヘッダ構造体
  * @return エラーコード
+ * @todo static ArtifactType *a_ptr は設計変更で不要にできるかもしれない (mapの最終要素を取り出せば良い)
  */
 errr parse_a_info(std::string_view buf, angband_header *)
 {
@@ -50,22 +52,20 @@ errr parse_a_info(std::string_view buf, angband_header *)
             return PARSE_ERROR_GENERIC;
         }
 
-        auto i = std::stoi(tokens[1]);
-        if (i < error_idx) {
+        const auto int_idx = std::stoi(tokens[1]);
+        const auto a_idx = i2enum<FixedArtifactId>(int_idx);
+        if (int_idx < error_idx) {
             return PARSE_ERROR_NON_SEQUENTIAL_RECORDS;
         }
-        if (i >= static_cast<int>(a_info.size())) {
-            a_info.resize(i + 1);
-        }
 
-        error_idx = i;
-        a_ptr = &a_info[i];
-        a_ptr->idx = i2enum<FixedArtifactId>(i);
+        error_idx = int_idx;
+        ArtifactType artifact;
+        a_info.emplace(a_idx, artifact);
+        a_ptr = &a_info.at(a_idx);
         a_ptr->flags.set(TR_IGNORE_ACID);
         a_ptr->flags.set(TR_IGNORE_ELEC);
         a_ptr->flags.set(TR_IGNORE_FIRE);
         a_ptr->flags.set(TR_IGNORE_COLD);
-
 #ifdef JP
         a_ptr->name = tokens[2];
 #endif
index dc561f9..81a76fa 100644 (file)
@@ -146,9 +146,9 @@ parse_error_type parse_line_feature(floor_type *floor_ptr, char *buf)
                 const auto &quest_list = QuestList::get_instance();
                 const auto a_idx = quest_list[floor_ptr->quest_number].reward_artifact_idx;
                 if (a_idx != FixedArtifactId::NONE) {
-                    const auto *a_ptr = &a_info[enum2i(a_idx)];
-                    if (a_ptr->gen_flags.has_not(ItemGenerationTraitType::INSTA_ART)) {
-                        letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
+                    const auto &a_ref = a_info.at(a_idx);
+                    if (a_ref.gen_flags.has_not(ItemGenerationTraitType::INSTA_ART)) {
+                        letter[index].object = lookup_kind(a_ref.tval, a_ref.sval);
                     }
                 }
             }
index 936958d..53cd248 100644 (file)
@@ -52,7 +52,7 @@ void do_cmd_knowledge_artifacts(PlayerType *player_ptr)
         okay.emplace(i2enum<FixedArtifactId>(i), false);
     }
 
-    for (const auto &a_ref : a_info) {
+    for (const auto &[a_idx, a_ref] : a_info) {
         if (a_ref.name.empty()) {
             continue;
         }
@@ -60,7 +60,7 @@ void do_cmd_knowledge_artifacts(PlayerType *player_ptr)
             continue;
         }
 
-        okay[a_ref.idx] = true;
+        okay[a_idx] = true;
     }
 
     for (POSITION y = 0; y < player_ptr->current_floor_ptr->height; y++) {
@@ -97,19 +97,19 @@ void do_cmd_knowledge_artifacts(PlayerType *player_ptr)
     }
 
     std::vector<FixedArtifactId> whats;
-    for (const auto &a_ref : a_info) {
-        if (okay[a_ref.idx]) {
-            whats.push_back(a_ref.idx);
+    for (const auto &[a_idx, a_ref] : a_info) {
+        if (okay[a_idx]) {
+            whats.push_back(a_idx);
         }
     }
 
     uint16_t why = 3;
     ang_sort(player_ptr, whats.data(), &why, whats.size(), ang_sort_art_comp, ang_sort_art_swap);
     for (auto a_idx : whats) {
-        auto *a_ptr = &a_info[enum2i(a_idx)];
+        const auto &a_ref = a_info.at(a_idx);
         GAME_TEXT base_name[MAX_NLEN];
         strcpy(base_name, _("未知の伝説のアイテム", "Unknown Artifact"));
-        const auto z = lookup_kind(a_ptr->tval, a_ptr->sval);
+        const auto z = lookup_kind(a_ref.tval, a_ref.sval);
         if (z != 0) {
             ObjectType forge;
             ObjectType *q_ptr;
index 060036e..7955c35 100644 (file)
@@ -101,10 +101,10 @@ static void do_cmd_knowledge_quests_current(PlayerType *player_ptr, FILE *fff)
 
                 case QuestKindType::FIND_ARTIFACT:
                     if (q_ref.reward_artifact_idx != FixedArtifactId::NONE) {
-                        auto *a_ptr = &a_info[enum2i(q_ref.reward_artifact_idx)];
+                        const auto &a_ref = a_info.at(q_ref.reward_artifact_idx);
                         ObjectType forge;
                         auto *o_ptr = &forge;
-                        KIND_OBJECT_IDX k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
+                        KIND_OBJECT_IDX k_idx = lookup_kind(a_ref.tval, a_ref.sval);
                         o_ptr->prep(k_idx);
                         o_ptr->fixed_artifact_idx = q_ref.reward_artifact_idx;
                         o_ptr->ident = IDENT_STORE;
index ccd0b21..1feebe4 100644 (file)
@@ -1,9 +1,11 @@
 #include "load/item/item-loader-base.h"
+#include "artifact/fixed-art-types.h"
 #include "load/angband-version-comparer.h"
 #include "load/load-util.h"
 #include "object/object-kind.h"
 #include "system/artifact-type-definition.h"
 #include "util/bit-flags-calculator.h"
+#include "util/enum-converter.h"
 
 /*!
  * @brief アイテムオブジェクトの鑑定情報をロードする.
@@ -27,16 +29,18 @@ void ItemLoaderBase::load_item(void)
  */
 void ItemLoaderBase::load_artifact(void)
 {
-    auto loading_max_a_idx = rd_u16b();
     ArtifactType dummy;
+    auto loading_max_a_idx = rd_u16b();
     for (auto i = 0U; i < loading_max_a_idx; i++) {
-        auto *a_ptr = i < a_info.size() ? &a_info[i] : &dummy;
-        a_ptr->is_generated = rd_bool();
+        const auto a_idx = i2enum<FixedArtifactId>(i);
+        const auto it = a_info.find(a_idx);
+        auto &artifact = it != a_info.end() ? it->second : dummy;
+        artifact.is_generated = rd_bool();
         if (h_older_than(1, 5, 0, 0)) {
-            a_ptr->floor_id = 0;
+            artifact.floor_id = 0;
             strip_bytes(3);
         } else {
-            a_ptr->floor_id = rd_s16b();
+            artifact.floor_id = rd_s16b();
         }
     }
 
index 41f3831..49f4b93 100644 (file)
@@ -132,19 +132,19 @@ void rd_item_old(ObjectType *o_ptr)
                 o_ptr->curse_flags.set(CurseTraitType::PERMA_CURSE);
             }
             if (o_ptr->is_fixed_artifact()) {
-                auto *a_ptr = &a_info[enum2i(o_ptr->fixed_artifact_idx)];
-                if (a_ptr->gen_flags.has(ItemGenerationTraitType::HEAVY_CURSE)) {
+                const auto &a_ref = a_info.at(o_ptr->fixed_artifact_idx);
+                if (a_ref.gen_flags.has(ItemGenerationTraitType::HEAVY_CURSE)) {
                     o_ptr->curse_flags.set(CurseTraitType::HEAVY_CURSE);
                 }
-                if (a_ptr->gen_flags.has(ItemGenerationTraitType::PERMA_CURSE)) {
+                if (a_ref.gen_flags.has(ItemGenerationTraitType::PERMA_CURSE)) {
                     o_ptr->curse_flags.set(CurseTraitType::PERMA_CURSE);
                 }
             } else if (o_ptr->is_ego()) {
-                auto *e_ptr = &e_info[o_ptr->ego_idx];
-                if (e_ptr->gen_flags.has(ItemGenerationTraitType::HEAVY_CURSE)) {
+                const auto &e_ref = e_info[o_ptr->ego_idx];
+                if (e_ref.gen_flags.has(ItemGenerationTraitType::HEAVY_CURSE)) {
                     o_ptr->curse_flags.set(CurseTraitType::HEAVY_CURSE);
                 }
-                if (e_ptr->gen_flags.has(ItemGenerationTraitType::PERMA_CURSE)) {
+                if (e_ref.gen_flags.has(ItemGenerationTraitType::PERMA_CURSE)) {
                     o_ptr->curse_flags.set(CurseTraitType::PERMA_CURSE);
                 }
             }
@@ -339,15 +339,15 @@ void rd_item_old(ObjectType *o_ptr)
     }
 
     if (o_ptr->is_fixed_artifact()) {
-        const auto *a_ptr = &a_info[enum2i(o_ptr->fixed_artifact_idx)];
-        if (a_ptr->name.empty()) {
+        const auto &a_ref = a_info.at(o_ptr->fixed_artifact_idx);
+        if (a_ref.name.empty()) {
             o_ptr->fixed_artifact_idx = FixedArtifactId::NONE;
         }
     }
 
     if (o_ptr->is_ego()) {
-        auto *e_ptr = &e_info[o_ptr->ego_idx];
-        if (e_ptr->name.empty()) {
+        const auto &e_ref = e_info[o_ptr->ego_idx];
+        if (e_ref.name.empty()) {
             o_ptr->ego_idx = EgoType::NONE;
         }
     }
index bcad92c..f21dea3 100644 (file)
@@ -72,7 +72,7 @@ static void load_quest_details(PlayerType *player_ptr, quest_type *q_ptr, const
     }
     q_ptr->reward_artifact_idx = i2enum<FixedArtifactId>(rd_s16b());
     if (q_ptr->reward_artifact_idx != FixedArtifactId::NONE) {
-        a_info[enum2i(q_ptr->reward_artifact_idx)].gen_flags.set(ItemGenerationTraitType::QUESTITEM);
+        a_info.at(q_ptr->reward_artifact_idx).gen_flags.set(ItemGenerationTraitType::QUESTITEM);
     }
 
     q_ptr->flags = rd_byte();
index 93b841d..3b05364 100644 (file)
@@ -179,20 +179,20 @@ static FixedArtifactId drop_artifact_index(PlayerType *player_ptr, monster_death
  */
 bool drop_single_artifact(PlayerType *player_ptr, monster_death_type *md_ptr, FixedArtifactId a_idx)
 {
-    auto *a_ptr = &a_info[enum2i(a_idx)];
-    if (a_ptr->is_generated) {
+    auto &a_ref = a_info.at(a_idx);
+    if (a_ref.is_generated) {
         return false;
     }
 
     if (create_named_art(player_ptr, a_idx, md_ptr->md_y, md_ptr->md_x)) {
-        a_ptr->is_generated = true;
+        a_ref.is_generated = true;
 
         if (w_ptr->character_dungeon) {
-            a_ptr->floor_id = player_ptr->floor_id;
+            a_ref.floor_id = player_ptr->floor_id;
         }
 
         if (!preserve_mode) {
-            a_ptr->is_generated = true;
+            a_ref.is_generated = true;
         }
 
         return true;
@@ -208,17 +208,17 @@ static KIND_OBJECT_IDX drop_dungeon_final_artifact(PlayerType *player_ptr, monst
     }
 
     a_idx = d_info[player_ptr->dungeon_idx].final_artifact;
-    auto *a_ptr = &a_info[enum2i(a_idx)];
-    if (a_ptr->is_generated) {
+    auto &a_ref = a_info.at(a_idx);
+    if (a_ref.is_generated) {
         return k_idx;
     }
     if (create_named_art(player_ptr, a_idx, md_ptr->md_y, md_ptr->md_x)) {
-        a_ptr->is_generated = true;
+        a_ref.is_generated = true;
         if (w_ptr->character_dungeon) {
-            a_ptr->floor_id = player_ptr->floor_id;
+            a_ref.floor_id = player_ptr->floor_id;
         }
     } else if (!preserve_mode) {
-        a_ptr->is_generated = true;
+        a_ref.is_generated = true;
     }
 
     return d_info[player_ptr->dungeon_idx].final_object ? k_idx : 0;
index 7e09f41..96f7b5a 100644 (file)
@@ -183,7 +183,7 @@ static void on_dead_sacred_treasures(PlayerType *player_ptr, monster_death_type
             break;
         }
 
-        a_ptr = &a_info[enum2i(a_idx)];
+        a_ptr = &a_info.at(a_idx);
     } while (a_ptr->is_generated);
 
     if (create_named_art(player_ptr, a_idx, md_ptr->md_y, md_ptr->md_x)) {
index 8bde8b9..cc3efc2 100644 (file)
@@ -58,10 +58,10 @@ bool object_is_quest_target(QuestId quest_idx, ObjectType *o_ptr)
         return false;
     }
 
-    auto *a_ptr = &a_info[enum2i(a_idx)];
-    if (a_ptr->gen_flags.has(ItemGenerationTraitType::INSTA_ART)) {
+    const auto &a_ref = a_info.at(a_idx);
+    if (a_ref.gen_flags.has(ItemGenerationTraitType::INSTA_ART)) {
         return false;
     }
 
-    return (o_ptr->tval == a_ptr->tval) && (o_ptr->sval == a_ptr->sval);
+    return (o_ptr->tval == a_ref.tval) && (o_ptr->sval == a_ref.sval);
 }
index cb489b0..694f16b 100644 (file)
@@ -55,7 +55,7 @@ TrFlags object_flags(const ObjectType *o_ptr)
     auto flgs = k_ptr->flags;
 
     if (o_ptr->is_fixed_artifact()) {
-        flgs = a_info[enum2i(o_ptr->fixed_artifact_idx)].flags;
+        flgs = a_info.at(o_ptr->fixed_artifact_idx).flags;
     }
 
     object_flags_lite(o_ptr, flgs);
@@ -100,7 +100,7 @@ TrFlags object_flags_known(const ObjectType *o_ptr)
     object_flags_lite(o_ptr, flgs);
     if (spoil || o_ptr->is_fully_known()) {
         if (o_ptr->is_fixed_artifact()) {
-            flgs = a_info[enum2i(o_ptr->fixed_artifact_idx)].flags;
+            flgs = a_info.at(o_ptr->fixed_artifact_idx).flags;
         }
 
         /* Random artifact ! */
index 1e30c41..8533c36 100644 (file)
@@ -31,11 +31,11 @@ PRICE flag_cost(const ObjectType *o_ptr, int plusses)
     flgs.reset(k_ptr->flags);
 
     if (o_ptr->is_fixed_artifact()) {
-        auto *a_ptr = &a_info[enum2i(o_ptr->fixed_artifact_idx)];
-        flgs.reset(a_ptr->flags);
+        const auto &a_ref = a_info.at(o_ptr->fixed_artifact_idx);
+        flgs.reset(a_ref.flags);
     } else if (o_ptr->is_ego()) {
-        auto *e_ptr = &e_info[o_ptr->ego_idx];
-        flgs.reset(e_ptr->flags);
+        const auto &e_ref = e_info[o_ptr->ego_idx];
+        flgs.reset(e_ref.flags);
     }
 
     /*
index 358f690..bd171bf 100644 (file)
@@ -157,21 +157,21 @@ PRICE object_value_real(const ObjectType *o_ptr)
     PRICE value = k_info[o_ptr->k_idx].cost;
     auto flgs = object_flags(o_ptr);
     if (o_ptr->is_fixed_artifact()) {
-        auto *a_ptr = &a_info[enum2i(o_ptr->fixed_artifact_idx)];
-        if (!a_ptr->cost) {
+        const auto &a_ref = a_info.at(o_ptr->fixed_artifact_idx);
+        if (!a_ref.cost) {
             return 0;
         }
 
-        value = a_ptr->cost;
+        value = a_ref.cost;
         value += flag_cost(o_ptr, o_ptr->pval);
         return value;
     } else if (o_ptr->is_ego()) {
-        auto *e_ptr = &e_info[o_ptr->ego_idx];
-        if (!e_ptr->cost) {
+        const auto &e_ref = e_info[o_ptr->ego_idx];
+        if (!e_ref.cost) {
             return 0;
         }
 
-        value += e_ptr->cost;
+        value += e_ref.cost;
         value += flag_cost(o_ptr, o_ptr->pval);
     } else {
         if (o_ptr->art_flags.any()) {
index 7d8eb09..4f1b8bf 100644 (file)
@@ -43,7 +43,8 @@ bool screen_object(PlayerType *player_ptr, ObjectType *o_ptr, BIT_FLAGS mode)
     int trivial_info = 0;
     auto flgs = object_flags(o_ptr);
 
-    shape_buffer(o_ptr->is_fixed_artifact() ? a_info[enum2i(o_ptr->fixed_artifact_idx)].text.c_str() : k_info[o_ptr->k_idx].text.c_str(), 77 - 15, temp, sizeof(temp));
+    const auto item_text = o_ptr->is_fixed_artifact() ? a_info.at(o_ptr->fixed_artifact_idx).text.c_str() : k_info[o_ptr->k_idx].text.c_str();
+    shape_buffer(item_text, 77 - 15, temp, sizeof(temp));
 
     int i = 0;
     for (int j = 0; temp[j]; j += 1 + strlen(&temp[j])) {
index acfd283..df6d3a1 100644 (file)
@@ -83,9 +83,9 @@ void calc_android_exp(PlayerType *player_ptr)
         q_ptr->curse_flags.clear();
 
         if (o_ptr->is_fixed_artifact()) {
-            const auto fixed_artifact_idx = enum2i(o_ptr->fixed_artifact_idx);
-            level = (level + std::max(a_info[fixed_artifact_idx].level - 8, 5)) / 2;
-            level += std::min(20, a_info[fixed_artifact_idx].rarity / (a_info[fixed_artifact_idx].gen_flags.has(ItemGenerationTraitType::INSTA_ART) ? 10 : 3));
+            const auto &fixed_artifact = a_info.at(o_ptr->fixed_artifact_idx);
+            level = (level + std::max(fixed_artifact.level - 8, 5)) / 2;
+            level += std::min(20, fixed_artifact.rarity / (fixed_artifact.gen_flags.has(ItemGenerationTraitType::INSTA_ART) ? 10 : 3));
         } else if (o_ptr->is_ego()) {
             level += std::max(3, (e_info[o_ptr->ego_idx].rating - 5) / 2);
         } else if (o_ptr->art_name) {
index d0a7a64..cd233f1 100644 (file)
@@ -41,6 +41,7 @@
 #include "util/angband-files.h"
 #include "view/display-messages.h"
 #include "world/world.h"
+#include <algorithm>
 
 /*!
  * @brief セーブデータの書き込み /
@@ -166,12 +167,21 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type)
         }
     }
 
-    tmp16u = static_cast<uint16_t>(a_info.size());
+    std::vector<short> a_nums;
+    for (const auto &[a_idx, a_ref] : a_info) {
+        a_nums.push_back(enum2i(a_idx));
+    }
+
+    auto max_a_num = *std::max_element(a_nums.begin(), a_nums.end());
+    tmp16u = max_a_num + 1;
     wr_u16b(tmp16u);
-    for (int i = 0; i < tmp16u; i++) {
-        auto *a_ptr = &a_info[i];
-        wr_bool(a_ptr->is_generated);
-        wr_s16b(a_ptr->floor_id);
+    ArtifactType dummy;
+    for (auto i = 0U; i < tmp16u; i++) {
+        const auto a_idx = i2enum<FixedArtifactId>(i);
+        const auto it = a_info.find(a_idx);
+        const auto &a_ref = it != a_info.end() ? a_info.at(a_idx) : dummy;
+        wr_bool(a_ref.is_generated);
+        wr_s16b(a_ref.floor_id);
     }
 
     wr_u32b(w_ptr->sf_play_time);
index 1e8d92e..dfcc7e2 100644 (file)
@@ -18,7 +18,7 @@
  */
 void get_bloody_moon_flags(ObjectType *o_ptr)
 {
-    o_ptr->art_flags = a_info[enum2i(FixedArtifactId::BLOOD)].flags;
+    o_ptr->art_flags = a_info.at(FixedArtifactId::BLOOD).flags;
 
     int dummy = randint1(2) + randint1(2);
     for (int i = 0; i < dummy; i++) {
index 0848ee8..606799f 100644 (file)
@@ -345,7 +345,7 @@ bool destroy_area(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION r,
 
                     /* Hack -- Preserve unknown artifacts */
                     if (o_ptr->is_fixed_artifact() && (!o_ptr->is_known() || in_generate)) {
-                        a_info[enum2i(o_ptr->fixed_artifact_idx)].is_generated = false;
+                        a_info.at(o_ptr->fixed_artifact_idx).is_generated = false;
 
                         if (in_generate && cheat_peek) {
                             GAME_TEXT o_name[MAX_NLEN];
index 4941c07..baf3449 100644 (file)
@@ -89,8 +89,8 @@ static const std::vector<amuse_type> amuse_info = {
 
 static std::optional<FixedArtifactId> sweep_amusement_artifact(const bool insta_art, const short k_idx)
 {
-    for (const auto &a_ref : a_info) {
-        if (a_ref.idx == FixedArtifactId::NONE) {
+    for (const auto &[a_idx, a_ref] : a_info) {
+        if (a_idx == FixedArtifactId::NONE) {
             continue;
         }
 
@@ -110,7 +110,7 @@ static std::optional<FixedArtifactId> sweep_amusement_artifact(const bool insta_
             continue;
         }
 
-        return a_ref.idx;
+        return a_idx;
     }
 
     return std::nullopt;
index 7269fd4..7d5f996 100644 (file)
@@ -70,7 +70,7 @@ void display_rumor(PlayerType *player_ptr, bool ex)
         while (true) {
             a_idx = i2enum<FixedArtifactId>(rumor_num(zz[1], static_cast<IDX>(a_info.size())));
 
-            a_ptr = &a_info[enum2i(a_idx)];
+            a_ptr = &a_info.at(a_idx);
             if (!a_ptr->name.empty()) {
                 break;
             }
index adb945b..c25a4a9 100644 (file)
@@ -3,4 +3,4 @@
 /*
  * The artifact arrays
  */
-std::vector<ArtifactType> a_info;
+std::map<FixedArtifactId, ArtifactType> a_info;
index 12794ed..ca8b052 100644 (file)
@@ -6,20 +6,19 @@
 #include "object-enchant/trg-types.h"
 #include "system/object-type-definition.h"
 #include "util/flag-group.h"
+#include <map>
 #include <string>
-#include <vector>
 
 /*!
  * @class ArtifactType
  * @brief 固定アーティファクト情報の構造体 / Artifact structure.
- * @details is_generated フィールドのみセーブファイルへの保存対象
+ * @details is_generated ã\81¨floor_id ã\83\95ã\82£ã\83¼ã\83«ã\83\89ã\81®ã\81¿ã\82»ã\83¼ã\83\96ã\83\95ã\82¡ã\82¤ã\83«ã\81¸ã\81®ä¿\9då­\98対象
  */
 enum class FixedArtifactId : short;
 enum class RandomArtActType : short;
 class ArtifactType {
 public:
     ArtifactType() = default;
-    FixedArtifactId idx{};
 
     std::string name; /*!< アーティファクト名 / Name */
     std::string text; /*!< アーティファクト解説 / Text */
@@ -43,4 +42,4 @@ public:
     RandomArtActType act_idx{}; /*! 発動能力ID / Activative ability index */
 };
 
-extern std::vector<ArtifactType> a_info;
+extern std::map<FixedArtifactId, ArtifactType> a_info;
index f7846a4..d52d839 100644 (file)
@@ -1,4 +1,5 @@
 #include "util/sort.h"
+#include "artifact/fixed-art-types.h"
 #include "dungeon/quest.h"
 #include "grid/feature.h"
 #include "grid/grid.h"
@@ -260,16 +261,17 @@ bool ang_sort_art_comp(PlayerType *player_ptr, vptr u, vptr v, int a, int b)
     uint16_t *who = (uint16_t *)(u);
     uint16_t *why = (uint16_t *)(v);
 
-    int w1 = who[a];
-    int w2 = who[b];
+    const auto w1 = i2enum<FixedArtifactId>(who[a]);
+    const auto w2 = i2enum<FixedArtifactId>(who[b]);
 
-    int z1, z2;
+    int z1;
+    int z2;
 
     /* Sort by total kills */
     if (*why >= 3) {
         /* Extract total kills */
-        z1 = enum2i(a_info[w1].tval);
-        z2 = enum2i(a_info[w2].tval);
+        z1 = enum2i(a_info.at(w1).tval);
+        z2 = enum2i(a_info.at(w2).tval);
 
         /* Compare total kills */
         if (z1 < z2) {
@@ -284,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 = a_info[w1].sval;
-        z2 = a_info[w2].sval;
+        z1 = a_info.at(w1).sval;
+        z2 = a_info.at(w2).sval;
 
         /* Compare levels */
         if (z1 < z2) {
@@ -300,8 +302,8 @@ bool ang_sort_art_comp(PlayerType *player_ptr, vptr u, vptr v, int a, int b)
     /* Sort by monster experience */
     if (*why >= 1) {
         /* Extract experience */
-        z1 = a_info[w1].level;
-        z2 = a_info[w2].level;
+        z1 = a_info.at(w1).level;
+        z2 = a_info.at(w2).level;
 
         /* Compare experience */
         if (z1 < z2) {
index 289408e..173af6c 100644 (file)
@@ -259,26 +259,26 @@ static void analyze_misc_magic(ObjectType *o_ptr, concptr *misc_list)
  */
 static void analyze_addition(ObjectType *o_ptr, char *addition)
 {
-    auto *a_ptr = &a_info[enum2i(o_ptr->fixed_artifact_idx)];
+    const auto &a_ref = a_info.at(o_ptr->fixed_artifact_idx);
     strcpy(addition, "");
 
-    if (a_ptr->gen_flags.has_all_of({ ItemGenerationTraitType::XTRA_POWER, ItemGenerationTraitType::XTRA_H_RES })) {
+    if (a_ref.gen_flags.has_all_of({ ItemGenerationTraitType::XTRA_POWER, ItemGenerationTraitType::XTRA_H_RES })) {
         strcat(addition, _("能力and耐性", "Ability and Resistance"));
-    } else if (a_ptr->gen_flags.has(ItemGenerationTraitType::XTRA_POWER)) {
+    } else if (a_ref.gen_flags.has(ItemGenerationTraitType::XTRA_POWER)) {
         strcat(addition, _("能力", "Ability"));
-        if (a_ptr->gen_flags.has(ItemGenerationTraitType::XTRA_RES_OR_POWER)) {
+        if (a_ref.gen_flags.has(ItemGenerationTraitType::XTRA_RES_OR_POWER)) {
             strcat(addition, _("(1/2でand耐性)", "(plus Resistance about 1/2)"));
         }
-    } else if (a_ptr->gen_flags.has(ItemGenerationTraitType::XTRA_H_RES)) {
+    } else if (a_ref.gen_flags.has(ItemGenerationTraitType::XTRA_H_RES)) {
         strcat(addition, _("耐性", "Resistance"));
-        if (a_ptr->gen_flags.has(ItemGenerationTraitType::XTRA_RES_OR_POWER)) {
+        if (a_ref.gen_flags.has(ItemGenerationTraitType::XTRA_RES_OR_POWER)) {
             strcat(addition, _("(1/2でand能力)", "(plus Ability about 1/2)"));
         }
-    } else if (a_ptr->gen_flags.has(ItemGenerationTraitType::XTRA_RES_OR_POWER)) {
+    } else if (a_ref.gen_flags.has(ItemGenerationTraitType::XTRA_RES_OR_POWER)) {
         strcat(addition, _("能力or耐性", "Ability or Resistance"));
     }
 
-    if (a_ptr->gen_flags.has(ItemGenerationTraitType::XTRA_DICE)) {
+    if (a_ref.gen_flags.has(ItemGenerationTraitType::XTRA_DICE)) {
         if (strlen(addition) > 0) {
             strcat(addition, _("、", ", "));
         }
@@ -295,9 +295,9 @@ static void analyze_addition(ObjectType *o_ptr, char *addition)
  */
 static void analyze_misc(ObjectType *o_ptr, char *misc_desc)
 {
-    auto *a_ptr = &a_info[enum2i(o_ptr->fixed_artifact_idx)];
-    sprintf(misc_desc, _("レベル %d, 希少度 %u, %d.%d kg, $%ld", "Level %d, Rarity %u, %d.%d lbs, %ld Gold"), (int)a_ptr->level, a_ptr->rarity,
-        _(lb_to_kg_integer(a_ptr->weight), a_ptr->weight / 10), _(lb_to_kg_fraction(a_ptr->weight), a_ptr->weight % 10), (long int)a_ptr->cost);
+    const auto &a_ref = a_info.at(o_ptr->fixed_artifact_idx);
+    sprintf(misc_desc, _("レベル %d, 希少度 %u, %d.%d kg, $%ld", "Level %d, Rarity %u, %d.%d lbs, %ld Gold"), (int)a_ref.level, a_ref.rarity,
+        _(lb_to_kg_integer(a_ref.weight), a_ref.weight / 10), _(lb_to_kg_fraction(a_ref.weight), a_ref.weight % 10), (long int)a_ref.cost);
 }
 
 /*!
index cd1ff04..52e4a69 100644 (file)
@@ -86,26 +86,26 @@ static void print_header(void)
  */
 static bool make_fake_artifact(ObjectType *o_ptr, FixedArtifactId fixed_artifact_idx)
 {
-    auto *a_ptr = &a_info[enum2i(fixed_artifact_idx)];
-    if (a_ptr->name.empty()) {
+    auto &a_ref = a_info.at(fixed_artifact_idx);
+    if (a_ref.name.empty()) {
         return false;
     }
 
-    OBJECT_IDX i = lookup_kind(a_ptr->tval, a_ptr->sval);
+    OBJECT_IDX i = lookup_kind(a_ref.tval, a_ref.sval);
     if (!i) {
         return false;
     }
 
     o_ptr->prep(i);
     o_ptr->fixed_artifact_idx = fixed_artifact_idx;
-    o_ptr->pval = a_ptr->pval;
-    o_ptr->ac = a_ptr->ac;
-    o_ptr->dd = a_ptr->dd;
-    o_ptr->ds = a_ptr->ds;
-    o_ptr->to_a = a_ptr->to_a;
-    o_ptr->to_h = a_ptr->to_h;
-    o_ptr->to_d = a_ptr->to_d;
-    o_ptr->weight = a_ptr->weight;
+    o_ptr->pval = a_ref.pval;
+    o_ptr->ac = a_ref.ac;
+    o_ptr->dd = a_ref.dd;
+    o_ptr->ds = a_ref.ds;
+    o_ptr->to_a = a_ref.to_a;
+    o_ptr->to_h = a_ref.to_h;
+    o_ptr->to_d = a_ref.to_d;
+    o_ptr->weight = a_ref.weight;
     return true;
 }
 
@@ -164,14 +164,14 @@ SpoilerOutputResultType spoil_fixed_artifact(concptr fname)
         spoiler_blanklines(1);
 
         for (auto tval : tval_list) {
-            for (const auto &a_ref : a_info) {
+            for (const auto &[a_idx, a_ref] : a_info) {
                 if (a_ref.tval != tval) {
                     continue;
                 }
 
                 ObjectType obj;
                 obj.wipe();
-                if (!make_fake_artifact(&obj, a_ref.idx)) {
+                if (!make_fake_artifact(&obj, a_idx)) {
                     continue;
                 }
 
index 8657935..917878d 100644 (file)
@@ -194,8 +194,8 @@ void wiz_restore_aware_flag_of_fixed_arfifact(FixedArtifactId a_idx, bool aware)
         return;
     }
 
-    auto *a_ptr = &a_info[int_a_idx];
-    a_ptr->is_generated = aware;
+    auto reset_artifact_idx = i2enum<FixedArtifactId>(int_a_idx);
+    a_info.at(reset_artifact_idx).is_generated = aware;
     msg_print(aware ? "Modified." : "Restored.");
 }
 
@@ -416,9 +416,8 @@ static void wiz_statistics(PlayerType *player_ptr, ObjectType *o_ptr)
     concptr p = "Enter number of items to roll: ";
     char tmp_val[80];
 
-    const auto o_fixed_artifact_idx = enum2i(o_ptr->fixed_artifact_idx);
     if (o_ptr->is_fixed_artifact()) {
-        a_info[o_fixed_artifact_idx].is_generated = false;
+        a_info.at(o_ptr->fixed_artifact_idx).is_generated = false;
     }
 
     uint32_t i, matches, better, worse, other, correct;
@@ -471,9 +470,8 @@ static void wiz_statistics(PlayerType *player_ptr, ObjectType *o_ptr)
             auto *q_ptr = &forge;
             q_ptr->wipe();
             make_object(player_ptr, q_ptr, mode);
-            const auto q_fixed_artifact_idx = enum2i(q_ptr->fixed_artifact_idx);
             if (q_ptr->is_fixed_artifact()) {
-                a_info[q_fixed_artifact_idx].is_generated = false;
+                a_info.at(q_ptr->fixed_artifact_idx).is_generated = false;
             }
 
             if ((o_ptr->tval != q_ptr->tval) || (o_ptr->sval != q_ptr->sval)) {
@@ -481,7 +479,8 @@ static void wiz_statistics(PlayerType *player_ptr, ObjectType *o_ptr)
             }
 
             correct++;
-            if ((q_ptr->pval == o_ptr->pval) && (q_ptr->to_a == o_ptr->to_a) && (q_ptr->to_h == o_ptr->to_h) && (q_ptr->to_d == o_ptr->to_d) && (q_fixed_artifact_idx == o_fixed_artifact_idx)) {
+            const auto is_same_fixed_artifact_idx = q_ptr->fixed_artifact_idx == o_ptr->fixed_artifact_idx;
+            if ((q_ptr->pval == o_ptr->pval) && (q_ptr->to_a == o_ptr->to_a) && (q_ptr->to_h == o_ptr->to_h) && (q_ptr->to_d == o_ptr->to_d) && is_same_fixed_artifact_idx) {
                 matches++;
             } else if ((q_ptr->pval >= o_ptr->pval) && (q_ptr->to_a >= o_ptr->to_a) && (q_ptr->to_h >= o_ptr->to_h) && (q_ptr->to_d >= o_ptr->to_d)) {
                 better++;
@@ -497,7 +496,7 @@ static void wiz_statistics(PlayerType *player_ptr, ObjectType *o_ptr)
     }
 
     if (o_ptr->is_fixed_artifact()) {
-        a_info[o_fixed_artifact_idx].is_generated = true;
+        a_info.at(o_ptr->fixed_artifact_idx).is_generated = true;
     }
 }
 
@@ -521,10 +520,9 @@ static void wiz_reroll_item(PlayerType *player_ptr, ObjectType *o_ptr)
     bool changed = false;
     while (true) {
         wiz_display_item(player_ptr, q_ptr);
-        const auto int_fixed_artifact_idx = enum2i(q_ptr->fixed_artifact_idx);
         if (!get_com("[a]ccept, [w]orthless, [c]ursed, [n]ormal, [g]ood, [e]xcellent, [s]pecial? ", &ch, false)) {
             if (q_ptr->is_fixed_artifact()) {
-                a_info[int_fixed_artifact_idx].is_generated = false;
+                a_info.at(q_ptr->fixed_artifact_idx).is_generated = false;
                 q_ptr->fixed_artifact_idx = FixedArtifactId::NONE;
             }
 
@@ -538,7 +536,7 @@ static void wiz_reroll_item(PlayerType *player_ptr, ObjectType *o_ptr)
         }
 
         if (q_ptr->is_fixed_artifact()) {
-            a_info[int_fixed_artifact_idx].is_generated = false;
+            a_info.at(q_ptr->fixed_artifact_idx).is_generated = false;
             q_ptr->fixed_artifact_idx = FixedArtifactId::NONE;
         }
 
@@ -952,8 +950,8 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
 
         int len;
         int mlen = 0;
-        for (const auto &a_ref : a_info) {
-            if (a_ref.idx == FixedArtifactId::NONE || a_ref.name.empty()) {
+        for (const auto &[a_idx, a_ref] : a_info) {
+            if (a_idx == FixedArtifactId::NONE || a_ref.name.empty()) {
                 continue;
             }
 
@@ -963,7 +961,7 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
             }
 
             o_ptr->prep(k_idx);
-            o_ptr->fixed_artifact_idx = a_ref.idx;
+            o_ptr->fixed_artifact_idx = a_idx;
 
             describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
 #ifndef JP
@@ -1005,7 +1003,7 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
 #endif
 
             if (cheat_xtra) {
-                msg_format("Matching artifact No.%d %s(%s)", a_ref.idx, a_desc, _(&o_name[2], o_name));
+                msg_format("Matching artifact No.%d %s(%s)", a_idx, a_desc, _(&o_name[2], o_name));
             }
 
             std::vector<const char *> l = { a_str, a_ref.name.c_str(), _(&o_name[2], o_name) };
@@ -1013,7 +1011,7 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
                 if (!strcmp(str, l.at(c))) {
                     len = strlen(l.at(c));
                     if (len > mlen) {
-                        a_ids.push_back(a_ref.idx);
+                        a_ids.push_back(a_idx);
                         mlen = len;
                     }
                 }
@@ -1028,11 +1026,11 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
 
     if (a_ids.size() == 1) {
         const auto a_idx = a_ids.back();
-        const auto int_a_idx = enum2i(a_idx);
-        if (must || (ok_art && !a_info[int_a_idx].is_generated)) {
+        auto &a_ref = a_info.at(a_idx);
+        if (must || (ok_art && !a_ref.is_generated)) {
             create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
             if (!w_ptr->wizard) {
-                a_info[int_a_idx].is_generated = true;
+                a_ref.is_generated = true;
             }
         } else {
             wishing_puff_of_smoke();
@@ -1050,25 +1048,23 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
         KIND_OBJECT_IDX k_idx = k_ids.back();
         auto *k_ptr = &k_info[k_idx];
 
-        ArtifactType *a_ptr;
         FixedArtifactId a_idx = FixedArtifactId::NONE;
         if (k_ptr->gen_flags.has(ItemGenerationTraitType::INSTA_ART)) {
-            for (const auto &a_ref : a_info) {
-                if (a_ref.idx == FixedArtifactId::NONE || a_ref.tval != k_ptr->tval || a_ref.sval != k_ptr->sval) {
+            for (const auto &[a_idx_loop, a_ref_loop] : a_info) {
+                if (a_idx_loop == FixedArtifactId::NONE || a_ref_loop.tval != k_ptr->tval || a_ref_loop.sval != k_ptr->sval) {
                     continue;
                 }
-                a_idx = a_ref.idx;
+                a_idx = a_idx_loop;
                 break;
             }
         }
 
         if (a_idx != FixedArtifactId::NONE) {
-            const auto int_a_idx = enum2i(a_idx);
-            a_ptr = &a_info[int_a_idx];
-            if (must || (ok_art && !a_ptr->is_generated)) {
+            auto &a_ref = a_info.at(a_idx);
+            if (must || (ok_art && !a_ref.is_generated)) {
                 create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
                 if (!w_ptr->wizard) {
-                    a_info[int_a_idx].is_generated = true;
+                    a_ref.is_generated = true;
                 }
             } else {
                 wishing_puff_of_smoke();
index a8cba1d..f88f3b6 100644 (file)
@@ -236,12 +236,12 @@ void wiz_create_item(PlayerType *player_ptr)
     }
 
     if (k_info[k_idx].gen_flags.has(ItemGenerationTraitType::INSTA_ART)) {
-        for (const auto &a_ref : a_info) {
-            if ((a_ref.idx == FixedArtifactId::NONE) || (a_ref.tval != k_info[k_idx].tval) || (a_ref.sval != k_info[k_idx].sval)) {
+        for (const auto &[a_idx, a_ref] : a_info) {
+            if ((a_idx == FixedArtifactId::NONE) || (a_ref.tval != k_info[k_idx].tval) || (a_ref.sval != k_info[k_idx].sval)) {
                 continue;
             }
 
-            (void)create_named_art(player_ptr, a_ref.idx, player_ptr->y, player_ptr->x);
+            (void)create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
             msg_print("Allocated(INSTA_ART).");
             return;
         }
@@ -264,7 +264,7 @@ void wiz_create_item(PlayerType *player_ptr)
  */
 static std::string wiz_make_named_artifact_desc(PlayerType *player_ptr, FixedArtifactId a_idx)
 {
-    const auto &a_ref = a_info[enum2i(a_idx)];
+    const auto &a_ref = a_info.at(a_idx);
     ObjectType obj;
     obj.prep(lookup_kind(a_ref.tval, a_ref.sval));
     obj.fixed_artifact_idx = a_idx;
@@ -343,9 +343,9 @@ static std::vector<FixedArtifactId> wiz_collect_group_a_idx(const grouper &group
     const auto &[tval_list, name] = group_artifact;
     std::vector<FixedArtifactId> a_idx_list;
     for (auto tval : tval_list) {
-        for (const auto &a_ref : a_info) {
+        for (const auto &[a_idx, a_ref] : a_info) {
             if (a_ref.tval == tval) {
-                a_idx_list.push_back(a_ref.idx);
+                a_idx_list.push_back(a_idx);
             }
         }
     }