OSDN Git Service

[Refactor] #2628 ObjectType をItemEntity に変更した
[hengbandforosx/hengbandosx.git] / src / wizard / wizard-item-modifier.cpp
index 08eaf40..092f8e1 100644 (file)
@@ -1,12 +1,13 @@
 #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 "core/show-file.h"
 #include "core/player-update-types.h"
-#include "core/window-redrawer.h"
+#include "core/show-file.h"
 #include "core/stuff-handler.h"
+#include "core/window-redrawer.h"
 #include "flavor/flavor-describer.h"
 #include "flavor/object-flavor-types.h"
 #include "floor/floor-object.h"
 #include "inventory/inventory-slot-types.h"
 #include "io/input-key-acceptor.h"
 #include "io/input-key-requester.h"
-#include "object-enchant/apply-magic.h"
 #include "object-enchant/item-apply-magic.h"
+#include "object-enchant/item-magic-applier.h"
 #include "object-enchant/object-ego.h"
 #include "object-enchant/special-object-flags.h"
 #include "object-enchant/tr-types.h"
 #include "object/item-use-flags.h"
 #include "object/object-flags.h"
 #include "object/object-info.h"
-#include "object/object-kind.h"
 #include "object/object-kind-hook.h"
 #include "object/object-mark-types.h"
 #include "object/object-value.h"
-#include "util/bit-flags-calculator.h"
-#include "util/string-processor.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"
 #include "system/system-variables.h"
 #include "term/screen-processor.h"
 #include "term/term-color-types.h"
-#include "view/display-messages.h"
 #include "util/bit-flags-calculator.h"
 #include "util/int-char-converter.h"
+#include "util/string-processor.h"
+#include "view/display-messages.h"
 #include "wizard/wizard-special-process.h"
 #include "world/world.h"
 #include <algorithm>
@@ -49,7 +49,7 @@
 #include <tuple>
 #include <vector>
 
-#define K_MAX_DEPTH 110 /*!< アイテムの階層毎生成率を表示する最大階 */
+constexpr auto BASEITEM_MAX_DEPTH = 110; /*!< アイテムの階層毎生成率を表示する最大階 */
 
 namespace {
 /*!
@@ -74,15 +74,16 @@ constexpr std::array wizard_sub_menu_table = {
  */
 void display_wizard_sub_menu()
 {
-    for (auto y = 1U; y <= wizard_sub_menu_table.size(); y++)
+    for (auto y = 1U; y <= wizard_sub_menu_table.size(); y++) {
         term_erase(14, y, 64);
+    }
 
     int r = 1;
     int c = 15;
     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,14 +99,14 @@ 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);
 
 /*!
   * @brief ゲーム設定コマンドの入力を受け付ける
   * @param player_ptr プレイヤーの情報へのポインタ
      */
+ * @brief ゲーム設定コマンドの入力を受け付ける
+ * @param player_ptr プレイヤーの情報へのポインタ
+ */
 void wizard_item_modifier(PlayerType *player_ptr)
 {
     screen_save();
@@ -122,14 +123,15 @@ 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)
+        if (command_arg <= 0) {
             command_arg = 1;
+        }
 
         acquirement(player_ptr, player_ptr->y, player_ptr->x, command_arg, true, false, true);
         break;
@@ -137,8 +139,9 @@ void wizard_item_modifier(PlayerType *player_ptr)
         identify_fully(player_ptr, false);
         break;
     case 'g':
-        if (command_arg <= 0)
+        if (command_arg <= 0) {
             command_arg = 1;
+        }
 
         acquirement(player_ptr, player_ptr->y, player_ptr->x, command_arg, false, false, true);
         break;
@@ -152,8 +155,9 @@ void wizard_item_modifier(PlayerType *player_ptr)
         wiz_learn_items_all(player_ptr);
         break;
     case 's':
-        if (command_arg <= 0)
+        if (command_arg <= 0) {
             command_arg = 1;
+        }
 
         acquirement(player_ptr, player_ptr->y, player_ptr->x, command_arg, true, true, true);
         break;
@@ -169,26 +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.");
 }
 
