OSDN Git Service

[Refactor] #2628 ObjectType をItemEntity に変更した
[hengbandforosx/hengbandosx.git] / src / wizard / wizard-item-modifier.cpp
index b794984..092f8e1 100644 (file)
 #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"
@@ -49,7 +49,7 @@
 #include <tuple>
 #include <vector>
 
-#define K_MAX_DEPTH 110 /*!< アイテムの階層毎生成率を表示する最大階 */
+constexpr auto BASEITEM_MAX_DEPTH = 110; /*!< アイテムの階層毎生成率を表示する最大階 */
 
 namespace {
 /*!
@@ -83,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);
     }
 }
 }
@@ -177,25 +177,15 @@ void wizard_item_modifier(PlayerType *player_ptr)
  */
 void wiz_restore_aware_flag_of_fixed_arfifact(FixedArtifactId reset_artifact_idx, bool aware)
 {
-    auto max_a_idx = enum2i(a_info.rbegin()->first);
-    auto int_a_idx = enum2i(reset_artifact_idx);
+    auto max_a_idx = enum2i(artifacts_info.rbegin()->first);
+    int int_a_idx = enum2i(reset_artifact_idx);
     if (int_a_idx <= 0) {
-        char tmp[80] = "";
-        sprintf(tmp, "Artifact ID (1-%d): ", max_a_idx);
-        char tmp_val[10] = "";
-        if (!get_string(tmp, tmp_val, 3)) {
+        if (!get_value("Artifact ID", 1, max_a_idx, &int_a_idx)) {
             return;
         }
-
-        int_a_idx = static_cast<short>(atoi(tmp_val));
-    }
-
-    if ((int_a_idx <= 0) || (int_a_idx > static_cast<short>(max_a_idx))) {
-        msg_format(_("番号は1から%dの間で指定して下さい。", "ID must be between 1 to %d."), max_a_idx);
-        return;
     }
 
-    a_info.at(i2enum<FixedArtifactId>(int_a_idx)).is_generated = aware;
+    artifacts_info.at(i2enum<FixedArtifactId>(int_a_idx)).is_generated = aware;
     msg_print(aware ? "Modified." : "Restored.");
 }
 
@@ -235,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);
@@ -257,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);
@@ -332,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) {
@@ -355,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);
@@ -410,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.at(o_ptr->fixed_artifact_idx).is_generated = false;
+        artifacts_info.at(o_ptr->fixed_artifact_idx).is_generated = false;
     }
 
     uint32_t i, matches, better, worse, other, correct;
@@ -466,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.at(q_ptr->fixed_artifact_idx).is_generated = false;
+                artifacts_info.at(q_ptr->fixed_artifact_idx).is_generated = false;
             }
 
             if ((o_ptr->tval != q_ptr->tval) || (o_ptr->sval != q_ptr->sval)) {
@@ -479,7 +468,7 @@ static void wiz_statistics(PlayerType *player_ptr, ObjectType *o_ptr)
             }
 
             correct++;
-            const auto is_same_fixed_artifact_idx = 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)) {
@@ -496,7 +485,7 @@ static void wiz_statistics(PlayerType *player_ptr, ObjectType *o_ptr)
     }
 
     if (o_ptr->is_fixed_artifact()) {
-        a_info.at(o_ptr->fixed_artifact_idx).is_generated = true;
+        artifacts_info.at(o_ptr->fixed_artifact_idx).is_generated = true;
     }
 }
 
@@ -505,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);
 
@@ -522,7 +511,7 @@ 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.at(q_ptr->fixed_artifact_idx).is_generated = false;
+                artifacts_info.at(q_ptr->fixed_artifact_idx).is_generated = false;
                 q_ptr->fixed_artifact_idx = FixedArtifactId::NONE;
             }
 
@@ -536,7 +525,7 @@ static void wiz_reroll_item(PlayerType *player_ptr, ObjectType *o_ptr)
         }
 
         if (q_ptr->is_fixed_artifact()) {
-            a_info.at(q_ptr->fixed_artifact_idx).is_generated = false;
+            artifacts_info.at(q_ptr->fixed_artifact_idx).is_generated = false;
             q_ptr->fixed_artifact_idx = FixedArtifactId::NONE;
         }
 
@@ -598,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;
@@ -645,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;
@@ -686,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;
@@ -694,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;
@@ -744,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);
 
@@ -798,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];
 
@@ -890,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;
             }
@@ -918,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
@@ -950,17 +939,17 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
 
         int len;
         int mlen = 0;
-        for (const auto &[a_idx, a_ref] : a_info) {
+        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->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));
@@ -968,7 +957,7 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
             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++;
@@ -1006,7 +995,7 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
                 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));
@@ -1026,12 +1015,9 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
 
     if (a_ids.size() == 1) {
         const auto a_idx = a_ids.back();
-        auto &a_ref = a_info.at(a_idx);
+        auto &a_ref = artifacts_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_ref.is_generated = true;
-            }
+            (void)create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
         } else {
             wishing_puff_of_smoke();
         }
@@ -1045,27 +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];
-
-        FixedArtifactId a_idx = FixedArtifactId::NONE;
-        if (k_ptr->gen_flags.has(ItemGenerationTraitType::INSTA_ART)) {
-            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) {
+        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_idx_loop;
                 break;
             }
         }
 
         if (a_idx != FixedArtifactId::NONE) {
-            auto &a_ref = a_info.at(a_idx);
+            const auto &a_ref = artifacts_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_ref.is_generated = true;
-                }
+                (void)create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
             } else {
                 wishing_puff_of_smoke();
             }
@@ -1075,12 +1058,10 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
 
         if (wish_randart) {
             if (must || ok_art) {
-                bool is_fixed_artifact;
                 do {
                     o_ptr->prep(k_idx);
-                    ItemMagicApplier(player_ptr, o_ptr, k_ptr->level, AM_SPECIAL | AM_NO_FIXED_ART).execute();
-                    is_fixed_artifact = o_ptr->fixed_artifact_idx != FixedArtifactId::NONE;
-                } while (!o_ptr->art_name || is_fixed_artifact || 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);
@@ -1103,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();
-                        const auto is_fixed_artifact = o_ptr->fixed_artifact_idx != FixedArtifactId::NONE;
-                        if (is_fixed_artifact || 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;
                         }