OSDN Git Service

[Refactor] #2628 ObjectType をItemEntity に変更した
[hengbandforosx/hengbandosx.git] / src / wizard / wizard-item-modifier.cpp
index f4f917a..092f8e1 100644 (file)
@@ -1,5 +1,6 @@
 #include "wizard/wizard-item-modifier.h"
 #include "artifact/fixed-art-generator.h"
+#include "artifact/fixed-art-types.h"
 #include "artifact/random-art-effects.h"
 #include "artifact/random-art-generator.h"
 #include "core/asking-player.h"
 #include "object/object-flags.h"
 #include "object/object-info.h"
 #include "object/object-kind-hook.h"
-#include "object/object-kind.h"
 #include "object/object-mark-types.h"
 #include "object/object-value.h"
 #include "spell-kind/spells-perception.h"
 #include "spell/spells-object.h"
 #include "system/alloc-entries.h"
 #include "system/artifact-type-definition.h"
+#include "system/baseitem-info-definition.h"
 #include "system/floor-type-definition.h"
 #include "system/object-type-definition.h"
 #include "system/player-type-definition.h"
@@ -48,7 +49,7 @@
 #include <tuple>
 #include <vector>
 
-#define K_MAX_DEPTH 110 /*!< アイテムの階層毎生成率を表示する最大階 */
+constexpr auto BASEITEM_MAX_DEPTH = 110; /*!< アイテムの階層毎生成率を表示する最大階 */
 
 namespace {
 /*!
@@ -82,7 +83,7 @@ void display_wizard_sub_menu()
     for (const auto &[symbol, desc] : wizard_sub_menu_table) {
         std::stringstream ss;
         ss << symbol << ") " << desc;
-        put_str(ss.str().c_str(), r++, c);
+        put_str(ss.str().data(), r++, c);
     }
 }
 }
@@ -98,7 +99,7 @@ T clamp_cast(int val)
         static_cast<int>(std::numeric_limits<T>::max())));
 }
 
-void wiz_restore_aware_flag_of_fixed_arfifact(ARTIFACT_IDX a_idx, bool aware = false);
+void wiz_restore_aware_flag_of_fixed_arfifact(FixedArtifactId reset_artifact_idx, bool aware = false);
 void wiz_modify_item_activation(PlayerType *player_ptr);
 void wiz_identify_full_inventory(PlayerType *player_ptr);
 
@@ -122,10 +123,10 @@ void wizard_item_modifier(PlayerType *player_ptr)
     case '\r':
         break;
     case 'a':
-        wiz_restore_aware_flag_of_fixed_arfifact(command_arg);
+        wiz_restore_aware_flag_of_fixed_arfifact(i2enum<FixedArtifactId>(command_arg));
         break;
     case 'A':
-        wiz_restore_aware_flag_of_fixed_arfifact(command_arg, true);
+        wiz_restore_aware_flag_of_fixed_arfifact(i2enum<FixedArtifactId>(command_arg), true);
         break;
     case 'e':
         if (command_arg <= 0) {
@@ -172,27 +173,19 @@ void wizard_item_modifier(PlayerType *player_ptr)
 /*!
  * @brief 固定アーティファクトの出現フラグをリセットする
  * @param a_idx 指定したアーティファクトID
+ * @details 外からはenum class を受け取るが、この関数内では数値の直指定処理なので数値型にキャストする.
  */
-void wiz_restore_aware_flag_of_fixed_arfifact(ARTIFACT_IDX a_idx, bool aware)
+void wiz_restore_aware_flag_of_fixed_arfifact(FixedArtifactId reset_artifact_idx, bool aware)
 {
-    if (a_idx <= 0) {
-        char tmp[80] = "";
-        sprintf(tmp, "Artifact ID (1-%d): ", static_cast<int>(a_info.size()) - 1);
-        char tmp_val[10] = "";
-        if (!get_string(tmp, tmp_val, 3)) {
+    auto max_a_idx = enum2i(artifacts_info.rbegin()->first);
+    int int_a_idx = enum2i(reset_artifact_idx);
+    if (int_a_idx <= 0) {
+        if (!get_value("Artifact ID", 1, max_a_idx, &int_a_idx)) {
             return;
         }
-
-        a_idx = (ARTIFACT_IDX)atoi(tmp_val);
-    }
-
-    if (a_idx <= 0 || a_idx >= static_cast<ARTIFACT_IDX>(a_info.size())) {
-        msg_format(_("番号は1から%dの間で指定して下さい。", "ID must be between 1 to %d."), a_info.size() - 1);
-        return;
     }
 
-    auto *a_ptr = &a_info[a_idx];
-    a_ptr->cur_num = aware ? 1 : 0;
+    artifacts_info.at(i2enum<FixedArtifactId>(int_a_idx)).is_generated = aware;
     msg_print(aware ? "Modified." : "Restored.");
 }
 
@@ -232,7 +225,7 @@ void wiz_identify_full_inventory(PlayerType *player_ptr)
             continue;
         }
 
-        auto k_ptr = &k_info[o_ptr->k_idx];
+        auto k_ptr = &baseitems_info[o_ptr->k_idx];
         k_ptr->aware = true; //!< @note 記録には残さないためTRUEを立てるのみ
         set_bits(o_ptr->ident, IDENT_KNOWN | IDENT_FULL_KNOWN);
         set_bits(o_ptr->marked, OM_TOUCHED);
@@ -254,50 +247,49 @@ void wiz_identify_full_inventory(PlayerType *player_ptr)
  */
 static void prt_alloc(ItemKindType tval, OBJECT_SUBTYPE_VALUE sval, TERM_LEN row, TERM_LEN col)
 {
-    uint32_t rarity[K_MAX_DEPTH] = {};
-    uint32_t total[K_MAX_DEPTH] = {};
-    int32_t display[22] = {};
-
-    int home = 0;
-    for (int i = 0; i < K_MAX_DEPTH; i++) {
-        int total_frac = 0;
-        object_kind *k_ptr;
+    uint32_t rarity[BASEITEM_MAX_DEPTH]{};
+    uint32_t total[BASEITEM_MAX_DEPTH]{};
+    int32_t display[22]{};
+
+    auto home = 0;
+    for (auto i = 0; i < BASEITEM_MAX_DEPTH; i++) {
+        auto total_frac = 0;
+        constexpr auto magnificant = CHANCE_BASEITEM_LEVEL_BOOST * BASEITEM_MAX_DEPTH;
         for (const auto &entry : alloc_kind_table) {
-            PERCENTAGE prob = 0;
-
+            auto prob = 0;
             if (entry.level <= i) {
-                prob = entry.prob1 * GREAT_OBJ * K_MAX_DEPTH;
+                prob = entry.prob1 * magnificant;
             } else if (entry.level - 1 > 0) {
-                prob = entry.prob1 * i * K_MAX_DEPTH / (entry.level - 1);
+                prob = entry.prob1 * i * BASEITEM_MAX_DEPTH / (entry.level - 1);
             }
 
-            k_ptr = &k_info[entry.index];
-
-            total[i] += prob / (GREAT_OBJ * K_MAX_DEPTH);
-            total_frac += prob % (GREAT_OBJ * K_MAX_DEPTH);
+            const auto &bi_ref = baseitems_info[entry.index];
+            total[i] += prob / magnificant;
+            total_frac += prob % magnificant;
 
-            if ((k_ptr->tval == tval) && (k_ptr->sval == sval)) {
-                home = k_ptr->level;
-                rarity[i] += prob / (GREAT_OBJ * K_MAX_DEPTH);
+            BaseitemKey bi_key(tval, sval);
+            if (bi_ref.bi_key == bi_key) {
+                home = bi_ref.level;
+                rarity[i] += prob / magnificant;
             }
         }
 
-        total[i] += total_frac / (GREAT_OBJ * K_MAX_DEPTH);
+        total[i] += total_frac / magnificant;
     }
 
-    for (int i = 0; i < 22; i++) {
-        int possibility = 0;
-        for (int j = i * K_MAX_DEPTH / 22; j < (i + 1) * K_MAX_DEPTH / 22; j++) {
+    for (auto i = 0; i < 22; i++) {
+        auto possibility = 0;
+        for (int j = i * BASEITEM_MAX_DEPTH / 22; j < (i + 1) * BASEITEM_MAX_DEPTH / 22; j++) {
             possibility += rarity[j] * 100000 / total[j];
         }
 
         display[i] = possibility / 5;
     }
 
-    for (int i = 0; i < 22; i++) {
+    for (auto i = 0; i < 22; i++) {
         term_putch(col, row + i + 1, TERM_WHITE, '|');
         prt(format("%2dF", (i * 5)), row + i + 1, col);
-        if ((i * K_MAX_DEPTH / 22 <= home) && (home < (i + 1) * K_MAX_DEPTH / 22)) {
+        if ((i * BASEITEM_MAX_DEPTH / 22 <= home) && (home < (i + 1) * BASEITEM_MAX_DEPTH / 22)) {
             c_prt(TERM_RED, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
         } else {
             c_prt(TERM_WHITE, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
@@ -329,7 +321,7 @@ static void prt_binary(BIT_FLAGS flags, const int row, int col)
  * @param player_ptr プレイヤーへの参照ポインタ
  * @param o_ptr 詳細を表示するアイテム情報の参照ポインタ
  */
-static void wiz_display_item(PlayerType *player_ptr, ObjectType *o_ptr)
+static void wiz_display_item(PlayerType *player_ptr, ItemEntity *o_ptr)
 {
     auto flgs = object_flags(o_ptr);
     auto get_seq_32bits = [](const TrFlags &flgs, uint start) {
@@ -352,7 +344,7 @@ static void wiz_display_item(PlayerType *player_ptr, ObjectType *o_ptr)
     prt(buf, 2, j);
 
     auto line = 4;
-    prt(format("kind = %-5d  level = %-4d  tval = %-5d  sval = %-5d", o_ptr->k_idx, k_info[o_ptr->k_idx].level, o_ptr->tval, o_ptr->sval), line, j);
+    prt(format("kind = %-5d  level = %-4d  tval = %-5d  sval = %-5d", o_ptr->k_idx, baseitems_info[o_ptr->k_idx].level, o_ptr->tval, o_ptr->sval), line, j);
     prt(format("number = %-3d  wgt = %-6d  ac = %-5d    damage = %dd%d", o_ptr->number, o_ptr->weight, o_ptr->ac, o_ptr->dd, o_ptr->ds), ++line, j);
     prt(format("pval = %-5d  toac = %-5d  tohit = %-4d  todam = %-4d", o_ptr->pval, o_ptr->to_a, o_ptr->to_h, o_ptr->to_d), ++line, j);
     prt(format("fixed_artifact_idx = %-4d  ego_idx = %-4d  cost = %ld", o_ptr->fixed_artifact_idx, o_ptr->ego_idx, object_value_real(o_ptr)), ++line, j);
@@ -378,7 +370,7 @@ static void wiz_display_item(PlayerType *player_ptr, ObjectType *o_ptr)
     prt("rtsxnaeydcedwlatdcedsrekdfddrxss", ++line, j);
     prt_binary(get_seq_32bits(flgs, 32 * 1), ++line, j);
 
-    line = 10;
+    line = 13;
     prt("+------------FLAGS3------------+", line, j + 32);
     prt("fe cnn t      stdrmsiiii d ab   ", ++line, j + 32);
     prt("aa aoomywhs lleeieihgggg rtgl   ", ++line, j + 32);
@@ -407,14 +399,14 @@ static void wiz_display_item(PlayerType *player_ptr, ObjectType *o_ptr)
  * counter flags to prevent weirdness.  We use the items to collect
  * statistics on item creation relative to the initial item.
  */
-static void wiz_statistics(PlayerType *player_ptr, ObjectType *o_ptr)
+static void wiz_statistics(PlayerType *player_ptr, ItemEntity *o_ptr)
 {
     concptr q = "Rolls: %ld  Correct: %ld  Matches: %ld  Better: %ld  Worse: %ld  Other: %ld";
     concptr p = "Enter number of items to roll: ";
     char tmp_val[80];
 
     if (o_ptr->is_fixed_artifact()) {
-        a_info[o_ptr->fixed_artifact_idx].cur_num = 0;
+        artifacts_info.at(o_ptr->fixed_artifact_idx).is_generated = false;
     }
 
     uint32_t i, matches, better, worse, other, correct;
@@ -463,12 +455,12 @@ static void wiz_statistics(PlayerType *player_ptr, ObjectType *o_ptr)
                 term_fresh();
             }
 
-            ObjectType forge;
+            ItemEntity forge;
             auto *q_ptr = &forge;
             q_ptr->wipe();
             make_object(player_ptr, q_ptr, mode);
             if (q_ptr->is_fixed_artifact()) {
-                a_info[q_ptr->fixed_artifact_idx].cur_num = 0;
+                artifacts_info.at(q_ptr->fixed_artifact_idx).is_generated = false;
             }
 
             if ((o_ptr->tval != q_ptr->tval) || (o_ptr->sval != q_ptr->sval)) {
@@ -476,7 +468,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_ptr->fixed_artifact_idx == o_ptr->fixed_artifact_idx)) {
+            const auto is_same_fixed_artifact_idx = o_ptr->is_specific_artifact(q_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++;
@@ -492,7 +485,7 @@ static void wiz_statistics(PlayerType *player_ptr, ObjectType *o_ptr)
     }
 
     if (o_ptr->is_fixed_artifact()) {
-        a_info[o_ptr->fixed_artifact_idx].cur_num = 1;
+        artifacts_info.at(o_ptr->fixed_artifact_idx).is_generated = true;
     }
 }
 
@@ -501,14 +494,14 @@ static void wiz_statistics(PlayerType *player_ptr, ObjectType *o_ptr)
  * Apply magic to an item or turn it into an artifact. -Bernd-
  * @param o_ptr 再生成の対象となるアイテム情報の参照ポインタ
  */
-static void wiz_reroll_item(PlayerType *player_ptr, ObjectType *o_ptr)
+static void wiz_reroll_item(PlayerType *player_ptr, ItemEntity *o_ptr)
 {
     if (o_ptr->is_artifact()) {
         return;
     }
 
-    ObjectType forge;
-    ObjectType *q_ptr;
+    ItemEntity forge;
+    ItemEntity *q_ptr;
     q_ptr = &forge;
     q_ptr->copy_from(o_ptr);
 
@@ -518,8 +511,8 @@ static void wiz_reroll_item(PlayerType *player_ptr, ObjectType *o_ptr)
         wiz_display_item(player_ptr, q_ptr);
         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[q_ptr->fixed_artifact_idx].cur_num = 0;
-                q_ptr->fixed_artifact_idx = 0;
+                artifacts_info.at(q_ptr->fixed_artifact_idx).is_generated = false;
+                q_ptr->fixed_artifact_idx = FixedArtifactId::NONE;
             }
 
             changed = false;
@@ -532,8 +525,8 @@ static void wiz_reroll_item(PlayerType *player_ptr, ObjectType *o_ptr)
         }
 
         if (q_ptr->is_fixed_artifact()) {
-            a_info[q_ptr->fixed_artifact_idx].cur_num = 0;
-            q_ptr->fixed_artifact_idx = 0;
+            artifacts_info.at(q_ptr->fixed_artifact_idx).is_generated = false;
+            q_ptr->fixed_artifact_idx = FixedArtifactId::NONE;
         }
 
         switch (tolower(ch)) {
@@ -594,7 +587,7 @@ static void wiz_reroll_item(PlayerType *player_ptr, ObjectType *o_ptr)
  * @param player_ptr プレイヤーへの参照ポインタ
  * @param o_ptr 調整するアイテムの参照ポインタ
  */
-static void wiz_tweak_item(PlayerType *player_ptr, ObjectType *o_ptr)
+static void wiz_tweak_item(PlayerType *player_ptr, ItemEntity *o_ptr)
 {
     if (o_ptr->is_artifact()) {
         return;
@@ -641,7 +634,7 @@ static void wiz_tweak_item(PlayerType *player_ptr, ObjectType *o_ptr)
  * @param player_ptr プレイヤーへの参照ポインタ
  * @param o_ptr 変更するアイテム情報構造体の参照ポインタ
  */
-static void wiz_quantity_item(ObjectType *o_ptr)
+static void wiz_quantity_item(ItemEntity *o_ptr)
 {
     if (o_ptr->is_artifact()) {
         return;
@@ -682,7 +675,7 @@ void wiz_modify_item(PlayerType *player_ptr)
     concptr q = "Play with which object? ";
     concptr s = "You have nothing to play with.";
     OBJECT_IDX item;
-    ObjectType *o_ptr;
+    ItemEntity *o_ptr;
     o_ptr = choose_object(player_ptr, &item, q, s, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT);
     if (!o_ptr) {
         return;
@@ -690,8 +683,8 @@ void wiz_modify_item(PlayerType *player_ptr)
 
     screen_save();
 
-    ObjectType forge;
-    ObjectType *q_ptr;
+    ItemEntity forge;
+    ItemEntity *q_ptr;
     q_ptr = &forge;
     q_ptr->copy_from(o_ptr);
     char ch;
@@ -740,7 +733,7 @@ void wiz_modify_item(PlayerType *player_ptr)
 /*!
  * @brief オブジェクトの装備スロットがエゴが有効なスロットかどうか判定
  */
-static int is_slot_able_to_be_ego(PlayerType *player_ptr, ObjectType *o_ptr)
+static int is_slot_able_to_be_ego(PlayerType *player_ptr, ItemEntity *o_ptr)
 {
     int slot = wield_slot(player_ptr, o_ptr);
 
@@ -794,7 +787,7 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
 
     char buf[MAX_NLEN] = "\0";
     char *str = buf;
-    ObjectType forge;
+    ItemEntity forge;
     auto *o_ptr = &forge;
     char o_name[MAX_NLEN];
 
@@ -886,7 +879,7 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
     if (exam_base) {
         int len;
         int max_len = 0;
-        for (const auto &k_ref : k_info) {
+        for (const auto &k_ref : baseitems_info) {
             if (k_ref.idx == 0 || k_ref.name.empty()) {
                 continue;
             }
@@ -914,12 +907,12 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
             KIND_OBJECT_IDX k_idx = k_ids.back();
             o_ptr->prep(k_idx);
 
-            for (const auto &[e_idx, e_ref] : e_info) {
+            for (const auto &[e_idx, e_ref] : egos_info) {
                 if (e_ref.idx == EgoType::NONE || e_ref.name.empty()) {
                     continue;
                 }
 
-                strcpy(o_name, e_ref.name.c_str());
+                strcpy(o_name, e_ref.name.data());
 #ifndef JP
                 str_tolower(o_name);
 #endif
@@ -938,7 +931,7 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
         }
     }
 
-    std::vector<ARTIFACT_IDX> a_ids;
+    std::vector<FixedArtifactId> a_ids;
 
     if (allow_art) {
         char a_desc[MAX_NLEN] = "\0";
@@ -946,25 +939,25 @@ 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 == 0 || a_ref.name.empty()) {
+        for (const auto &[a_idx, a_ref] : artifacts_info) {
+            if (a_idx == FixedArtifactId::NONE || a_ref.name.empty()) {
                 continue;
             }
 
-            KIND_OBJECT_IDX k_idx = lookup_kind(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->fixed_artifact_idx = a_ref.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));
 #ifndef JP
             str_tolower(o_name);
 #endif
             a_str = a_desc;
-            strcpy(a_desc, a_ref.name.c_str());
+            strcpy(a_desc, a_ref.name.data());
 
             if (*a_str == '$') {
                 a_str++;
@@ -999,15 +992,15 @@ 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) };
+            std::vector<const char *> l = { a_str, a_ref.name.data(), _(&o_name[2], o_name) };
             for (size_t c = 0; c < l.size(); c++) {
                 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;
                     }
                 }
@@ -1021,12 +1014,10 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
     }
 
     if (a_ids.size() == 1) {
-        ARTIFACT_IDX a_idx = a_ids.back();
-        if (must || (ok_art && !a_info[a_idx].cur_num)) {
-            create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
-            if (!w_ptr->wizard) {
-                a_info[a_idx].cur_num = 1;
-            }
+        const auto a_idx = a_ids.back();
+        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 {
             wishing_puff_of_smoke();
         }
@@ -1040,28 +1031,24 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
     }
 
     if (k_ids.size() == 1) {
-        KIND_OBJECT_IDX k_idx = k_ids.back();
-        auto *k_ptr = &k_info[k_idx];
-
-        artifact_type *a_ptr;
-        ARTIFACT_IDX a_idx = 0;
-        if (k_ptr->gen_flags.has(ItemGenerationTraitType::INSTA_ART)) {
-            for (const auto &a_ref : a_info) {
-                if (a_ref.idx == 0 || a_ref.tval != k_ptr->tval || a_ref.sval != k_ptr->sval) {
+        const auto k_idx = k_ids.back();
+        const auto &k_ref = baseitems_info[k_idx];
+        auto a_idx = FixedArtifactId::NONE;
+        if (k_ref.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.bi_key != k_ref.bi_key) {
                     continue;
                 }
-                a_idx = a_ref.idx;
+
+                a_idx = a_idx_loop;
                 break;
             }
         }
 
-        if (a_idx > 0) {
-            a_ptr = &a_info[a_idx];
-            if (must || (ok_art && !a_ptr->cur_num)) {
-                create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
-                if (!w_ptr->wizard) {
-                    a_info[a_idx].cur_num = 1;
-                }
+        if (a_idx != FixedArtifactId::NONE) {
+            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 {
                 wishing_puff_of_smoke();
             }
@@ -1073,8 +1060,8 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
             if (must || ok_art) {
                 do {
                     o_ptr->prep(k_idx);
-                    ItemMagicApplier(player_ptr, o_ptr, k_ptr->level, AM_SPECIAL | AM_NO_FIXED_ART).execute();
-                } while (!o_ptr->art_name || o_ptr->fixed_artifact_idx || o_ptr->is_ego() || o_ptr->is_cursed());
+                    ItemMagicApplier(player_ptr, o_ptr, k_ref.level, AM_SPECIAL | AM_NO_FIXED_ART).execute();
+                } while (!o_ptr->art_name || o_ptr->is_ego() || o_ptr->is_cursed());
 
                 if (o_ptr->art_name) {
                     drop_near(player_ptr, o_ptr, -1, player_ptr->y, player_ptr->x);
@@ -1097,9 +1084,8 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
                     int i = 0;
                     for (i = 0; i < max_roll; i++) {
                         o_ptr->prep(k_idx);
-                        ItemMagicApplier(player_ptr, o_ptr, k_ptr->level, AM_GREAT | AM_NO_FIXED_ART).execute();
-
-                        if (o_ptr->fixed_artifact_idx || o_ptr->art_name) {
+                        ItemMagicApplier(player_ptr, o_ptr, k_ref.level, AM_GREAT | AM_NO_FIXED_ART).execute();
+                        if (o_ptr->art_name) {
                             continue;
                         }