@@ -224,10 +221,11 @@ void wiz_identify_full_inventory(PlayerType *player_ptr)
 {
     for (int i = 0; i < INVEN_TOTAL; i++) {
         auto *o_ptr = &player_ptr->inventory_list[i];
-        if (!o_ptr->k_idx)
+        if (!o_ptr->k_idx) {
             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);
@@ -249,52 +247,53 @@ 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
+        } else {
             c_prt(TERM_WHITE, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
+        }
     }
 
     concptr r = "+---Rate---+";
@@ -307,11 +306,13 @@ static void prt_alloc(ItemKindType tval, OBJECT_SUBTYPE_VALUE sval, TERM_LEN row
 static void prt_binary(BIT_FLAGS flags, const int row, int col)
 {
     uint32_t bitmask;
-    for (int i = bitmask = 1; i <= 32; i++, bitmask *= 2)
-        if (flags & bitmask)
+    for (int i = bitmask = 1; i <= 32; i++, bitmask *= 2) {
+        if (flags & bitmask) {
             term_putch(col++, row, TERM_BLUE, '*');
-        else
+        } else {
             term_putch(col++, row, TERM_WHITE, '-');
+        }
+    }
 }
 
 /*!
@@ -320,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) {
@@ -333,8 +334,9 @@ static void wiz_display_item(PlayerType *player_ptr, ObjectType *o_ptr)
         return result;
     };
     int j = 13;
-    for (int i = 1; i <= 23; i++)
+    for (int i = 1; i <= 23; i++) {
         prt("", i, j - 2);
+    }
 
     prt_alloc(o_ptr->tval, o_ptr->sval, 1, 0);
     char buf[256];
@@ -342,10 +344,10 @@ 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("name1 = %-4d  name2 = %-4d  cost = %ld", o_ptr->fixed_artifact_idx, o_ptr->ego_idx, (long)object_value_real(o_ptr)), ++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);
     prt(format("ident = %04x  activation_id = %-4d  timeout = %-d", o_ptr->ident, o_ptr->activation_id, o_ptr->timeout), ++line, j);
     prt(format("chest_level = %-4d  fuel = %-d", o_ptr->chest_level, o_ptr->fuel), ++line, j);
     prt(format("smith_hit = %-4d  smith_damage = %-4d", o_ptr->smith_hit, o_ptr->smith_damage), ++line, j);
@@ -368,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);
@@ -397,14 +399,15 @@ 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;
+    if (o_ptr->is_fixed_artifact()) {
+        artifacts_info.at(o_ptr->fixed_artifact_idx).is_generated = false;
+    }
 
     uint32_t i, matches, better, worse, other, correct;
     uint32_t test_roll = 1000000;
@@ -414,8 +417,9 @@ static void wiz_statistics(PlayerType *player_ptr, ObjectType *o_ptr)
     while (true) {
         concptr pmt = "Roll for [n]ormal, [g]ood, or [e]xcellent treasure? ";
         wiz_display_item(player_ptr, o_ptr);
-        if (!get_com(pmt, &ch, false))
+        if (!get_com(pmt, &ch, false)) {
             break;
+        }
 
         if (ch == 'n' || ch == 'N') {
             mode = 0L;
@@ -431,8 +435,9 @@ static void wiz_statistics(PlayerType *player_ptr, ObjectType *o_ptr)
         }
 
         sprintf(tmp_val, "%ld", (long int)test_roll);
-        if (get_string(p, tmp_val, 10))
+        if (get_string(p, tmp_val, 10)) {
             test_roll = atol(tmp_val);
+        }
         test_roll = std::max<uint>(1, test_roll);
         msg_format("Creating a lot of %s items. Base level = %d.", quality, player_ptr->current_floor_ptr->dun_level);
         msg_print(nullptr);
@@ -450,19 +455,21 @@ 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;
+            if (q_ptr->is_fixed_artifact()) {
+                artifacts_info.at(q_ptr->fixed_artifact_idx).is_generated = false;
+            }
 
-            if ((o_ptr->tval != q_ptr->tval) || (o_ptr->sval != q_ptr->sval))
+            if ((o_ptr->tval != q_ptr->tval) || (o_ptr->sval != q_ptr->sval)) {
                 continue;
+            }
 
             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++;
@@ -477,8 +484,9 @@ static void wiz_statistics(PlayerType *player_ptr, ObjectType *o_ptr)
         msg_print(nullptr);
     }
 
-    if (o_ptr->is_fixed_artifact())
-        a_info[o_ptr->fixed_artifact_idx].cur_num = 1;
+    if (o_ptr->is_fixed_artifact()) {
+        artifacts_info.at(o_ptr->fixed_artifact_idx).is_generated = true;
+    }
 }
 
 /*!
@@ -486,13 +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())
+    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);
 
@@ -502,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;
@@ -516,42 +525,43 @@ 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)) {
         /* Apply bad magic, but first clear object */
         case 'w':
             q_ptr->prep(o_ptr->k_idx);
-            apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT | AM_CURSED);
+            ItemMagicApplier(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT | AM_CURSED).execute();
             break;
         /* Apply bad magic, but first clear object */
         case 'c':
             q_ptr->prep(o_ptr->k_idx);
-            apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_CURSED);
+            ItemMagicApplier(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_CURSED).execute();
             break;
         /* Apply normal magic, but first clear object */
         case 'n':
             q_ptr->prep(o_ptr->k_idx);
-            apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART);
+            ItemMagicApplier(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART).execute();
             break;
         /* Apply good magic, but first clear object */
         case 'g':
             q_ptr->prep(o_ptr->k_idx);
-            apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD);
+            ItemMagicApplier(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD).execute();
             break;
         /* Apply great magic, but first clear object */
         case 'e':
             q_ptr->prep(o_ptr->k_idx);
-            apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT);
+            ItemMagicApplier(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT).execute();
             break;
         /* Apply special magic, but first clear object */
         case 's':
             q_ptr->prep(o_ptr->k_idx);
-            apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_GOOD | AM_GREAT | AM_SPECIAL);
-            if (!q_ptr->is_artifact())
+            ItemMagicApplier(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_GOOD | AM_GREAT | AM_SPECIAL).execute();
+            if (!q_ptr->is_artifact()) {
                 become_random_artifact(player_ptr, q_ptr, false);
+            }
 
             break;
         default:
@@ -563,8 +573,9 @@ static void wiz_reroll_item(PlayerType *player_ptr, ObjectType *o_ptr)
         q_ptr->marked = o_ptr->marked;
     }
 
-    if (!changed)
+    if (!changed) {
         return;
+    }
 
     o_ptr->copy_from(q_ptr);
     set_bits(player_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
@@ -576,37 +587,42 @@ 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())
+    if (o_ptr->is_artifact()) {
         return;
+    }
 
     concptr p = "Enter new 'pval' setting: ";
     char tmp_val[80];
     sprintf(tmp_val, "%d", o_ptr->pval);
-    if (!get_string(p, tmp_val, 5))
+    if (!get_string(p, tmp_val, 5)) {
         return;
+    }
 
     o_ptr->pval = clamp_cast<int16_t>(atoi(tmp_val));
     wiz_display_item(player_ptr, o_ptr);
     p = "Enter new 'to_a' setting: ";
     sprintf(tmp_val, "%d", o_ptr->to_a);
-    if (!get_string(p, tmp_val, 5))
+    if (!get_string(p, tmp_val, 5)) {
         return;
+    }
 
     o_ptr->to_a = clamp_cast<int16_t>(atoi(tmp_val));
     wiz_display_item(player_ptr, o_ptr);
     p = "Enter new 'to_h' setting: ";
     sprintf(tmp_val, "%d", o_ptr->to_h);
-    if (!get_string(p, tmp_val, 5))
+    if (!get_string(p, tmp_val, 5)) {
         return;
+    }
 
     o_ptr->to_h = clamp_cast<int16_t>(atoi(tmp_val));
     wiz_display_item(player_ptr, o_ptr);
     p = "Enter new 'to_d' setting: ";
     sprintf(tmp_val, "%d", (int)o_ptr->to_d);
-    if (!get_string(p, tmp_val, 5))
+    if (!get_string(p, tmp_val, 5)) {
         return;
+    }
 
     o_ptr->to_d = clamp_cast<int16_t>(atoi(tmp_val));
     wiz_display_item(player_ptr, o_ptr);
@@ -618,27 +634,31 @@ 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())
+    if (o_ptr->is_artifact()) {
         return;
+    }
 
     int tmp_qnt = o_ptr->number;
     char tmp_val[100];
     sprintf(tmp_val, "%d", (int)o_ptr->number);
     if (get_string("Quantity: ", tmp_val, 2)) {
         int tmp_int = atoi(tmp_val);
-        if (tmp_int < 1)
+        if (tmp_int < 1) {
             tmp_int = 1;
+        }
 
-        if (tmp_int > 99)
+        if (tmp_int > 99) {
             tmp_int = 99;
+        }
 
         o_ptr->number = (byte)tmp_int;
     }
 
-    if (o_ptr->tval == ItemKindType::ROD)
+    if (o_ptr->tval == ItemKindType::ROD) {
         o_ptr->pval = o_ptr->pval * o_ptr->number / tmp_qnt;
+    }
 }
 
 /*!
@@ -655,15 +675,16 @@ 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)
+    if (!o_ptr) {
         return;
+    }
 
     screen_save();
 
-    ObjectType forge;
-    ObjectType *q_ptr;
+    ItemEntity forge;
+    ItemEntity *q_ptr;
     q_ptr = &forge;
     q_ptr->copy_from(o_ptr);
     char ch;
@@ -712,21 +733,23 @@ 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);
 
-    if (slot > -1)
+    if (slot > -1) {
         return slot;
+    }
 
-    if ((o_ptr->tval == ItemKindType::SHOT) || (o_ptr->tval == ItemKindType::ARROW) || (o_ptr->tval == ItemKindType::BOLT))
+    if ((o_ptr->tval == ItemKindType::SHOT) || (o_ptr->tval == ItemKindType::ARROW) || (o_ptr->tval == ItemKindType::BOLT)) {
         return INVEN_AMMO;
+    }
 
     return -1;
 }
 
 /*!
- * @brief 願ったが消えてしまった場合のメッセージ 
+ * @brief 願ったが消えてしまった場合のメッセージ
  */
 static void wishing_puff_of_smoke(void)
 {
@@ -764,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];
 
@@ -779,11 +802,13 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
     bool fixed = true;
 
     while (1) {
-        if (get_string(_("何をお望み? ", "For what do you wish?"), buf, (MAX_NLEN - 1)))
+        if (get_string(_("何をお望み? ", "For what do you wish?"), buf, (MAX_NLEN - 1))) {
             break;
+        }
         if (confirm) {
-            if (!get_check(_("何も願いません。本当によろしいですか?", "Do you wish nothing, really? ")))
+            if (!get_check(_("何も願いません。本当によろしいですか?", "Do you wish nothing, really? "))) {
                 continue;
+            }
         }
         return WishResultType::NOTHING;
     }
@@ -792,10 +817,11 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
     str_tolower(str);
 
     /* remove 'a' */
-    if (!strncmp(buf, "a ", 2))
+    if (!strncmp(buf, "a ", 2)) {
         str = ltrim(str + 1);
-    else if (!strncmp(buf, "an ", 3))
+    } else if (!strncmp(buf, "an ", 3)) {
         str = ltrim(str + 2);
+    }
 #endif // !JP
 
     str = rtrim(str);
@@ -822,7 +848,7 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
     } else
 #endif
 
-    if (!strncmp(str, _("☆", "The "), _(2, 4))) {
+        if (!strncmp(str, _("☆", "The "), _(2, 4))) {
         str = ltrim(str + _(2, 4));
         wish_art = true;
         wish_randart = true;
@@ -844,25 +870,28 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
         return WishResultType::NOTHING;
     }
 
-    if (cheat_xtra)
+    if (cheat_xtra) {
         msg_format("Wishing %s....", buf);
+    }
 
     std::vector<KIND_OBJECT_IDX> k_ids;
     std::vector<EgoType> e_ids;
     if (exam_base) {
         int len;
         int max_len = 0;
-        for (const auto &k_ref : k_info) {
-            if (k_ref.idx == 0 || k_ref.name.empty())
+        for (const auto &k_ref : baseitems_info) {
+            if (k_ref.idx == 0 || k_ref.name.empty()) {
                 continue;
+            }
 
             o_ptr->prep(k_ref.idx);
             describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
 #ifndef JP
             str_tolower(o_name);
 #endif
-            if (cheat_xtra)
+            if (cheat_xtra) {
                 msg_format("Matching object No.%d %s", k_ref.idx, o_name);
+            }
 
             len = strlen(o_name);
 
@@ -878,20 +907,23 @@ 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) {
-                if (e_ref.idx == EgoType::NONE || e_ref.name.empty())
+            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
-                if (cheat_xtra)
+                if (cheat_xtra) {
                     msg_format("matching ego no.%d %s...", e_ref.idx, o_name);
+                }
 
                 if (_(!strncmp(str, o_name, strlen(o_name)), !strrncmp(str, o_name, strlen(o_name)))) {
-                    if (is_slot_able_to_be_ego(player_ptr, o_ptr) != e_ref.slot)
+                    if (is_slot_able_to_be_ego(player_ptr, o_ptr) != e_ref.slot) {
                         continue;
+                    }
 
                     e_ids.push_back(e_ref.idx);
                 }
@@ -899,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";
@@ -907,26 +939,29 @@ 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 == '$')
+            if (*a_str == '$') {
                 a_str++;
+            }
 #ifdef JP
             /* remove quotes */
             if (!strncmp(a_str, "『", 2)) {
@@ -956,15 +991,16 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
             str_tolower(a_str);
 #endif
 
-            if (cheat_xtra)
-                msg_format("Matching artifact No.%d %s(%s)", a_ref.idx, a_desc, _(&o_name[2], o_name));
+            if (cheat_xtra) {
+                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;
                     }
                 }
@@ -976,49 +1012,46 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
         msg_print(_("候補が多すぎる!", "Too many matches!"));
         return WishResultType::FAIL;
     }
-    
+
     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;
-        }
-        else
+        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();
+        }
 
         return WishResultType::ARTIFACT;
     }
-    
+
     if (!allow_ego && (wish_ego || e_ids.size() > 0)) {
         msg_print(_("エゴアイテムは願えない!", "Can not wish ego item."));
         return WishResultType::NOTHING;
     }
-    
+
     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;
-            }
-            else
+        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();
+            }
 
             return WishResultType::ARTIFACT;
         }
@@ -1027,11 +1060,12 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
             if (must || ok_art) {
                 do {
                     o_ptr->prep(k_idx);
-                    apply_magic_to_object(player_ptr, o_ptr, k_ptr->level, (AM_SPECIAL | AM_NO_FIXED_ART));
-                } 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)
+                if (o_ptr->art_name) {
                     drop_near(player_ptr, o_ptr, -1, player_ptr->y, player_ptr->x);
+                }
             } else {
                 wishing_puff_of_smoke();
             }
@@ -1050,13 +1084,14 @@ 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);
-                        (void)apply_magic_to_object(player_ptr, o_ptr, k_ptr->level, (AM_GREAT | AM_NO_FIXED_ART));
-
-                        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;
+                        }
 
-                        if (wish_ego)
+                        if (wish_ego) {
                             break;
+                        }
 
                         EgoType e_idx = EgoType::NONE;
                         for (auto e : e_ids) {
@@ -1066,8 +1101,9 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
                             }
                         }
 
-                        if (e_idx != EgoType::NONE)
+                        if (e_idx != EgoType::NONE) {
                             break;
+                        }
                     }
 
                     if (i == max_roll) {
@@ -1078,20 +1114,22 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
             } else {
                 wishing_puff_of_smoke();
             }
-            
+
             res = WishResultType::EGO;
         } else {
             for (int i = 0; i < 100; i++) {
                 o_ptr->prep(k_idx);
-                apply_magic_to_object(player_ptr, o_ptr, 0, (AM_NO_FIXED_ART));
-                if (!o_ptr->is_cursed())
+                ItemMagicApplier(player_ptr, o_ptr, 0, AM_NO_FIXED_ART).execute();
+                if (!o_ptr->is_cursed()) {
                     break;
+                }
             }
             res = WishResultType::NORMAL;
         }
 
-        if (blessed && wield_slot(player_ptr, o_ptr) != -1)
+        if (blessed && wield_slot(player_ptr, o_ptr) != -1) {
             o_ptr->art_flags.set(TR_BLESSED);
+        }
 
         if (fixed && wield_slot(player_ptr, o_ptr) != -1) {
             o_ptr->art_flags.set(TR_IGNORE_ACID);